Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Bleigh mbleigh

View GitHub Profile
@mbleigh
mbleigh / config.ru
Created Apr 8, 2013
Quick "Hello World" for running Grape and Sinatra together using Rack::Cascade.
View config.ru
# Put this in a new directory, then run `rackup`
require 'sinatra'
require 'grape'
class Web < Sinatra::Base
get '/' do
"Hello world."
end
end
@mbleigh
mbleigh / gist:3894298
Created Oct 15, 2012
How to use LetterOpener with Pony
View gist:3894298
require 'pony'
Pony.options = {
:via => :smtp,
:from => "Somebody <notifications@example.com>"
}
if ENV['RACK_ENV'] == 'development'
require "letter_opener"
Pony.options.merge!({
via: LetterOpener::DeliveryMethod,
@mbleigh
mbleigh / output.html
Created Sep 18, 2012
100% unmodified output from Divshot
View output.html
<!doctype html>
<html>
<head>
<title>Divshot Demo Output</title>
<link rel="stylesheet" href="https://app.divshot.com/css/divshot-util.css">
<link rel="stylesheet" href="https://app.divshot.com/css/bootstrap.css">
<link rel="stylesheets" href="https://app.divshot.com/css/bootstrap-responsive.css">
</head>
@mbleigh
mbleigh / matchers.rb
Created Sep 7, 2012
RSpec matcher for JSON responses.
View matchers.rb
RSpec::Matchers.define :have_json_key do |expected_key|
match do |response|
@body = MultiJson.load(response.body)
result = @body.key?(expected_key.to_s)
result &&= @body[expected_key.to_s] == @expected_val if @val_provided
result
end
chain :with_value do |val|
@mbleigh
mbleigh / service_account.rb
Created May 16, 2012
Google OAuth 2.0 Service Account Authorization
View service_account.rb
require 'multi_json'
require 'base64'
require 'openssl'
require 'faraday'
now = Time.now.utc.to_i
def encode(hash)
Base64.urlsafe_encode64(MultiJson.dump(hash))
end
@mbleigh
mbleigh / welcome.html
Created May 1, 2012
This is real output from Divshot, the drag and drop editor that developers and designers can be proud to use.
View welcome.html
<!doctype html>
<html>
<head>
<title>Divshot Welcome - Welcome to Divshot (Divshot Prototype)</title>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<script type='text/javascript' src='http://divshot.dev/assets/preview.js'></script>
<link rel='stylesheet' href='http://divshot.dev/assets/preview.css' />
</head>
<body>
<div class='container-fluid'>
@mbleigh
mbleigh / bouncy.rb
Created Mar 29, 2012
A rough and naive declarative syntax for class reloading.
View bouncy.rb
module Bouncy
def self.mappings
@@mappings ||= []
end
def self.bounce!
mappings.each(&:bounce!)
end
def self.runner(const_name)
@mbleigh
mbleigh / Gemfile
Created Mar 21, 2012
Non-Rails Rackup with Sprockets, Compass, Handlebars, Coffeescript, and Twitter Bootstrap
View Gemfile
source "https://rubygems.org"
gem 'sprockets'
gem 'sprockets-sass'
gem 'sass'
gem 'compass'
gem 'bootstrap-sass'
gem 'handlebars_assets'
gem 'coffee-script'
View my_class.rb
MyClass
This class is a simple class that does things. Notice that I'm
just using it as an example for potential documentation style.
.class_method
Does something at the class level.
@param options [Hash] A hash of options
.new
Creates a new instance of MyClass
View models.rb
class User
attr_reader :item
def self.create(name)
User.new(TABLES['users'].items.create(id: name))
end
def self.all
TABLES['users'].items.to_a.map{|i| User.new(i)}
end
You can’t perform that action at this time.