Skip to content

Instantly share code, notes, and snippets.

for video in $*
do
dimension=`exiftool "$video" | grep 'Image Size' | while read a b c d; do echo $d; done`
ffmpeg -i "$video" -s $dimension -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=7 > "$video.gif"
done
#!/usr/bin/env ruby
require 'socket'
require 'fileutils'
if ENV['MAC_HOST'] && ENV['MAC_PORT']
if child_pid = fork
loop do
begin
puts "Connecting..."
@choonkeat
choonkeat / add-gitproj-as-rails-plugin
Created November 19, 2008 02:57
add-gitproj-as-rails-plugin
#!/bin/bash
PROJECT=$1
GITPATH=$2
if test -z "$PROJECT" || test -z "$GITPATH"
then
echo Usage: $0 project gitpath
exit 1
fi
git remote add -f $PROJECT $GITPATH
@choonkeat
choonkeat / gist:32869
Created December 6, 2008 13:02
backup cron (backups of last 7 days, last month or any year)
#!/bin/bash
#
# place this file in the directory you want to keep the backup
# mysqldumps. this script lets you retrieve dumps of last 7 days,
# last month or any year
#
BACKUP_DB=app_production
cd `dirname $0`
mysqldump $BACKUP_DB -u root > today.sql && \
@choonkeat
choonkeat / gist:43643
Created January 6, 2009 03:00
loop thru elements, show border, 0-padding, 0-margin to find layout-culprit in IE6
var searchtext = $('.searchtext')[0];
function slow_hunt_for_ie(items, index) {
items = items || $('#ele, #ele *');
index = index || 0;
searchtext.value = index;
var max = index + 5;
for (; index < max && index < items.length; index++) {
$(items[index]).css({
border: '1px #000 solid',
margin: '0px',
# Modified from http://errtheblog.com/posts/50-vendor-everything
Dir["#{File.join(File.dirname(__FILE__), '..')}/vendor/gems/**"].map do |dir|
require_paths_file = File.join(dir, ".require_paths")
paths = File.exists?(require_paths_file) ?
IO.read(require_paths_file).split(/[\r\n]+/).collect {|subdir| File.join(dir, subdir) } :
[(File.directory?(lib = "#{dir}/lib") ? lib : dir)]
$LOAD_PATH.unshift(*paths)
end
@choonkeat
choonkeat / gist:64557
Created February 15, 2009 01:45
a commonly needed server side component: expand tinyurl (et al)
class BigurlsController < ApplicationController
def index
url = URI.parse(params[:url])
res = Net::HTTP.start(url.host, url.port) {|http| http.get([url.path, url.query].compact.join('?'), "User-Agent" => request.user_agent) }
render :text => (res['location'] || params[:url])
rescue
"#{params[:url]}##{$!.to_s}"
end
end
@choonkeat
choonkeat / gist:75025
Created March 6, 2009 19:20
irbrc config to make irb or script/console output be copy-paste friendly
# Append this content into ~/.irbrc
#
# irb console prompt to make the output copy-paste friendly
# overrides :simple for use in Rails' script/console
# overrides :default for use in regular irb session
IRB.conf[:PROMPT][:SIMPLE] = IRB.conf[:PROMPT][:DEFAULT] = {
:PROMPT_I => "\"%N(%m):%03n:%i>\"; ", # normal prompt: an inconsequential statement, a string
:PROMPT_S => "", # prompt for continuing strings: nothing
:PROMPT_C => "", # prompt for continuing statement: nothing
:RETURN => "#=> %s\n" # return value output is commented to not disrupt the code flow
@choonkeat
choonkeat / gist:78819
Created March 13, 2009 23:09
This controller illustrates the problem of Rails sending "Set-Cookie" back to the client when cookie-store is being used -- even when session data has NOT changed
# This controller illustrates the problem of Rails sending "Set-Cookie" back to the client
# when cookie-store is being used -- even when session data has NOT changed.
class HomeController < ApplicationController
def index
%w[one two three four five six].each do |word|
session[word] = word
end
render :text => "<a href='#{url_for(:action => 'show')}'>click here</a>"
end
def simple_inline_css(html, *css_files)
doc = Hpricot(html)
css_files.each do |css_file|
css_content_without_comments = IO.read(css_file).gsub(/\/\*.*?\*\//m, '')
css_content_without_comments.split('}').each do |rule|
(match, properties) = rule.split('{')
next unless properties
match.gsub!(/^\s*|\s*$/, '')
properties.gsub!(/^\s*|\s*$/, '')
(doc/match).each do |ele|