Skip to content

Instantly share code, notes, and snippets.

@moudy
moudy / Revealing_Module_Pattern.js
Created January 21, 2011 19:01
A design pattern to help structure and namespace your Javascript code.
// single global namespace
var Resturaunt = (function (window, document, $, undefined) {
// private variables
var name = 'Building on Bond',
location = (function () {
// nested private variables
var address = { street: '112 Bond St',
city: 'Brooklyn',
state: 'NY',
@moudy
moudy / vertical_div_align.html
Created January 27, 2011 15:39
aligns a div vertically on a page
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
html,body{
height:100%;
margin:0;
padding:0;}
#offset{
width:100%;
@moudy
moudy / sass with style
Created January 27, 2011 16:09
run sass with style option
sass --style compact --watch master.scss:style.css
@moudy
moudy / globals.js
Created April 1, 2011 19:31
handy code for monitoring global vars, should go at the end
if (true /* MONITOR_GLOBALS */) {
(function(){
var globals = {};
var startGlobals = [];
for (var j in window) {
globals[j] = true;
startGlobals.push(j);
}
if (true /* PRINT_INITIAL_GLOBALS */)
console.log("Initial globals: "+startGlobals.sort().join(', '));
@moudy
moudy / downloading multiple files with curl
Created April 10, 2011 18:46
download sequentially numbered files, specified using brackets [01-20] and rename them
curl http://www.cl.cam.ac.uk/~rja14/Papers/SE-[01-10].pdf -o renamed_file_#1.pdf
function () {
return Backbone.View.prototype.render(this, arguments);
return Backbone.View.prototype.render(this, Array.prototype.slice.call(arguments));
}
@moudy
moudy / .pryrc
Created February 11, 2013 20:11
# load rails or RACK app if runnning pry in a project
if Dir.exists? './config'
current_app = './config/application.rb' if File.exists? './config/application.rb'
current_app = './config/environment.rb' if File.exists? './config/environment.rb'
require current_app if current_app
end
if defined? Rails && Rails.version[0..0] == "3"
require 'rails/console/app'
require 'rails/console/helpers'
@moudy
moudy / jayz
Created February 15, 2013 17:08
#!/bin/bash
# play jay-z
jayz() {
osascript <<-EOF
tell application "iTunes" to play track 1 of playlist "Jay-Z"
EOF
}
@moudy
moudy / flv-to-mp3
Last active December 14, 2015 21:59
ffmpeg -i moviet.flv -f mp3 sound.mp3
# Detect unsuppoerted browsers exculding crawlers and chrome frame
# browser gem - https://github.com/fnando/browser
def is_unsupported_browser?
is_ie = browser.ie6? || browser.ie7? || browser.ie8?
is_firefox36 = browser.firefox? && browser.full_version.match(/^3.6.*/)
is_crawler = request.env["HTTP_USER_AGENT"].match(/\(.*https?:\/\/.*\)/) if request.env["HTTP_USER_AGENT"]
has_chrome_frame = request.env["HTTP_USER_AGENT"].match(/chromeframe/) if request.env["HTTP_USER_AGENT"]
return !has_chrome_frame && (is_ie || is_firefox36) unless is_crawler