Skip to content

Instantly share code, notes, and snippets.

View chrismcg's full-sized avatar

Chris McGrath chrismcg

View GitHub Profile
anonymous
anonymous / config.exs
Created June 2, 2015 00:46
config :logger, :console,
format: "time=$dateT$timeZ level=$level $metadata$message\n",
metadata: [:request_id],
utc_log: true
# HaveFilter matchers for RSpec
# save as: spec/support/have_filter.rb
#
# class HomeController < ApplicationController
# before_filter :require_user, :except => [:action_1, :action_2]
# ...
# end
#
# describe HomeController do
# it { should have_before_filter(:require_user).except(:action_1, :action_2) }
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'midi-winmm'
# tested with midi-winmm, but I assume will work with alsa-rawmidi
class Numeric
def to_hex_str
"%02x" % self
end
end
@jeroenvandijk
jeroenvandijk / ack.rb
Created June 18, 2011 19:41
ack your gems
#!/usr/bin/env ruby
# Usage:
#
# ./ack.rb your-query
require 'rubygems'
require 'bundler'
if query = ARGV[0]
gem_dirs = Bundler.load.specs.map(&:full_gem_path).join(' ')
@jamis
jamis / demo.rb
Created August 3, 2011 21:56
Repairing a unicode string that contains invalid characters
# encoding: utf-8
s = "Blah \xe9 blah 헌글"
puts "BEFORE"
puts "encoding: #{s.encoding}"
puts "valid : #{s.valid_encoding?}"
puts "text : #{s}"
s = s.
@assaf
assaf / gist:1207141
Created September 9, 2011 19:41
rescueFrom for jQuery AJAX requests
rescue_from = {}
# Associate status code with an HTTP status code. First argument is the status
# code, second argument is a function that accepts the XHR object. For example:
# $.rescueFrom 404, (xhr)-> alert("Oh no, page not found!")
$.rescueFrom = (status, fn)->
rescue_from[status] = fn
# Default handling for unsuccessulf HTTP status code. Finds and calls most
# appropriate handler based on the HTTP status code (see `$.rescueFrom`).
require 'psych'
class MyEmitter < Psych::Visitors::Emitter
end
o = "hello world"
visitor = Psych::Visitors::YAMLTree.new {}
visitor << o
my_emitter = MyEmitter.new $stdout
@timgremore
timgremore / index.html.haml
Created January 3, 2012 21:13
Ember.js, document collection and polling...written in CoffeeScript
- title "#{@game.name}"
%h1= yield(:title)
#documents
= form_tag(assessment_game_documents_path(@game)) do
%ul
%script{ type: "text/x-handlebars" }
{{#collection Game.DocumentsCollectionView contentBinding="Game.documentsController"}}
%li {{content.name}}
{{/collection}}
@jamesgary
jamesgary / gist:5485061
Last active December 16, 2015 19:29
Testing HTTP APIs in Ruby - @shaiguitar - RailsConf 2013

Testing HTTP APIs in Ruby

@shaiguitar

  • Everything as a service
  • Test it!
  • Problem statement: Testing a server/client HTTP API
  • Good plan:
    • Create API
    • Build client lib that can be used in confusmer apps
  • Make it easy for consumer apps to test w/ our client library
@atmos
atmos / shell_output.txt
Created July 19, 2013 01:54
how to iterate quickly on gems without cutting releases.
$ rails new foo
create
create README.rdoc
...
~$ cd foo
~/foo$ git init
Initialized empty Git repository in /Users/atmos/foo/.git/
~/foo$ git add .
~/foo$ git commit -m "initial import"
[master (root-commit) c3392c9] initial import