Skip to content

Instantly share code, notes, and snippets.

Avatar

Stephen Celis stephencelis

View GitHub Profile
View gist:72914
#import "SCListener.h" // Remember to link to AudioToolbox.framework.
// Start listening.
[[SCListener sharedListener] listen];
// Retrieve the average power.
[[SCListener sharedListener] averagePower];
// Retrieve the peak power.
[[SCListener sharedListener] peakPower];
@stephencelis
stephencelis / redcarpet.rb
Created Aug 29, 2011
Redcarpet (Markdown) template handler for Rails 3.1.
View redcarpet.rb
# config/initializers/redcarpet.rb
class ActionView::Template
class Redcarpet < Handler
include Handlers::Compilable
def compile template
::Redcarpet.new(template.source).to_html.inspect
end
end
@stephencelis
stephencelis / minifacture.rb
Last active Sep 17, 2016
factory_girl for minitest
View minifacture.rb
# factory_girl for minitest
#
# Factory.define :user do |f|
# f.login 'johndoe%d' # Sequence.
# f.email '%{login}@example.com' # Interpolate.
# f.password f.password_confirmation('foobar') # Chain.
# end
#
# Factory.define :post do |f|
# f.user { Factory :user } # Blocks, if you must.
View zelda-battery-tmux.sh
#!/usr/bin/env sh
#
# Works best with blinking text: the last heart will blink when you have less
# than 25% of your battery life remaining.
#
# Add the following to your `~/.tmux.conf`;
#
# set -g status-right "#[fg=red]#(path/to/zelda-battery-tmux.sh) "
battery="$(pmset -g ps | awk 'NR==2' | perl -pe 's/.*?(\d+)%.*/\1/')"
@stephencelis
stephencelis / twoby.rb
Created May 16, 2013
Pretty big/breaking change in the new Ruby 2.0.0 patch level (p0 => p195).
View twoby.rb
def keyword_fun arg = nil, **options
[arg, options]
end
keyword_fun hello: 'world', 'goodnight' => 'moon'
# Ruby 2.0.0p0
# => [nil, {:hello=>"world", "goodnight"=>"moon"}]
# Ruby 2.0.0p195
# => [{"goodnight"=>"moon"}, {:hello=>"world"}]
View burl.rb
require 'formula'
class Burl < Formula
homepage 'https://github.com/visionmedia/burl'
version '1.0.1'
url 'https://github.com/visionmedia/burl/tarball/1.0.1'
sha1 'f24bdfee9d2be74c20602aa12970f84df26214b2'
def install
system "make install"
View cached_account.rb
class CachedAccount < CachedDelegateClass(Recurly::Account)
self.cache_key = :account_code
cache_constructor :find
cache(:billing_info)
cache(:subscription) { subscriptions.live.first }
cache(:add_ons) { subscription.try(:add_ons).to_a }
cache(:plan) { subscription.try :plan }
cache(:balance) {
@stephencelis
stephencelis / emoji.txt
Created Apr 3, 2012
iOS 6 / Mountain Lion Emoji
View emoji.txt
2139 ℹ INFORMATION SOURCE
23EB ⏫ BLACK UP-POINTING DOUBLE TRIANGLE
23EC ⏬ BLACK DOWN-POINTING DOUBLE TRIANGLE
23F0 ⏰ ALARM CLOCK
23F3 ⏳ HOURGLASS WITH FLOWING SAND
26C5 ⛅ SUN BEHIND CLOUD
26D4 ⛔ NO ENTRY
2705 ✅ WHITE HEAVY CHECK MARK
2753 ❓ BLACK QUESTION MARK ORNAMENT
2757 ❗ HEAVY EXCLAMATION MARK SYMBOL
View nested_query.rb
# Helper methods to encode and parse nested query strings without a
# third-party library (e.g. ActiveSupport, Addressable, or Rack).
module NestedQuery
autoload :CGI, 'cgi'
extend self
# Dumps a hash into a nested query string.
#
# NestedQuery.encode a: [1, 3], b: { 2 => 4 }, c: 5
# # => "a%5B%5D=1&a%5B%5D=3&b%5B2%5D=4&c=5"
@stephencelis
stephencelis / Gemfile
Created Feb 15, 2011
Rails 3.1 Assets
View Gemfile
gem 'coffee-script'
gem 'compass',
:git => 'git://github.com/chriseppstein/compass.git',
:branch => 'master'
gem 'rails_assets',
:git => 'git://github.com/wycats/rails_assets.git'