Skip to content

Instantly share code, notes, and snippets.

View sleepingkingstudios's full-sized avatar
💭
🚀

Rob Smith sleepingkingstudios

💭
🚀
View GitHub Profile
@sleepingkingstudios
sleepingkingstudios / mixin.rb
Created August 17, 2014 23:38
Class-method inheritance.
# Implements module-based inheritance of both class- and instance-level
# methods.
module Mixin
def mixins
@mixins ||= []
end # accessor mixins
def mixins=(ary)
@mixins = ary
@sleepingkingstudios
sleepingkingstudios / gist:972856
Created May 15, 2011 03:11
ArticlesController (original implementation)
# config/routes
match 'articles/*path' => "articles#static"
match '*path' => "articles#static"
# app/controllers/ArticlesController
class ArticlesController < ApplicationController
# GET /articles/:path
def static
module AttributeFiltering
# [ :flying, :not => :psychic]
def is(arg)
return true if arg.class == TrueClass
return false if arg.class == FalseClass || arg.class == NilClass
if arg.class == Array
put "It's an array! #{arg.inspect}}"
# lib/explore/models/location.rb
require 'controllers/action_delegate'
require 'util/argument_validator'
require 'util/text_processor'
require 'explore/models/edge'
require 'explore/parsers/location_parser'
module Explore::Models
class Comparator
def initialize(actual, expected)
@actual = actual
@expected = expected
@errors = Hash.new { |hsh, key| hsh[key] = [] }
end # constructor
attr_accessor :actual, :expected, :errors
def eql?
alias git-list-branches="git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'"
@sleepingkingstudios
sleepingkingstudios / gist:955676
Created May 4, 2011 18:05
Adding a :redcarpet Haml Filter to Rails
# Thanks to:
# http://stackoverflow.com/questions/1921777/how-to-write-a-haml-custom-filter
# config/initializers/haml_filters.rb
require 'haml/filters/redcarpet'
# lib/haml/filters/redcarpet.rb
require 'redcarpet'
module Haml::Filters::Redcarpet
@sleepingkingstudios
sleepingkingstudios / mock_example_group.rb
Created June 20, 2017 19:11
Mock Implementations of RSpec components.
module Spec::Support
class ExampleGroup
class << self
attr_reader :description
def describe description
example_group = Class.new(self)
example_group.description = description
class CommandParser
class OptionsParser
def initialize
@parsed = nil
@buffer = nil
@bname = nil
end # constructor
def parse tokens
self.buffer = ''