Skip to content

Instantly share code, notes, and snippets.

@latentflip
latentflip / gist:2250248
Created March 30, 2012 09:20
Can you spot the deliberate mistake
def attributes_from_bill_json(json)
accounting_category = find_accounting_category(json['category']),
{
:accounting_category => accounting_category,
:project_name => find_project_name(json['project']),
:contact => find_contact(json['contact'])
}
end

Testing OAuth Apis in rails 3.x apps

  1. Install phantomjs
  2. Add rspec, poltergeist, capybara, vcr to Gemfile
  3. bundle install
  4. Create spec/acceptance folder
  5. Create spec/acceptance/acceptance_helper.rb (see below)
  6. Create spec for oauth flow (see below) read the comments carefully

NB: My signup flow is something like:

@latentflip
latentflip / 1-description.md
Created April 27, 2012 10:27
Fancy split navigation with vim and tmux
  • In vim I have split navigation mapped to ctrl+h/j/k/l.
  • In tmux I navigate splits with prefix + ctrl+h/j/k/l.
  • Ideally I would be able to navigate between vim and tmux splits transparently using only ctrl+h/j/k/l.
  • I haven't figured that out yet, but I have figured out how to jump out of vim into the next tmux split if I am at the boundary of vim and tmux, without having to prefix jump, which is pretty ace. ie:
    *=cursor position
    
    -----------            -----------            -----------                  -----------
game_server.html
<script src="http://js.pusher.com/1.12/pusher.min.js">
</script>
<script>
//setup pusher and a presence channel
pusher = new Pusher('pusher-key')
channel = pusher.subscribe('presence-main-channel')
@latentflip
latentflip / 1.1_directory_structure.txt
Created May 3, 2012 09:24
In Lieu of doing this properly
./frontend
├── /coffee
│   ├── /models
│   | └── MyBaseModel.coffee
│   | └── MyModel.coffee
│   ├── /routers
│   | └── MyRouter.coffee
│   ├── /templates
| │   ├── /tmpl-dir1
@latentflip
latentflip / README.md
Created May 3, 2012 10:44
Loads a random mix from sonicrouter

Short for music? try a random sonicrouter mix

  • Stick sonicrouter.rb in your path, or curl https://raw.github.com/gist/2584960/7a8433fc0477ad388fc09af0b5ef6501d595c085/sonicrouter.rb > /somewhere/in/your/path/sonicrouter

  • Rename it sonicrouter (it's named .rb so gist syntax highlights it)

  • Type sonicrouter at a terminal.

  • Or if you are really lazy, just alias this command: curl https://raw.github.com/gist/2584960/7a8433fc0477ad388fc09af0b5ef6501d595c085/sonicrouter.rb | ruby

Bonus feature

Hilary,
I promise to feed you when you are hungry, and give you warmth when you are cold.
I promise to be the best husband and father that I can be, and learn from my mistakes when I am not.
I promise to stand by you when you take on the world, and protect you when you’d rather hide.
I promise to push you to be your best, and to act with dignity when you challenge me.
@latentflip
latentflip / Edinburgh2dates.js
Created June 27, 2012 17:44
Edinburgh2.com dates
// moment.js
// version : 1.6.2
// author : Tim Wood
// license : MIT
// momentjs.com
(function(a,b){function A(a,b){this._d=a,this._isUTC=!!b}function B(a){return a<0?Math.ceil(a):Math.floor(a)}function C(a){var b=this._data={},c=a.years||a.y||0,d=a.months||a.M||0,e=a.weeks||a.w||0,f=a.days||a.d||0,g=a.hours||a.h||0,h=a.minutes||a.m||0,i=a.seconds||a.s||0,j=a.milliseconds||a.ms||0;this._milliseconds=j+i*1e3+h*6e4+g*36e5,this._days=f+e*7,this._months=d+c*12,b.milliseconds=j%1e3,i+=B(j/1e3),b.seconds=i%60,h+=B(i/60),b.minutes=h%60,g+=B(h/60),b.hours=g%24,f+=B(g/24),f+=e*7,b.days=f%30,d+=B(f/30),b.months=d%12,c+=B(d/12),b.years=c}function D(a,b){var c=a+"";while(c.length<b)c="0"+c;return c}function E(a,b,c){var d=b._milliseconds,e=b._days,f=b._months,g;d&&a._d.setTime(+a+d*c),e&&a.date(a.date()+e*c),f&&(g=a.date(),a.date(1).month(a.month()+f*c).date(Math.min(g,a.daysInMonth())))}function F(a){return Object.prototype.toString.call(a)==="[object Array]"}function G(b){return new a(b[0],b[1]||0,b[2]||1,b[3]||0,b[4]
<h1>Foo</h1>
<h2>Bar</h2>
<h3>Tad</h3>
@latentflip
latentflip / notes.md
Created July 4, 2012 20:47
This is ridiculous, never ever do this.

So @MattWynne totally nerd-sniped me this evening, by asking this:

Is is possible to dynamically add ActiveModel::Naming compliance to an object at runtime? My meta-fu is letting me down.

As far as I can figure out, it's not doable, but I can get 'pretty' close, here's what I learned: