Skip to content

Instantly share code, notes, and snippets.

View jimsynz's full-sized avatar
💜

James Harton jimsynz

💜
View GitHub Profile
@jimsynz
jimsynz / mr_darcy.rb
Last active August 29, 2015 13:56
So, after our dopodcast episode about DCI (http://dopodcast.org/blog/2014/02/10/show-9-dci-with-jim-gay-and-craig-ambrose/) I've been thinking a lot about the intersection of DCI and Promises/A+ in Ruby, and here's an example of what I've been thinking.
class MrDarcy
class Context
class << self
def role role_name, &block
role_name = role_name.to_sym
roles[role_name] = Module.new(&block)
role_name
This file has been truncated, but you can view the full file.
..../Users/jnh/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.5/lib/rspec/core/memoized_helpers.rb:199: [BUG] Segmentation fault at 0x007fff51ad3fd8
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]
-- Crash Report log information --------------------------------------------
See Crash Report log file under the one of following:
* ~/Library/Logs/CrashReporter
* /Library/Logs/CrashReporter
* ~/Library/Logs/DiagnosticReports
* /Library/Logs/DiagnosticReports
for more details.
@jimsynz
jimsynz / api_controller.rb
Created March 19, 2014 01:42
Ember API Token
# app/controllers/api_controller.rb
class ApiController < ApplicationController
skip_before_action :verify_authenticity_token
respond_to :json
rescue_from UserAuthenticationService::NotAuthorized, with: :not_authorized
rescue_from ActiveRecord::RecordNotFound, with: :not_found
before_filter :api_session_token_authenticate!
private
@jimsynz
jimsynz / adapter.coffee
Last active August 29, 2015 13:57
Discussion about API for mapping endpoints in EPF, similar in concept to the Ember router.
# For example:
App.Adapter = Ep.RestAdapter.extend
namespace: '/api/v1/'
routes:
# some magic DSL.
@jimsynz
jimsynz / purposes.md
Last active August 29, 2015 13:58
Proposed purposes of Ruby NZ:
  1. Foster and support the Ruby programming language, it's users, community and ecosystem in New Zealand.
  2. Advocate for Open Source in general, and the Ruby programming language in particular.
  3. Provide organisational, financial and legal support for Ruby community events.
  4. Provide for the safety and welcome inclusion of all people within the Ruby community and Ruby community events regardless of; gender, gender expression, sexuality, marital status, religious belief, ethical belief, colour, race, ethnic or national origin, disability, age, political opinion, employment or family status.
@jimsynz
jimsynz / jruby-1.7.11.rb
Last active August 29, 2015 13:58
Monkey patching singleton methods...
m = Module.new { def a; :a; end }
# => #<Module:0x3cbea6af>
method = m.instance_method :a
# => #<UnboundMethod: #<Module:0x3cbea6af>#a>
o = Object.new
# => #<Object:0x590bcaf1>
o.define_singleton_method :a, method
# TypeError: bind argument must be an instance of #<Module:0x3cbea6af>
# from org/jruby/RubyModule.java:1521:in `define_method'
# from org/jruby/RubyKernel.java:1491:in `define_singleton_method'
source 'https://rubygems.org/'
jem <<EOF
` ` `
`````````` ` ` ` `
,:::::::::::,,,:;, +,,,,,,,,.#@.`'::,,,,,,,,,,,+'+,,,,,;;:;,....`````````..... ':' `.,` '..,,``` :,,,,,,...,.,,,,,,,,.``...,,,,,,,....,,,,,,,,
:::::::::::,,,,' ;,,,,,,,,,;#'`::,,,,,,,,.,:: ':,; ;.````````.......` . `.,: ` #,,`';.``, :,.,,,,,,,,,,,,,,,,,....,,,,,,,,,...,,,,,,,,,
:::::::::::::+` .;.,,,,,,,,.;@. '::,,,,,,,,+ ;;`' `,,`,`,; `,``````..........`...' :.,,#.,:.`, ,,,,,,,,,,,,,,,,,,,.,,,,,,,,,,,,...,,,,,,,,,
:::::::::::;, +.,,,,,,.....`#@ :,,,,,,,,:+ .: ` #+ ' `.````. .````.............,: `,,,;+..'...` ',,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,...,,,,,,,,,
::::::::::+ ;,.,,,.........`:@, ',,:,,,,; .```.``'# ` ....````` .```.....
@jimsynz
jimsynz / 00_original.js
Last active August 29, 2015 14:02
An exercise in refactoring horrible procedural JavaScript. Please don't be this person.
/*
* This is a JS file from a library that our client wanted us to use. It included a dependency on a JS lib called `classie` which is
* used for adding and removing HTML classes to elements. The project already includes jQuery.
*/
(function() {
$(document).ready(function() {
@jimsynz
jimsynz / 01_turnstile.rb
Last active August 29, 2015 14:04
Source code for our No More Mr State Machine talk.
# Our simple example of a Turnstile state machine.
class Turnstile
def initialize
@state = "Locked"
end
def push!
@state = "Locked" if unlocked?
end
source 'https://rubygems.org'
gem 'oedipus_lex'
gem 'rake'
gem 'rspec-core'
gem 'rspec-mocks'
gem 'rspec-expectations'