“...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
Senior Software Engineer, UK

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;
	}
}

sublime-text-2-hash-syntax

https://github.com/iltempo/sublime-text-2-hash-syntax (CMD+CTRL+H)
- turns :blah => true to blah: true
- for much rejoicing of time saved twiddling

text_area_tag newline irritation

Yeah, well that’s not very helpful if you’re trying to count the characters in a text area and Rails is putting in a newline when you don’t want one.

2.1.2 :003 > helper.text_area_tag('test','test')
=> "<textarea name=\"test\" id=\"test\">\ntest</textarea>"

HAML doesn’t do this

%textarea string    #=> "<textarea>string</textarea>"
%textarea= 'string' #=> "<textarea>string</textarea>"

Plenty of *not right* going on

I, [2015-01-22T07:15:59.225481 #30041]  INFO -- :   Rendered api/characters/_character.json.jbuilder (0.0ms)
I, [2015-01-22T07:15:59.225700 #30041]  INFO -- :   Rendered api/characters/_character.json.jbuilder (0.0ms)
I, [2015-01-22T07:15:59.225951 #30041]  INFO -- :   Rendered api/characters/_character.json.jbuilder (0.1ms)
I, [2015-01-22T07:16:00.561068 #30041]  INFO -- :   Rendered api/characters/_character.json.jbuilder (1307.7ms)
I, [2015-01-22T07:16:00.561527 #30041]  INFO -- :   Rendered api/characters/_character.json.jbuilder (0.1ms)
I, [2015-01-22T07:16:00.561772 #30041]  INFO -- :   Rendered api/characters/_character.json.jbuilder (0.1ms)
I, [2015-01-22T07:16:00.561993 #30041]  INFO -- :   Rendered api/characters/_character.json.jbuilder (0.1ms)
I, [2015-01-22T07:16:00.562210 #30041]  INFO -- :   Rendered api/characters/_character.json.jbuilder (0.0ms)
I, [2015-01-22T07:16:00.562425 #30041]  INFO -- :   Rendered api/characters/_character.json.jbuilder (0.1ms)

Post # 242

Oh Dear

Completed 200 OK in 4100900.7ms (Views: 3288.4ms | ActiveRecord: 4097424.5ms)

AngularJS and Uglifier don't mix well.

Uglifier’s mangling messes with AngularJS. To turn it off you should do something like…

# config.assets.js_compressor = :uglifier
config.assets.js_compressor = Uglifier.new(mangle: false) if defined? Uglifier

Checkout a single file from a different branch

I totally managed to mess up my Gemfile.lock file setting the versions of many gems to far higher versions than I’d intended. bundle update is bad, even if you set the version in your Gemfile the dependencies of thos gems are not versioned so precisely. I did this in a branch so fortunately the Gemfile.lock in my master branch is accurate.

git checkout master -- Gemfile.lock

That did the job. Then a bundle install puts the changes I’d made to my Gemfile into Gemfile.lock with the correct dependencies as per master. Phew.

Brew fails after installing Yosemite

If you upgrade to MacOSX Yosemite and get this

Robs-iMac:~ rl$ brew install

/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory

/usr/local/bin/brew: line 26: /usr/local/Library/brew.rb: Undefined error: 0

you need to do this

cd /usr/local/Library

git pull origin master

Then you’re good again.

Xcode Licence blocking gem install

Hmmmzzz..

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /Users/rl/.rvm/rubies/ruby-2.1.2/bin/ruby extconf.rb 
creating Makefile

make "DESTDIR=" clean


Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.



make "DESTDIR="


Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.



make failed, exit code 69

Gem files will remain installed in /Users/rl/.rvm/gems/ruby-2.1.2@upgrade-ruby/gems/byebug-3.5.1 for inspection.
Results logged to /Users/rl/.rvm/gems/ruby-2.1.2@upgrade-ruby/extensions/x86_64-darwin-13/2.1.0-static/byebug-3.5.1/gem_make.out
An error occurred while installing byebug (3.5.1), and Bundler cannot continue.
Make sure that `gem install byebug -v '3.5.1'` succeeds before bundling.

You need to do sudo xcrun cc

..blah blah blah...

By typing 'agree' you are agreeing to the terms of the software license agreements. Type 'print' to print them or anything else to cancel, [agree, print, cancel] agree
GPK of the Day Charred CHAD