code-beautification

Writing Beautiful Ruby: Checking for nil string before concatenating

Currently I have: file.puts "cn: " + (var1.nil? ? "UNKNOWN" : var1) Which works fine, but doesn't look good. What is a better way to write this in ruby so that I am checking for nil and not concatenating it Note: This question is similar to a LOT of questions, but in no such way is it anything of a duplicate. This question is about s...

Ruby: String no longer mixes in Enumerable in 1.9

So how can I still be able to write beautiful code such as: 'im a string meing!'.pop Note: str.chop isn't suffecient answer ...

Writing better Ruby: How to cast a objects to false or true?

In ruby, what is the best/most-elegant way to return a value such as: #method returns true or false if 'do i match' is present in string def method(str) str =~ /do i match/ end ...

What is the proper way to phrase this statement in Ruby?

Hi Guys, I'm new at this, and I'm having trouble finding the proper way to phrase this in Ruby. And I don't know if the Ruby API in SketchUp is different. But, thats what I'm trying to use it for. def self.initialize_job_info return{ 'salesperson' => ' = $pg_settings['salespersons'[['salesperson']['id']]] if ('on' = $pg_set...

Ruby: Can I write multi-line string with no concatenation?

Is there I way I can make this look a little better? conn.exec 'select attr1, attr2, attr3, attr4, attr5, attr6, attr7 ' + 'from table1, table2, table3, etc, etc, etc, etc, etc, ' + 'where etc etc etc etc etc etc etc etc etc etc etc etc etc' Like, is there a way I imply concatenation? ...

Writing 'CONTAINS' query using LINQ

Given the output of query: var queryResult = from o in objects where ... select new { FileName = o.File, Size = o.Size } What would you consider the neatest way to detect if a file is in the queryResult? H...

Most idiomatic way to print a time difference in Java?

I'm familiar with printing time difference in milliseconds: long time = System.currentTimeMillis(); //do something that takes some time... long completedIn = System.currentTimeMillis() - time; But, is there a nice way print a complete time in a specified format (eg: HH:MM:SS) either using Apache Commons or even the dreaded platform...

So, I have this jquery bit that adds a row to a table the way I need it to, but it's UGLY

I have a table that looks like this: <table name="exercises" id="workout-table"> <tr> <th>Name</th> <th>Reps/Intervals</th> <th>Sets</th> <th>Weight/Distance/Time</th> </tr> [%- i=0 %] [% WHILE i<=10 %] <tr class="workout-rows"> <td><input type="text" name="workout[exercise][[% i %]][name]" /></td> <td><input type="text" name="workou...

Order source code alphabetically by function name

I use Geany as text editor (windows). It shows the functions list sorted alphabetically and I would like to have the actual functions in the source code sorted in that way. Is there any program to process the source code (php) and output the functions sorted alphabetically my name? ...

Controlling code beautifing in emacs

How can I get Emacs to put padding spaces around opening brackets and operators on indentation ()? ...

Spring - adding BindingResult to newly created model attribute

My task is - to create a model attribute by given request parameters, to validate it (in same method) and to give it whole to the View. I was given this example code: @Controller class PromotionController { @RequestMapping("promo") public String showPromotion(@RequestParam String someRequestParam, Model model) { //Crea...

Beautify HTML code using Ruby or Java?

I'm looking for pure Ruby (or Java) solutions for beautifying HTML code. I'm currently using Hpricot to parse HTML, since Nokogiri and other HTML parsers require external C programs. I assume that I can use Hpricot to clean up HTML if I can come up with a good algorithm. I'd prefer not to reinvent if this has already been done. ...

Can I apply PL/SQL beautifer rules from command line?

Topic is self-explanatory. My goal is to automate the process of code beautification, so a program like SQLPlus will compile code after it has been beautified. ...

making a small regular expression a bit more readable

I've got a working regular expression, but I'd like to make it a tad more readable, and I'm far from a regex guru, so I was humbly hoping for some tips. This is designed to scrape the output of several different compilers, linkers, and other build tools, and is used to build a nice little summery report. It does it's job great, but I'm...

Writing a code beautifier

I'd like to write a code beautifier and i thought of using Ruby to do it. Could someone show me a place to get started? I've seen a lot of code beautifiers online but I've never come across any tutorials on how to write one. Is this a very challenging task for someone who's never undertaken any projects such as writing a compiler, parser...