Skip to content

Instantly share code, notes, and snippets.

Avatar
👻
A ghost

Nathan myobie

👻
A ghost
View GitHub Profile
@myobie
myobie / workflow-example.rb
Created Mar 9, 2014
I have this idea to create workflows for actions that need their data validated before acting and I don't want to shove it all into the model.
View workflow-example.rb
module Workflow
extend ActiveSupport::Concern
included do
extend ActiveModel::Naming
include ActiveModel::Validations
end
def call
if valid?
View stark_params.rb
class TasksController
def index
Task.where(IndexParams.new(params).params)
end
def create
Task.create!(CreateParams.new(params).params)
end
private
@myobie
myobie / my_sinatra_test_methods.rb
Created Mar 21, 2014
My methods I am accumulating for testing sinatra applications.
View my_sinatra_test_methods.rb
module MySinatraTestMethods
def self.included(other)
other.send :include, Rack::Test::Methods
end
def app
Sinatra::Application.new
end
def session
View gist:9771994
# example that works
get "/", {}, "rack.session" => { user_id: 1 }
# example that I wish worked
logged_in_as(1) { get "/" }
# or this
View request_repsonse.coffee
# Heavily inspired and modified from http://www.quirksmode.org/js/xmlhttp.html
XMLHttpFactories = [
(-> return new XMLHttpRequest()),
(-> return new ActiveXObject("Msxml2.XMLHTTP")),
(-> return new ActiveXObject("Msxml3.XMLHTTP")),
(-> return new ActiveXObject("Microsoft.XMLHTTP"))
]
class Response
View promise.rb
require 'monitor'
class Promise
include MonitorMixin
NOTHING = Object.new.freeze
def initialize(&blk)
@blk = blk
@value = NOTHING
end
View future.rb
require 'monitor'
require 'forwardable'
module Wunderlist
module SDK
AlreadyComplete = Class.new(StandardError)
class Future
include MonitorMixin
NOTHING = Object.new.freeze
View keybase.md

Keybase proof

I hereby claim:

  • I am myobie on github.
  • I am myobie (https://keybase.io/myobie) on keybase.
  • I have a public key whose fingerprint is 69D2 E49C B648 2AF7 165D 6DC7 0C2B ADEB 54D2 48F1

To claim this, I am signing this object:

View discussion_controller_spec.rb
require 'spec_helper'
describe DiscussionsController do
before { stub_current_user }
describe "index" do
context "(with a project and some discussions)" do
before do
@project = create :project, owner: current_user, member_ids: [current_user.id]
@discussions = 3.times.map do
@myobie
myobie / alarm.rb
Created Jun 14, 2014
$ ruby alarm.rb in 30 minutes
View alarm.rb
require "curses"
require "monitor"
class Timer
def initialize(amount)
@amount = amount
end
def after(&blk)
@after = blk
You can’t perform that action at this time.