Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/ruby -rubygems
# This is a replacement for "livereload" gem for working with Rails.
# It watches the filesystem with OS X FSEvents rather than with EventMachine.
# This is better for large projects for wich EventMachine fails.
#
# Sass is supported; .sass files can also be stored in "app/styles/" directory.
#
# Command line options are "-D" to enable debug mode. All other parameters
# (if given) specify a list of directories to watch.
@micho
micho / Prompt git branch for bash
Created September 10, 2010 12:00
Git branches on terminal prompt. Add to your .bash_profile file
# This will add the git branch to your path, with something like this:
# ~/code/teambox[master]:
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/[\1]/'
}
function precmd() {
PROMPT="%n@%m %~$(parse_git_branch)%# "
}
@micho
micho / gist:728639
Created December 5, 2010 00:40
Throttle and debounce examples
// Run the function as soon as it's called, but prevent further calls during `delay` ms
// Example: function.throttle(200) will only run function() once every 200 ms.
// Useful, for example, to avoid constant processing while typing in a live search box.
Function.prototype.throttle = function(delay) {
var fn = this
return function() {
var now = (new Date).getTime()
if (!fn.lastExecuted || fn.lastExecuted + delay < now) {
fn.lastExecuted = now
fn.apply(fn, arguments)
@micho
micho / gist:870485
Created March 15, 2011 09:15
CAPSLOCK PLUGIN FOR TALKERAPP.COM
plugin.onMessageSend = function (event) {
if ((new Date()).getDate() === 14) {
if ((event.content.match(/^([a-z]+)$/) || [false])[0]) {
alert('Y U NO UZ CAPSLOCK?');
}
Talker.sendMessage(event.content.toUpperCase());
Talker.getMessageBox().val('');
return false;
}
else {
@micho
micho / gist:872697
Created March 16, 2011 15:46
Cloudapp plugin for Talkerapp
plugin.onMessageSend = function (event) {
var match, url, content;
if (match = event.content.match(/(https?:\/\/cl.ly\/[^\/]+)(\/[^\/]+)*/)) {
url = match[1] || false;
content = match[2] || false;
if (!content || content.indexOf('/content') != -1) {
event.content = event.content.replace(url, url+'/content#.png');
Talker.sendMessage(event, "");
Talker.getMessageBox().val('');
return false;
@micho
micho / gist:1120193
Created August 2, 2011 13:37
Prompt branch for bash
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/[\1]/'
}
function precmd() {
PROMPT="%n@%m %~$(parse_git_branch)%# "
}
export PATH="/usr/local/mysql/bin:${PATH}:/usr/local/git/bin"
function proml {
@micho
micho / nginx.conf
Last active September 29, 2023 16:38 — forked from unixcharles/nginx.conf
nginx config for http/https proxy to localhost:3000
First, install nginx for mac with "brew install nginx".
Then follow homebrew's instructions to know where the config file is.
1. To use https you will need a self-signed certificate: https://devcenter.heroku.com/articles/ssl-certificate-self
2. Copy it somewhere (use full path in the example below for server.* files)
3. sudo nginx -s reload
4. Access https://localhost/
Edit /usr/local/etc/nginx/nginx.conf:
@micho
micho / gist:1733598
Created February 3, 2012 23:17
Prevent stupid Mac scroll
/**
* Show a notice when Mac's stupid scroll happens
* http://micho.biz/mac-osx-lion-horizontal-scroll-event/
*/
Global.preventStupidMacScroll = function () {
var self = this,
broken_browser = navigator.userAgent.match(/Macintosh/),
hide = Teambox.models.user.get('settings').hide_scroll_notice;
if (!broken_browser || hide) {
@micho
micho / debug.js
Created February 9, 2012 10:50
debug times for js
/**
* Create a debugger with the given `name`.
*
* @param {String} name
* @return {Type}
* @api public
*/
function debug(name) {
var now = Date.now();
alert(1)