Skip to content

Instantly share code, notes, and snippets.

@lwalen
lwalen / git-blame-colored
Created October 31, 2013 00:08
A fancy git blame. Presents code with initials of author to the left. Colors author's names and initials for easy blaming.
#!/usr/bin/env ruby
# Colorize string
class String
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end
end
class Colors
@lwalen
lwalen / remove_trailing_whitespace.sh
Created February 2, 2016 01:16
Removes trailing whitespace from modified lines
#!/bin/bash
git diff --cached --no-color > stage.diff && \
git apply --index -R stage.diff && \
git apply --index --whitespace=fix stage.diff &> log.txt && \
removals=$(egrep -v '(stage.diff:|warning:)' log.txt | wc -l | tr -d '[[:space:]]') && \
echo "whitespace removed from $removals line$([ $removals -ne 1 ] && echo 's')" && \
rm -f stage.diff log.txt
@lwalen
lwalen / lbcf.json
Created August 14, 2016 22:16
London Baptist Confession of Faith (1689) in JSON format
{
"title":"The London Baptist Confession of Faith",
"year":1689,
"chapters":{
"1":{
"title":"Of the Holy Scriptures",
"paragraphs":{
"1":"The Holy Scripture is the only sufficient, certain, and infallible rule of all saving Knowledge, Faith and Obedience; Although the light of Nature, and the works of Creation and Providence do so far manifest the goodness, wisdom and power of God, as to leave men unexcusable; yet are they not sufficient to give that knowledge of God and His will, which is necessary unto Salvation. Therefore it pleased the Lord at sundry times, and in divers manners, to reveal himself, and to declare that His will unto his Church; and afterward for the better preserving, and propagating of the Truth, and for the more sure Establishment, and Comfort of the Church against the corruption of the flesh, and the malice of Satan, and of the World, to commit the same wholly unto writing; which maketh the Holy Scriptures to be most necessary, those former ways of Gods revealing his will
package main
// Catches the SIGTERM given by ^C and waits until the end of the loop to quit.
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
# bash/zsh git prompt support
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Distributed under the GNU General Public License, version 2.0.
#
# This script allows you to see repository status in your prompt.
#
# To enable:
#
# 1) Copy this file to somewhere (e.g. ~/.git-prompt.sh).
@lwalen
lwalen / book.rb
Created May 14, 2016 20:16
Get the shortest possible unique substring that references each book of the bible
#!/usr/bin/env ruby
BOOKS = ['Genesis', 'Exodus', 'Leviticus', 'Numbers', 'Deuteronomy', 'Joshua', 'Judges', 'Ruth', '1 Samuel', '2 Samuel', '1 Kings', '2 Kings', '1 Chronicles', '2 Chronicles', 'Ezra', 'Nehemiah', 'Esther', 'Job', 'Psalms', 'Proverbs', 'Ecclesiastes', 'Song of Solomon', 'Isaiah', 'Jeremiah', 'Lamentations', 'Ezekiel', 'Daniel', 'Hosea', 'Joel', 'Amos', 'Obadiah', 'Jonah', 'Micah', 'Nahum', 'Habakkuk', 'Zephaniah', 'Haggai', 'Zechariah', 'Malachi', 'Matthew', 'Mark', 'Luke', 'John', 'Acts', 'Romans', '1 Corinthians', '2 Corinthians', 'Galatians', 'Ephesians', 'Philippians', 'Colossians', '1 Thessalonians', '2 Thessalonians', '1 Timothy', '2 Timothy', 'Titus', 'Philemon', 'Hebrews', 'James', '1 Peter', '2 Peter', '1 John', '2 John', '3 John', 'Jude', 'Revelation'].freeze
books = BOOKS.map{ |b| b.gsub(' ', '') }.sort
partials = {}
shortest = {}
i = 0
@lwalen
lwalen / jira-prepare-commit-msg
Last active August 29, 2015 14:27
Automatically add JIRA task id to git commits
#!/usr/bin/env ruby
=begin
# Git "Prepare Commit Message" Hook Script
# Description
This script will automatically add the correct JIRA task ID to the
beginning of each commit message when the branch name has the JIRA task ID.
It can be overridden if specified in the message.
@lwalen
lwalen / pivotal-prepare-commit-msg
Last active August 29, 2015 14:10
Automatically add Pivotal Tracker story id to git commits
#!/usr/bin/env ruby
=begin
# Git "Prepare Commit Message" Hook Script
# Description
This script will automatically add the correct Pivotal Story ID to the
beginning of each commit message when the branch name has the Pivotal Story ID.
It can be overridden if specified in the message.
@lwalen
lwalen / is_livable.rb
Created October 27, 2014 17:53
A nice way to say if your models are 'live', whatever that means.
#
# Setup:
# * Put this file in lib
# * Put `require 'is_livable'` in an initializer
#
# Usage:
# * Within a class like Post, do something like
# `is_livable :released_at, status: APPROVED`
# * Then you can do
# `Post.live, Post.not_live, Post.first.live?`
@lwalen
lwalen / itunes-artists-with-one-song.pl
Created April 7, 2014 01:11
Returns a list of artists with only one song from a given iTunes library or playlist file
#!/usr/bin/env perl
use v5.10;
use Mac::iTunes::Library;
use Mac::iTunes::Library::XML;
use Mac::iTunes::Library::Playlist;
my $library = Mac::iTunes::Library::XML->parse(@ARGV[0]);
my %results;
my %items = $library->items();