Skip to content

Instantly share code, notes, and snippets.

View greatseth's full-sized avatar

Seth Thomas Rasmussen greatseth

View GitHub Profile
#!/usr/bin/env ruby
class Array
def nearest_to(given)
if given < min
min
elsif given > max
max
else
low, high = map do |r|
_\m/ store (master) | ffmpeg -y -i ../videos/dinner.3g2 -sameq -f mp4 -s cif -r 25 -ar 32000 -ac 2 dinner.mp4
FFmpeg version git-611415b, Copyright (c) 2000-2008 Fabrice Bellard, et al.
configuration: --prefix=/usr/local --enable-libmp3lame --disable-vhook --enable-shared --disable-mmx --enable-libfaac --enable-libfaad --enable-gpl --enable-libx264 --enable-libamr-nb --enable-libamr-wb --enable-nonfree
libavutil 49.12. 0 / 49.12. 0
libavcodec 52. 7. 0 / 52. 7. 0
libavformat 52.23. 1 / 52.23. 1
libavdevice 52. 1. 0 / 52. 1. 0
built on Feb 6 2009 09:49:33, gcc: 4.0.1 (Apple Inc. build 5490)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '../videos/dinner.3g2':
Duration: 00:03:36.00, start: 0.000000, bitrate: 241 kb/s
@greatseth
greatseth / blankslate.rb
Created January 30, 2009 22:36
basic object class from Builder
#!/usr/bin/env ruby
#--
# Copyright 2004, 2006 by Jim Weirich (jim@weirichhouse.org).
# All rights reserved.
# Permission is granted for use, copying, modification, distribution,
# and distribution of modified versions of this work as long as the
# above copyright notice is included.
#++
ruby(2802) malloc: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
ruby(2802) malloc: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
ruby(2802) malloc: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
ruby(2802) malloc: *** mmap(size=2097152) failed (error code=12)
def inject_status_in_response
yield
case request.format.to_sym
when :json
json = JSON.parse response.body
json["status"] = {
:code => response.status[/\d+/],
:message => @status_message
}
response.body = json.to_json
Shoes.app :width => 300, :height => 300 do
(1..9).each do |n|
stack :width => 100, :height => 100 do
border black
click { alert "clicked stack #{n}" }
end
end
end
>> j.to_json
=> "{\"current_status\": \"completed\", \"downloading_progress\": 100, \"complete?\": true, \"id\": 74, \"downloading_status\": \"Download complete\", \"encoding_progress\": 100, \"encoding_status\": \"complete\", \"delivering_progress\": 100, \"current_progress\": null, \"delivering_status\": \"Delivery complete\"}"
>> { :jobs => [j] }.to_json
TypeError: wrong argument type Hash (expected Data)
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/json/encoding.rb:21:in `to_json'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/json/encoding.rb:21:in `send'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/json/encoding.rb:21:in `encode'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/json/encoding.rb:31:in `raise_on_circular_reference'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/json/encoding.rb:20:in `encode'
from /usr/local/lib/ruby/ge
class FeelMyFlow < Widget
def initialize
stack do
para "new"
para "lines"
para "plz"
end
end
end
// form posts to a different url
// change 'subscribe' callback to 'unsubscribe'
// change loading
var form_element = obj.down('form');
var onsubmit = form_element.getAttribute('onsubmit').toString();
var onloading = 'onLoading:function(request){subscription_loading_unsubscribed(\'' + container_id + '\')}';
var new_onsubmit = onsubmit.gsub(/'\/subscriptions\/[\d]+'/, "'\/subscriptions'").gsub(/\{unsubscribe\(/, '{subscribe(').gsub(/onLoading:function\(request\)\{[^}]+\}/, onloading);
form_element.setAttribute('onsubmit', new_onsubmit);
<form onsubmit="new Ajax.Request(&#39;/subscriptions/800&#39;, {asynchronous:true, evalScripts:true, onComplete:function(request){replace_all_duplicate_buttons(&quot;subscribeForm-Show52&quot;,
&quot;SubscribeForm-Show52&quot;);}, onLoading:function(request){subscription_loading_subscribed(&#39;SubscribeForm1-Show52&#39;)}, onSuccess:function(request){unsubscribe(&#39;SubscribeForm1-Show52&#39;, request.responseText.evalJSON());}, parameters:Form.serialize(this)}); return false;" method="post" id="new_subscription" class="subscriptionForm" action="/subscriptions/800">
<input type="submit" value="Unsubscribe from Show" title="Unsubscribe from Show" name="commit" class="submitButton input_submit unsubscribe"/>
<label><span>New Saturday Night Live videos will be posted to your subscriptions feed in your profile.</span></label>
<input type="hidden" name="_method" value="delete"/><input type="hidden" name="format" value="js"/></form>