Tricks

You deleted 15 lines of my code, added two words and an exclamation point, and now it works…Dang it! How did you do that?!
Enough said. You will encounter many of these moments when working with other developers. You’ll hear people say things like, “Oh it’s just something I picked up along the way.” When you see a trick, write it down. You will want to remember them.

Encode an SVG file using base64 encoding

09/22/16  Public, Command Line, Tricks, Other Languages

Here is how to encode an SVG file, using base64 encoding, and then leverage the encoded string to set an element's background-image property to the SVG file in question.

1 - Open up an irb session
2 - Read the file into a variable, using...

1 vote - harrylevine

Shortcut for pretty printing Active Record data in the rails console

03/28/16  Public, Command Line, Shortcuts, Tricks

In the rails console, when you run something like Post.all it returns all of the posts in one big continuous paragraph. A quick, low-rent shortcut to get these records to pretty print is to:

  • lead with a y

For example:

$...

1 vote - harrylevine

Using the .class method to determine if an object is what you are looking for

05/28/15  Public, Tricks, Ruby General

Let's say that you want to use a given object if the object is an array; however, if the object is not an array (meaning it is a string, or a fixnum, etc.), then you do not want to use it.

You can use the .class method with conditional l...

1 vote - harrylevine

How to remove any non-alpha characters (a to z) from a string using gsub and RegEx

12/05/14  Public, Tricks, Ruby General

For example, let's say that you have a method that determines if a particular word (string) is a palindrome or not. As a fringe case, what if the string happens to contain characters like . or...

1 vote - harrylevine

Way to test a specific section in a file without using Focus

11/24/14  Public, Tricks, Testing / TDD

Adding a focus to a spec file is good way to just test that specific area. The one drawback is you have to remember to remove the...

1 vote - harrylevine