Skip to content

Instantly share code, notes, and snippets.

View timruffles's full-sized avatar

Tim Ruffles timruffles

View GitHub Profile
@timruffles
timruffles / subs.sh
Created November 23, 2011 10:34
VLC notes
On OSX, ensure you have 64 bit VLC.
// stream to png images
$ vlc INPUT --video-filter=scene --scene-format=png --scene-path=OUTPUT_FILE
// burn in subtitles
vlc -I rc -vv INPUT --sout '#transcode{soverlay,vcodec=h264}:standard{access=file,dst=OUTPUT_FILE,mux=ts}' --sub-language=eng
vlc -I rc -vv INPUT --sout '#transcode{soverlay,vcodec=h264}:standard{access=file,dst=OUTPUT_FILE,mux=ts}' --sub-track-id=623
@timruffles
timruffles / bank_account.coffee
Created November 28, 2011 21:18
bank account closure demo
BankAccount = (balance = 0) ->
(cmd, amount = 0) ->
if cmd == "withdraw" then BankAccount balance - amount
else if cmd == "deposit" then BankAccount balance + amount
else if cmd == "balance" then balance.toFixed 2
else "What kind of person would try to #{cmd} a bank account?"
@timruffles
timruffles / container_view_model.coffee
Created January 6, 2012 14:20
Simple list viewmodel
ListView = (el) ->
views = []
["pop","shift"].each (method) =>
@[method] = ->
remove = views[method]()
el.removeChild remove.el
[["unshift","prepend"],["push","append"]].each ([array,dom]) =>
@[array] = (view) ->
views[array](view)
byModelId[view.model.id] = view
@timruffles
timruffles / fb_mobile_ua.js
Created January 9, 2012 16:57
how to force FB to use mobile widgets
FB.UA._mobile = true;
@timruffles
timruffles / another_fb_facepalm.js
Created January 10, 2012 21:16
Fix facebook fbCallID undefined on mobile, caused by using a touchstart event not a click
el.on("touchstart", function() { FB.login(function() {...}) }); // facepalm with lovely cryptic error
el.on("click", function() { FB.login(function() {...}) }); // it works!
@timruffles
timruffles / enumerable.coffee
Created January 23, 2012 17:27
Wraps function that yields (is called with) multiple values with the Enumerable API (js 1.6 Array methods)
class Enumerable
constructor: (@fn,bind) ->
if bind
fn = @fn
@fn = -> fn.apply(bind,arguments)
map: (transform) ->
results = []
@fn ->
results.push transform(
@timruffles
timruffles / enter.rb
Created February 1, 2012 11:31
when do players enter our game?
RealGame.where("first_period_start_at IS NOT NULL").where("start_at > '2011-11-09'").map do |real_game|
entries = BigGameEntry.includes(:big_game)\
.where("big_games.real_game_id = #{real_game.id}")\
.where("big_games.start_point = '1:030:00'")\
.where("big_games.end_point = '2:045:00'")\
.where("big_games.currency_code = 'GBP'")\
.where("big_games.game_type = 'short'")
[real_game,entries]
end
@timruffles
timruffles / explore.html
Created March 2, 2012 16:23
torch light in css
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(function() {
$(".masker").mousemove(function(e) {
$(this).css("-webkit-mask","-webkit-radial-gradient(" + e.clientX + " " + e.clientY + ", 170 120, rgba(0,0,0,0) 40%, rgba(0,0,0,1)) 10%")
})
})
</script>
<style type="text/css" media="screen">
.masker {
@timruffles
timruffles / conf_via_methods.rb
Created March 6, 2012 11:26
Config via override
class Conf
class << self
class << self
def if_undef method, &block
define_method method, &block unless Conf.respond_to? method
end
end
if_undef :foo do
"foo"
end
@timruffles
timruffles / coffee_monad.coffee
Created March 6, 2012 13:21
figuring out monads with coffeescript
just = (x) -> [["maybe","just"],-> x]
nothing = -> [["maybe","nothing"],->]
bind = ([[monadType,_],_],operation) ->
switch monadType
when "maybe"
maybeBind arguments[0], operation
maybeBind = ([[_,valueType],value],operation) ->