Skip to content

Instantly share code, notes, and snippets.

View davidcornu's full-sized avatar

David Cornu davidcornu

View GitHub Profile
@davidcornu
davidcornu / jslint_textmate.rb
Created May 4, 2011 03:42
Textmate JSLint
#!/usr/bin/env ruby
require 'cgi'
lint = `/usr/local/bin/jslint4java #{ENV['TM_FILEPATH']}`
lrxp = Regexp.new(/jslint:.+.js:(\d+):(\d+):(.+)/i)
output = String.new
lint.split("\n").each do |error|
match = lrxp.match(error)
line = `cat #{ENV['TM_FILEPATH']} | head -#{match[1]} | tail -1`
@davidcornu
davidcornu / SoundParser.rb
Created August 25, 2011 17:23
Convert MP3 Files to Waveform Images in Ruby
# --------------------------------------------------------------------
# Create SoundCloud-style waveforms from mp3 files
# Author: David Cornu
# Credit for the idea goes to http://cl.ly/292t2B09022I3S3X3N2O
#
# Requirements:
# mpg123 - [ % brew install mpg123 ]
# imagemagick - [ % brew install imagemagick ]
# rmagick - [ % brew install rmagick ]
#
@davidcornu
davidcornu / install.sh
Created September 13, 2011 03:29
Media Server Easy Install
#!/usr/bin/env bash
# Usage: wget https://raw.github.com/artfox/ArtfoxMedia/master/install/install.sh -O - | sh
set -e;
echo '
_______ _______ ______ _____ _______
| | | |______ | \ | |_____|
| | | |______ |_____/ __|__ | |
_______ _______ ______ _ _ _______ ______
@davidcornu
davidcornu / gist:1506475
Created December 21, 2011 15:44
SQL Queries in Rails Console
# Show SQL queries in rails console
ActiveRecord::Base.logger = Logger.new(STDOUT) if "irb" == $0
@davidcornu
davidcornu / reload.js
Created January 16, 2012 17:09
Reload a page every 5 seconds (Useful for HAProxy)
document.write('<!DOCTYPE html><html><head><script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"><\/script></head><body>Loading...</body></html>');
setInterval(function(){
jQuery('body').load(window.location.href);
}, 5000);
@davidcornu
davidcornu / EventedClass.coffee
Created January 19, 2012 17:08
Allows CoffeeScript classes to trigger their own events and allow binding to them.
class EventedClass
bind: (event, callback) ->
@eventHandlers ||= {}
@eventHandlers[event] = [] unless @eventHandlers[event]?
@eventHandlers[event].push(callback)
return true
unbind: (event, callback) ->
@eventHandlers ||= {}
@davidcornu
davidcornu / free.sh
Created February 23, 2012 22:07
Run iPhone simulator standalone
ln -s /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app /Applications/iPhone\ Simulator.app
@davidcornu
davidcornu / manager.rb
Created March 8, 2012 22:00
Convenient command line methods
/usr/bin/ruby /Users/davidcornu/manager.rb $1 $2 $3 $4 $5
@davidcornu
davidcornu / static_controller.rb
Created March 21, 2012 19:35
http basic auth with rails
# -*- encoding : utf-8 -*-
class StaticController < ApplicationController
before_filter :admin_authentication, :only => :api_test
def index
end
def getting_started
@davidcornu
davidcornu / music.rb
Created March 30, 2012 20:29
Musical Dubstep
bassline = Thread.new do
`yes "wub" | xargs say`
end
lead = Thread.new do
`say -v cellos Doo da doo da dum dee dee doodly doo dum dum dum doo da doo da doo da doo da doo da doo da doo`
end
bassline.join
lead.join