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.

How to open a link in the same new named tab, every time

11/14/17  Public, Tricks, Other Languages

When you want a link to open up in a new tab, you simply set the target to _blank:

<a href="http://www.starfall.com/" target="_blank">Starfall</a>

But what if you have an index view containing all your Posts, and you want...

1 vote - harrylevine

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