“...I've been working since 2008 with Ruby / Ruby on Rails, love a bit of Elixir / Phoenix and learning Rust. I also poke through other people's code and make PRs for OpenSource Ruby projects that sometimes make it. Currently working for InPay...”

Rob Lacey (contact@robl.me)
Senior Software Engineer, Brighton, UK

that awk syntax I can never remember

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

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
end

url(options)

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
To git@github.com:/username/core.git
 - [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)
To git@github.com:/username/core.git
 * [new branch]      feature/something/trunk -> feature/something/trunk

Sublime Editor settings

{
	"color_scheme": "Packages/User/Monokai (SL).tmTheme",
	"ensure_newline_at_eof_on_save": true,
	"font_size": 12,
	"ignored_packages":
	[
		"Vintage"
	],
	"tab_size": 2,
	"translate_tabs_to_spaces": true,
	"trim_trailing_white_space_on_save": true
}

How to delete a remote tag in Git.

git tag -d tagtoremove
git push origin :refs/tags/tagtoremove

very clever. messing around with hostnames of routers

Robs-iMac:pledge_core rl$ traceroute 216.81.59.173
traceroute to 216.81.59.173 (216.81.59.173), 64 hops max, 52 byte packets
 1  10.10.140.1 (10.10.140.1)  11.123 ms  15.222 ms  13.561 ms
 2  brig-core-2a-xe-002-0.network.virginmedia.net (80.3.64.225)  11.023 ms  12.461 ms  11.560 ms
 3  brnt-bb-1a-ae19-0.network.virginmedia.net (213.105.159.153)  14.969 ms  13.989 ms  19.439 ms
 4  * * *
 5  * * *
 6  * * *
 7  nrth-bb-1c-ae0-0.network.virginmedia.net (62.254.42.134)  33.405 ms  13.518 ms  17.352 ms
 8  fran-ic-2-ae0-0.network.virginmedia.net (62.254.42.178)  32.933 ms  37.752 ms  33.935 ms
 9  30gigabitethernet4-3.core1.fra1.he.net (80.81.192.172)  38.951 ms  35.417 ms  43.849 ms
10  100ge5-2.core1.par2.he.net (72.52.92.13)  44.133 ms  62.041 ms  46.092 ms
11  10ge15-1.core1.ash1.he.net (184.105.213.93)  106.065 ms  123.027 ms  106.997 ms
12  10ge1-2.core1.atl1.he.net (184.105.213.110)  122.861 ms  125.631 ms  133.370 ms
13  216.66.0.26 (216.66.0.26)  316.928 ms  133.867 ms  119.540 ms
14  * * *
15  episode.iv (206.214.251.1)  158.935 ms  189.852 ms  159.442 ms
16  a.new.hope (206.214.251.6)  160.546 ms  166.501 ms  168.217 ms
17  it.is.a.period.of.civil.war (206.214.251.9)  161.563 ms  172.048 ms  165.151 ms
18  rebel.spaceships (206.214.251.14)  162.032 ms  164.220 ms  182.936 ms
19  striking.from.a.hidden.base (206.214.251.17)  175.150 ms  161.951 ms  163.248 ms
20  have.won.their.first.victory (206.214.251.22)  162.738 ms  163.320 ms  162.650 ms
21  against.the.evil.galactic.empire (206.214.251.25)  161.264 ms  384.746 ms  171.485 ms
22  during.the.battle (206.214.251.30)  357.428 ms  169.686 ms  160.789 ms
23  rebel.spies.managed (206.214.251.33)  159.636 ms  162.306 ms  158.633 ms
24  to.steal.secret.plans (206.214.251.38)  161.400 ms  158.717 ms  157.681 ms
25  to.the.empires.ultimate.weapon (206.214.251.41)  162.642 ms  161.686 ms  163.015 ms
26  the.death.star (206.214.251.46)  162.793 ms  166.526 ms  161.715 ms
27  an.armored.space.station (206.214.251.49)  161.710 ms  162.815 ms  159.922 ms
28  with.enough.power.to (206.214.251.54)  177.850 ms  175.679 ms  161.911 ms
29  destroy.an.entire.planet (206.214.251.57)  160.419 ms  160.928 ms  459.348 ms
30  pursued.by.the.empires (206.214.251.62)  159.853 ms  162.489 ms  211.870 ms
31  sinister.agents (206.214.251.65)  159.998 ms  164.795 ms  162.802 ms
32  princess.leia.races.home (206.214.251.70)  161.321 ms  165.046 ms  160.520 ms
33  aboard.her.starship (206.214.251.73)  161.139 ms  165.795 ms  166.763 ms
34  custodian.of.the.stolen.plans (206.214.251.78)  164.417 ms  164.701 ms  163.949 ms
35  that.can.save.her (206.214.251.81)  172.123 ms  379.719 ms  163.717 ms
36  people.and.restore (206.214.251.86)  162.872 ms  162.311 ms  236.724 ms
37  freedom.to.the.galaxy (206.214.251.89)  172.736 ms  162.064 ms  161.036 ms
38  0-----i-------i-----0 (206.214.251.94)  163.729 ms  178.702 ms  160.082 ms
39  0------------------0 (206.214.251.97)  159.938 ms  171.574 ms  166.623 ms
40  0-----------------0 (206.214.251.102)  162.639 ms  161.415 ms  164.806 ms
41  0----------------0 (206.214.251.105)  167.458 ms  162.318 ms  164.580 ms
42  0---------------0 (206.214.251.110)  169.286 ms  162.726 ms  162.048 ms
43  0--------------0 (206.214.251.113)  162.910 ms  164.204 ms  168.749 ms
44  0-------------0 (206.214.251.118)  166.699 ms  170.351 ms  172.651 ms
45  0------------0 (206.214.251.121)  159.047 ms  161.181 ms  162.952 ms
46  0-----------0 (206.214.251.126)  164.174 ms  173.919 ms  212.134 ms
47  0----------0 (206.214.251.129)  168.123 ms  209.428 ms  163.144 ms
48  0---------0 (206.214.251.134)  168.921 ms  164.755 ms  163.971 ms
49  0--------0 (206.214.251.137)  159.927 ms  207.254 ms  188.687 ms
50  0-------0 (206.214.251.142)  164.872 ms  162.988 ms  162.665 ms
51  0------0 (206.214.251.145)  163.522 ms  303.512 ms  159.782 ms
52  0-----0 (206.214.251.150)  162.139 ms  183.994 ms  193.999 ms
53  0----0 (206.214.251.153)  166.649 ms  165.147 ms  165.782 ms
54  0---0 (206.214.251.158)  167.327 ms  166.019 ms  167.644 ms
55  0--0 (206.214.251.161)  422.569 ms  182.132 ms  168.749 ms
56  0-0 (206.214.251.166)  166.422 ms  166.970 ms  165.926 ms
57  00 (206.214.251.169)  160.421 ms  160.880 ms  162.596 ms
58  i (206.214.251.174)  193.246 ms  165.820 ms  163.162 ms
59  by.ryan.werber (206.214.251.177)  163.115 ms  161.675 ms  347.660 ms
60  blizzards.breed.ccie.creativity (206.214.251.182)  163.674 ms  166.756 ms  163.709 ms
61  please.try.again.tracerote.to.obiwan.scrye.net (206.214.251.185)  165.720 ms  172.367 ms  165.217 ms
62  read.more.at.beaglenetworks.net (206.214.251.190)  178.686 ms *  168.679 ms

C# HTTP API calls from inside Unity

Had to fiddle about a bit to work out how to POST an JSON API with Unity via C#, this example sends raw JSON with the application/json header which Rails will then decode it and turn it into ‘params’.

using UnityEngine;
using System.Collections;

public class ThingAPI : MonoBehaviour {
	// Use this for initialization
	IEnumerator Start () {
		// GET
                var url = "http://localhost:3000/api/posts/1";
		WWW www = new WWW(url);
		yield return www;

                // POST
		url = "http://localhost:3000/api/posts";
		var jsonString = "{\"post\":[{\"title": "Something to post about\": 1, \"body\": \"and maybe someone will listen to my cries.\"}]}";
		
		var encoding = new System.Text.UTF8Encoding();
		var postHeader = new Hashtable();
		
		postHeader.Add("Content-Type", "application/json");
		postHeader.Add("Content-Length", jsonString.Length);

		www = new WWW(url, encoding.GetBytes(jsonString), postHeader);
		yield return www;
	}
}