Jump to content

Remember to take a break sometimes

- - - - -

  • Please log in to reply
1 reply to this topic

#1
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Or else your mind goes Zombiemode and you do the easiest things in the most complicated way.
I had this code fragment, formatted with HTML and I needed to figure out the amount of "real" lines it actually contained.
code-html sample: (it has <pre> tags around it, how pretty :P)

            oos.flush();

        } <span style="color: rgb(0,0,128); font-weight: bold;">

catch</span> (IOException e) {

            System.err.println("Oops, error, don't worry stream will be closed...");

        } <span style="color: rgb(0,0,128); font-weight: bold;">

finally</span> {

            <span style="color: rgb(0,0,128); font-weight: bold;">

try</span> {

                <span

style="color: rgb(0,0,128); font-weight: bold;">

if</span> (oos != null) {

                    oos.close();


Because this big String contains lines I don't need to count, like these 2

                <span

style="color: rgb(0,0,128); font-weight: bold;">

As well as the doctype on top, the head tags, the title, the body tags, html tags, etc etc.
I had the WONDERFUL idea to go write a regex which will only match the ends of lines I need.

After an hour or so I came up with

^((([^<>\n]*<.*>[^<>\n]+)*)|([^<>\n]*))$

(And that works ^^)

*goes on a break*
...
*comes back*
*thinking: Dude, this is Java. Every line ends with either a semicolon or curly braces if it's written properly*
result:

^.*[;{}]$

And added "|^$" to match empty lines too.
So I just rewrote the 1 hour regex in 5 minutes. :glare:
Really one of those moments where I wanna do this:
Posted Image

(Okay, you can write Java on multiple lines without using a semicolon if it's the same statement, but that was not happening in my htmls)

So guys and girls. Breaks are wonderful :)

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
I have learned that when my brain is in a certain state, writing code is just a Bad Idea ™. That's when I usually catch up on emails, do research on technologies, anything other than write code that has an 80% chance of being crap that I'll just have to fix later.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users