Skip to content

Instantly share code, notes, and snippets.

@dbtlr
dbtlr / webrick.rb
Created July 25, 2012 19:51
WEBrick command line server
#!/usr/bin/ruby
require 'webrick'
require 'optparse'
options = { :port => 4000, :host => 'localhost', :root => '.' }
OptionParser.new do |opts|
opts.banner = "Usage: webrick.rb [options]"
opts.on("-p", "--port [port]", "Set the port to use, defaults to 4000.") do |p|
@dbtlr
dbtlr / .bash_profile
Created July 31, 2012 02:13
Fancy command prompt
# PS1 Prompt Style Script
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo " ("${ref#refs/heads/}")"
}
# PS1 prompt color vars
RED="\[\033[1;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
@dbtlr
dbtlr / sitemap.xml.haml
Last active March 10, 2017 18:55
Sitemap.xml file in HAML for Middleman.
<?xml version="1.0" encoding="UTF-8"?>
- pages = sitemap.resources.find_all{ |page| page.source_file.match(/\.html/) and not page.source_file.match(/source\/test\// ) }
-# Fill this array in with pages you don't want in the sitemap.
- excluded_paths = ['404']
- host = "http://yoursite.com/"
%urlset{ :xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9" }
%url
%loc= host
%priority 0.3
%lastmod= DateTime.now.to_time.iso8601
@dbtlr
dbtlr / .inputrc
Created October 28, 2013 19:29
Bash inputrc with history searching
# Make Tab autocomplete regardless of filename case
set completion-ignore-case on
# List all matches in case multiple possible completions are possible
set show-all-if-ambiguous on
# Immediately add a trailing slash when autocompleting symlinks to directories
set mark-symlinked-directories on
# Use the text that has already been typed as the prefix for searching through
#!/usr/bin/env bash
# Take all the changes and run them through PHP Lint. Let the commit fail if this fails.
git diff --cached --name-status | awk '{ if ($1 != "D") print $2}' | grep -e \.php$ | xargs -n1 php -l
exit $?
@dbtlr
dbtlr / .gitconfig
Last active December 27, 2015 04:48
[alias]
# View the SHA, description, and history graph of the latest 20 commits
l = log --pretty=oneline -n 20 --graph
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
changes = log --pretty=format:\"%h %cr %cn %Cgreen%s%Creset\" --name-status
short = log --pretty=format:\"%h %cr %cn %Cgreen%s%Creset\"
changelog = log --pretty=format:\" * %s\"
shortnocolor = log --pretty=format:\"%h %cr %cn %s\"
# View the current working tree status using the short format
s = status
@dbtlr
dbtlr / freetype_fix.sh
Created December 10, 2013 22:13
Fixes freetype installation, as related to the installation of PHP 5.4 on OS X Mavericks.
brew rm freetype
brew install https://raw.github.com/mxcl/homebrew/0e450f2c2be7450934a3fdcc6537e3fa90c118aa/Library/Formula/freetype.rb
brew unlink freetype
brew install freetype # So dependency does not fail
brew switch freetype 2.4.11
+----+-------+-------------------------------+
| id | name | total_cold_inquiries_received |
+----+-------+-------------------------------+
| 2 | Mike | 1 |
| 4 | Bill | 2 |
| 5 | Kate | 1 |
| 6 | Sue | 1 |
| 7 | Linda | 2 |
| 8 | Mary | 1 |
+----+-------+-------------------------------+
+----------------+-------+---------------------+---------------------+
| sender_user_id | name | num_users_contacted | num_users_responded |
+----------------+-------+---------------------+---------------------+
| 3 | Greg | 1 | 1 |
| 1 | John | 4 | 0 |
| 7 | Linda | 1 | 1 |
| 6 | Sue | 2 | 2 |
+----------------+-------+---------------------+---------------------+
-- Setup some tables.
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1;
CREATE TABLE `internal_messages` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`owner_user_id` int(11) DEFAULT NULL,