Skip to content

Instantly share code, notes, and snippets.

View andrewle's full-sized avatar

Andrew Le andrewle

View GitHub Profile
@andrewle
andrewle / gist:2939200
Created June 15, 2012 23:22
Vim rename file
function! RenameFile()
let old_name = expand('%')
let new_name = input('New file name: ', expand('%'))
if new_name != '' && new_name != old_name
exec ':saveas ' . new_name
exec ':silent !rm ' . old_name
redraw!
endif
endfunction
map <leader>n :call RenameFile()<cr>
@andrewle
andrewle / leader-election.md
Created April 16, 2012 02:06 — forked from ryandotsmith/process-partitioning.md
Leader Election With Ruby & PostgreSQL

Leader Election With Ruby & PostgreSQL

The Problem

I have a table with millions of rows that needs processing. The type of processing is not really important for this article. We simply need to process some data with Ruby --or any other user-space programming language.

A Solution

@andrewle
andrewle / commit-msg
Created January 11, 2012 09:11
Automatically append a ticket number reference to git commit messages
#!/bin/bash
NUMLINES=$(cat "$1" |
sed '{
# Ignore the "References #blah" line
/^References \#[0-9]*/d
# Remove blank lines
/^$/d
# Remove lines containing only whitespace
/^[ \t]*$/d
#!/usr/bin/env ruby
require 'rubygems'
require 'chef'
require 'chef/client'
require 'chef/run_context'
Chef::Config[:solo] = true
Chef::Config[:log_level] = :info
Chef::Log.level(:info)
@andrewle
andrewle / output-current
Created February 23, 2011 00:55
[html5-boilerplate] Running `ant build` when optipng is not installed on OSX
# Current
$ ant build
Buildfile: /Users/andrewle/Projects/html5-boilerplate/build/build.xml
build:
[echo] Building a Production Environment...
-rev:
[echo] Increasing the build number...
Buildfile: /Users/andrewle/Projects/html5-boilerplate/build/build.xml
build:
[echo] Building a Production Environment...
-rev:
[echo] Increasing the build number...
[propertyfile] Updating property file: /Users/andrewle/Projects/html5-boilerplate/build/config/buildinfo.properties
[echo] Creating build 0009
" Lifted from http://vim.wikia.com/wiki/Xterm256_color_names_for_console_Vim
" and cleaned up alignment for for easy reference. Posted here so I can find
" this easily. //Andrew Le
" Generated from c:/pdsrc/xterm-222/256colres.h by allcolors.pl
" Xterm can display text in 256 colors, but it is hard to determine what all
" those colors are. So below is a list of the approximate names for the 256
" default colors in xterm. You can put it in your vimrc or just use it as a
" reference when in doubt.
@andrewle
andrewle / gist:636574
Created October 20, 2010 14:54
IE/Navigator Flashback
<html>
<script>
function IsNewBrowser()
{
var isIE = navigator.appName.indexOf("Microsoft") != -1;
var isNav = navigator.appName.search(/Netscape/i) != -1;
var ver = parseInt(navigator.appVersion);
if(isIE || (isNav && ver >=5) )
return true ;
return false ;
@andrewle
andrewle / projects.md
Created September 11, 2010 08:59
List of Current Projects

Productivity List

This is a list of things that I'm working on. All the projects that I want to spend more time doing that I work on depending on my mood the quality of time that I currently have.

Inspired by tips from Aaron Swartz at http://www.aaronsw.com/weblog/productivity

The Projects

@andrewle
andrewle / capture.rb
Created July 27, 2010 21:08
Get full screen shots of a list of webpages using webkit2png.py
#!/usr/bin/env ruby
PROJECT_NAME = ""
pages = %w{
... urls to pages go here
}
pages.each_with_index do |url, index|
system("python webkit2png.py -W 1200 -o #{PROJECT_NAME}_#{index} -F #{url}")