Skip to content

Instantly share code, notes, and snippets.

@aprescott
aprescott / gist:5683945
Last active December 17, 2015 22:39
An attempt at showing only git commits where a single character has been changed.
# an attempt at showing only commits where a single character has been changed.
#
# lots of false positives.
git rev-list --all --no-merges |
while read commit; do
files_changed=$(git diff $commit^ $commit --name-only | wc -l)
diffcontent="$(git diff --numstat --minimal -U0 --word-diff=porcelain --word-diff-regex=. $commit^ $commit | grep -e '^\+.$')"
if [ $files_changed -eq 1 ] && [ $(echo "$diffcontent" | wc -l) -eq 1 ] && [ ! -z "$diffcontent" ]; then
require 'benchmark'
n = 100_000
mock_methods = ('a'..'z').to_a
class Mock
end
mock_methods.each do |m|
Mock.class_eval do
@aprescott
aprescott / descrew-bt.js
Created March 21, 2013 20:16
JavaScript bookmarklet to undo a BT HomeHub's connection error page by visiting the intended URL. Visit page X, get taken to the error page, click the bookmarklet and you'll go back to X.
/*
* Save as the URL of a bookmark, and the next time your BT HomeHub takes you to a
* "problem with your connection" page, click the bookmark to go to the actual URL.
*
* This simply grabs the "org_url" parameter out of their error page and visits it.
*
* Useful if:
*
* 1. You don't want to retype URLs or open tabs repeatedly while checking to see
* the connection is up again. Just keep clicking the bookmark.
@aprescott
aprescott / gist:5184336
Created March 18, 2013 00:49
Take a selection in the page and turn it into a blockquote
//
// Take a user's selected content in the page, as HTML, and
// place it inside a blockquote.
//
// Allows the possibility of automatically converting it
// to Markdown with toMarkdown.
//
// the selection in the document -- Selection object
var sel = document.getSelection();
@aprescott
aprescott / feed.xml
Last active December 14, 2015 17:49
Sample feed.xml Liquid template for use with Serif 0.3.2. Post unique IDs are independent of URL. Note the caveats!
layout: none
<?xml version="1.0" encoding="utf-8"?>
{% assign feed_url = "http://example.com/feed" %}
{% assign feed_title = "Example Feed" %}
{% assign feed_alternate = "http://example.com/blog" %}
{% assign feed_global_unique_id = "tag:example.com,2013:TOTALLY-RANDOM-STRING-OF-CHARACTERS-GOES-HERE" %}
{% assign feed_author_name = "J. Smith" %}
@aprescott
aprescott / gist:5121481
Created March 8, 2013 23:58
Permissions and umask
def permissions_string(integer)
triplet_to_string = lambda { |x, s| x.tr("01", "-#{s}") }
integer.to_s(2).rjust(9, "0").chars.each_slice(3).map do |r, w, x|
[
triplet_to_string[r, "r"],
triplet_to_string[w, "w"],
triplet_to_string[x, "x"]
].join("")
end.join("")
@aprescott
aprescott / letterboxd-years.sh
Last active December 14, 2015 04:09
Number of films logged in Letterboxd.
#!/bin/bash
USERNAME=your-username
# -----
film_for_year() {
output=$(curl -s "http://letterboxd.com/$1/films/diary/year/$2/" | grep -Eo '([0-9]+)&nbsp;films' | grep -Eo '[0-9]+')
if [ -z "$output" ]; then
@aprescott
aprescott / gist:4996185
Last active December 14, 2015 00:08
Show all lines added to `some-dir/` in the last week (on all branches), restricted to: only newly added files, those by author matching "adam".
#
# Show all lines added to `some-dir/` in the last week (on all branches), restricted to:
#
# * only newly added files,
# * those by author matching "adam".
#
git log --author=adam --since={1.week.ago} --all --diff-filter=A -p -- some-dir/ |
# lines added
grep -E '^\+' |
@aprescott
aprescott / gist:4982269
Last active December 13, 2015 22:08
Find your longest man pages.
# Finds your longest man pages by counting `man n foo | wc -l`
# for all man pages available.
man -k . |
sed -e 's/(//' -e 's/)//' |
awk '{ print $2, $1 }' |
xargs -n 1 -I {} bash -c "echo -n -e "{}"'\t'; man "{}" | wc -l" 2>/dev/null |
awk -F$'\t' 'BEGIN { max = 0 } { if ($2 > max) { max = $2; print "max found: " max " (" $1 ")" } }'
@aprescott
aprescott / liquid_ordinals.liquid
Last active December 13, 2015 20:08
Ordinals in straight Liquid templates.
{% assign d = time | date: "%d" | plus:0 %}
{% assign d_mod = d | modulo:10 %}
{% assign ordinals = "th,st,nd,rd,th,th,th,th,th,th" | split:"," %}
{% if d > 10 and d < 14 %}
{{ d }}th
{% else %}
{{ ordinals[d_mod] }}
{% endif %}