This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author qiao / https://github.com/qiao | |
* @author mrdoob / http://mrdoob.com | |
* @author alteredq / http://alteredqualia.com/ | |
* @author WestLangley / https://github.com/WestLangley | |
*/ | |
THREE.OrbitControls = function ( object, domElement ) { | |
THREE.EventDispatcher.prototype.apply( this ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
in="$1" | |
out="$2" | |
fps=6 | |
delay=$(printf "%0.f" $(echo "scale=2;100 / $fps" | bc)) | |
mkdir gif | |
cd gif | |
ffmpeg -i $in -r $fps frame%05d.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# brew install highlight | |
pbpaste | highlight --syntax bash -k 'Andale Mono' -s molokai -O rtf | pbcopy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open3' | |
describe 'my_script' do | |
def run *args | |
options = args.extract_options! | |
args.unshift './my_script' | |
Open3.popen3(args.join(' ')) do |i, o, e| | |
i.write options[:stdin] | |
i.close |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Makes it easy to try more than one method on Object and just return nil if | |
# the Object doesn't respond to any of the methods. So, rather than: | |
# | |
# obj.try(:foo).try(:bar) | |
# | |
# you can just | |
# | |
# obj.try(:foo, :bar) | |
# | |
# Based on Object#try from ActiveSupport. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Makes it easy to access elements deep within a nested Enumerable. Rather than | |
# having to do | |
# | |
# enum[:foo] && enum[:foo][:bar] | |
# | |
# you can just do | |
# | |
# enum.try_keys :foo, :bar | |
module Enumerable | |
def try_keys *keys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
protected | |
# Define render_xxx methods for all known status codes. | |
ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE.each do |symbol, code| | |
define_method "render_#{symbol}" do |*args| | |
respond_to do |format| | |
format.html{render_error_html_file(code, (args.first || {}))} | |
format.all{head symbol} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A rake task to pull all your gists from github.com as html. | |
# | |
# This has advantages over the script embed: | |
# * the script uses document.write, which is not compatible with XHTML Strict 1.0 | |
# * document.write also can't be used after the document body has loaded (ie. no AJAX) | |
# * the gists get indexed by search engines this way | |
desc "Pull all gists from github and cache them locally" | |
task :gists do | |
uri = URI.parse 'http://gist.github.com/api/v1/yaml/gists/heisters' | |
html = YAML.load(Net::HTTP.get(uri))['gists'].inject('') do |h, gist| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make TShark dump and dissect an HTTP connection | |
sudo tshark -i3 -V -T text -i en1 -f "tcp port 80 and host <host ip>" -d "tcp.port==80,http" -R http.request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# An unintrusive, temporary DSL strategy. | |
# | |
# Why discusses Ruby DSLs and instance_eval vs. block arguments: | |
# http://hackety.org/2008/10/06/mixingOurWayOutOfInstanceEval.html | |
# | |
# This takes advantage of some Ruby 1.9 features to implement a DSL mixin that | |
# is temporary and doesn't override locally defined methods. | |
class DslInstance | |
attr_accessor :script | |
OlderNewer