Skip to content

Instantly share code, notes, and snippets.

@inf0rmer
inf0rmer / gist:ac4aaf46dd55e98a5537
Created May 19, 2014 14:30
Make sound work again in OSX
do shell script "kextunload /System/Library/Extensions/AppleHDA.kext && sleep 5 && kextload /System/Library/Extensions/AppleHDA.kext;" with administrator privileges
@inf0rmer
inf0rmer / testflight.sh
Created August 22, 2014 14:04
Automatically uploads a build to Testflight using Travis
!/bin/sh
if [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then
echo "This is a pull request. No deployment will be done."
exit 0
fi
if [[ "$TRAVIS_BRANCH" != "master" ]]; then
echo "Testing on a branch other than master. No deployment will be done."
exit 0
fi
@inf0rmer
inf0rmer / blanket-usage.rb
Last active August 29, 2015 14:12
Blanket simple usage
require 'blanket'
github = Blanket.wrap("https://api.github.com")
# Get some user's info
user = github.users('inf0rmer').get
user.login
# => "inf0rmer"
# Get a user's repos
@inf0rmer
inf0rmer / blanket-wrapper-method_missing.rb
Created December 30, 2014 16:19
Blanket::Wrapper's dynamic method dispatching
def method_missing(method, *args, &block)
Wrapper.new uri_from_parts([method, args.first]), {
headers: @headers,
extension: @extension
}
end
@inf0rmer
inf0rmer / blanket-wrapper-add-action.rb
Last active August 29, 2015 14:12
Blanket::Wrapper's macro-like interface for defining REST actions
def add_action(action)
define_method(action) do |id=nil, options={}|
request(action, id, options)
end
end
@inf0rmer
inf0rmer / blanket-adding-actions.rb
Created December 30, 2014 16:41
Adding RESTful actions using a "macro"-like interface
add_action :get
add_action :post
add_action :put
add_action :patch
add_action :delete
@inf0rmer
inf0rmer / http-statuses.rb
Last active August 29, 2015 14:12
Well-known HTTP status codes and their meanings (abridged)
STATUSES = {
# ...
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Resource Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
@inf0rmer
inf0rmer / blanket-generating-exception-classes.rb
Created December 30, 2014 16:53
Automatically generating ~60 Blanket::Exception subclasses
STATUSES.each_pair do |code, message|
klass = Class.new(Exception) do
send(:define_method, :message) {"#{code ? "#{code} " : ''}#{message}"}
end
klass_constant = const_set message.delete(' \-\''), klass
Exceptions::EXCEPTIONS_MAP[code] = klass_constant
end
@inf0rmer
inf0rmer / blanket-raise-exception.rb
Created December 30, 2014 16:58
Raising a well-known exception using EXCEPTIONS_MAP in Blanket
raise Blanket::Exceptions::EXCEPTIONS_MAP[500].new
@inf0rmer
inf0rmer / blanket-raise-exception-direct.rb
Last active August 29, 2015 14:12
Raising a well-known exception directly in Blanket
raise Blanket::InternalServerError.new