Petty Annoyance of the day #1

Methods that return different object types given different input. I understand why this does what it does but when you forget the 2nd argument and an Enumerator arrives unexpectedly….

2.1.2 :068 > 'somestring'.gsub(':').class
 => Enumerator 
2.1.2 :069 > 'somestring'.gsub(':','').class
 => String 

Not sure why its Enumerator

2.1.2 :085 > 'string'.gsub(/(s)trin(g)/).each do |blah|
2.1.2 :086 >     puts blah
2.1.2 :087?>   end
2.1.2 :099 > 'string'.gsub('staobasf').map(&:object_id)
 => [] 
2.1.2 :100 > 'string'.gsub('staobasf').map
 => #<Enumerator: #<Enumerator: "string":gsub("staobasf")>:map> 

I am pretty sure I don’t need to know but hey.

SSL Certificate - CSR generation

In order to generate a *.csr and *.key file for your SSL Certificate.

openssl req -new -newkey rsa:2048 -nodes -keyout somedomain.key -out somedomain.csr
Generating a 2048 bit RSA private key
writing new private key to ''
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
Country Name (2 letter code) [AU]:GB
State or Province Name (full name) [Some-State]:East Sussex
Locality Name (eg, city) []:Brighton
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Some Limited Company Limited
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:*
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

DNS / host commands

Want a few simple DNS details for a domain from the command line?

Robs-iMac:~ roblacey$ host -t mx mail is handled by 9 mail is handled by 10

Robs-iMac:~ roblacey$ host -t txt descriptive text "google-site-verification=E4g5ZQVgm9j01RsxbiGISNBaOvtH614IHSF1RGHHGJE"

Robs-iMac:~ roblacey$ host -t a has no A record

Robs-iMac:~ roblacey$ host -t a is an alias for has address

Robs-iMac:~ roblacey$ host -t cname is an alias for

today's challenge ActionView::Template::Error: not opened for reading

  not opened for reading

that awk syntax I can never remember

[production] rails@thisserver ~ $ ps -ef | grep resque:work | awk '{print $2;}'

MATOTU - Machines Are Taking Over The Universe - Teaser Video

The new project I have been working on is nearing launch, nice little teaser for you. M.A.T.O.T.U. – Machines Are Taking Over The Universe it would appear.

Need to learn something new....2D Platformer it is.

1 x Getting Started with Unity 5 [eBook] – £7.69
1 x Unity Game Development Blueprints [eBook] – £3.84
1 x Learning Unity 2D Game Development by Example [eBook] – £3.84
1 x Mastering Unity 2D Game Development [eBook] – £3.84
1 x NW.js Essentials [eBook] – £3.84
1 x Node Web Development – Second Edition [eBook] – £3.84

PacktPub Skillup Bundles are dirty cheap if you want to try something new.

Ruby objects and no dup-ing.

Got to remember that when you pass an object to method, that the object is still the same object in memory and it change the object in memory changes, leading to potentially unexpected behaviour. So if you really need to manipulate the arguments a method receives, perhaps think about call blah.dup to clone it before you make changes to it.

options = { :node => 'MyNodeThing' }

def url(options)
  node = options.delete(:node)
  puts node


puts options[:node]
#=> nil

Hash#slice and Hash#except

Because I can never remember this…

2.1.2 :005 > {:dave => :terry, :peanuts => 1, :pickles => :eleventy_two}.slice(:dave, :peanuts)
 => {:dave=>:terry, :peanuts=>1} 

And it’s nemesis

2.1.2 :006 > {:dave => :terry, :peanuts => 1, :pickles => :eleventy_two}.except(:dave, :peanuts)
 => {:pickles=>:eleventy_two} 

Renaming existing branch with Git

In order to rename an existing branch locally and remotely….

Robs-iMac:core roblacey$ git branch -m feature/something feature/something/trunk
Robs-iMac:core roblacey$ git push origin :feature/something
 - [deleted]         feature/something
Robs-iMac:core roblacey$ git push origin feature/something/trunk
Counting objects: 225, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (72/72), done.
Writing objects: 100% (74/74), 8.16 KiB | 0 bytes/s, done.
Total 74 (delta 55), reused 0 (delta 0)
 * [new branch]      feature/something/trunk -> feature/something/trunk