Skip to content

Instantly share code, notes, and snippets.

View jimsynz's full-sized avatar
💜

James Harton jimsynz

💜
View GitHub Profile
def bytecode g
pos g
g.push_rubinius
g.create_block block_from_children g
g.send_stack_with_block :lambda, 0
g.ret
end
{{description}}
source 'https://rubygems.org'
gem 'oedipus_lex'
gem 'rake'
gem 'rspec-core'
gem 'rspec-mocks'
gem 'rspec-expectations'
@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
@jimsynz
jimsynz / api_controller.rb
Last active December 27, 2018 07:29
API Session Token Example
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
def signed_in?
@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() {
source 'https://rubygems.org/'
jem <<EOF
` ` `
`````````` ` ` ` `
,:::::::::::,,,:;, +,,,,,,,,.#@.`'::,,,,,,,,,,,+'+,,,,,;;:;,....`````````..... ':' `.,` '..,,``` :,,,,,,...,.,,,,,,,,.``...,,,,,,,....,,,,,,,,
:::::::::::,,,,' ;,,,,,,,,,;#'`::,,,,,,,,.,:: ':,; ;.````````.......` . `.,: ` #,,`';.``, :,.,,,,,,,,,,,,,,,,,....,,,,,,,,,...,,,,,,,,,
:::::::::::::+` .;.,,,,,,,,.;@. '::,,,,,,,,+ ;;`' `,,`,`,; `,``````..........`...' :.,,#.,:.`, ,,,,,,,,,,,,,,,,,,,.,,,,,,,,,,,,...,,,,,,,,,
:::::::::::;, +.,,,,,,.....`#@ :,,,,,,,,:+ .: ` #+ ' `.````. .````.............,: `,,,;+..'...` ',,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,...,,,,,,,,,
::::::::::+ ;,.,,,.........`:@, ',,:,,,,; .```.``'# ` ....````` .```.....
@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'
@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 / 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.