Skip to content

Instantly share code, notes, and snippets.

View myobie's full-sized avatar

Nathan myobie

View GitHub Profile
@myobie
myobie / workflow-example.rb
Created March 9, 2014 11:45
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.
module Workflow
extend ActiveSupport::Concern
included do
extend ActiveModel::Naming
include ActiveModel::Validations
end
def call
if valid?
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 March 21, 2014 22:30
My methods I am accumulating for testing sinatra applications.
module MySinatraTestMethods
def self.included(other)
other.send :include, Rack::Test::Methods
end
def app
Sinatra::Application.new
end
def session
# example that works
get "/", {}, "rack.session" => { user_id: 1 }
# example that I wish worked
logged_in_as(1) { get "/" }
# or this
# 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
require 'monitor'
class Promise
include MonitorMixin
NOTHING = Object.new.freeze
def initialize(&blk)
@blk = blk
@value = NOTHING
end
require 'monitor'
require 'forwardable'
module Wunderlist
module SDK
AlreadyComplete = Class.new(StandardError)
class Future
include MonitorMixin
NOTHING = Object.new.freeze

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:

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 June 14, 2014 18:47
$ ruby alarm.rb in 30 minutes
require "curses"
require "monitor"
class Timer
def initialize(amount)
@amount = amount
end
def after(&blk)
@after = blk