This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os.path | |
import collections | |
from operator import itemgetter | |
WORDFILE = '/usr/share/dict/words' | |
class Autocorrect(object): | |
""" | |
Very simplistic implementation of autocorrect using ngrams. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Levenshtein edit distance calculator | |
* Usage: levenstein <string> <string> | |
* | |
* To compile: | |
* sudo xcode-select -switch /Applications/Xcode6-Beta.app/Contents/Developer | |
* xcrun swift -sdk $(xcrun --show-sdk-path --sdk macosx) levenshtein.swift | |
*/ | |
import Foundation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import select | |
from logging import DEBUG, ERROR | |
def call(popenargs, logger, stdout_log_level=DEBUG, stderr_log_level=ERROR, **kwargs): | |
""" | |
Variant of subprocess.call that accepts a logger instead of stdout/stderr, | |
and logs stdout messages via logger.debug and stderr messages via | |
logger.error. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# gbd - interactive git branch deletion | |
# based off https://www.peterp.me/articles/cli-tips-interactive-branch-delete/ | |
# use tab to select multiple | |
# Drop this in your .bashrc or .zshrc (assumes fzf is installed) | |
gbd() { | |
local branches branch | |
branches=$(git for-each-ref --sort=-committerdate refs/heads/ --format="[%(committerdate:short)] %(color:bold green)%(refname:short)%(color:reset) - %(contents:subject)" --color=always | egrep -v main) && | |
branch=$(echo "$branches" | fzf --multi --ansi --preview 'git show {2}' ) && | |
git branch -D $(echo "$branch" | awk '{print $2}') | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# mysql-style output for an array of ActiveRecord objects | |
# | |
# Usage: | |
# report(records) # displays report with all fields | |
# report(records, :field1, :field2, ...) # displays report with given fields | |
# | |
# Example: | |
# >> report(records, :id, :amount, :created_at) | |
# +------+-----------+--------------------------------+ | |
# | id | amount | created_at | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Versioning.sh | |
# | |
# https://gist.github.com/791352 by Marc Hedlund | |
# | |
# Found at http://kswizz.com/post/2686511526/git-xcode-versioning and slightly | |
# modified. | |
# To install: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sublime_plugin | |
class StripTrailingWhitespaceCommand(sublime_plugin.TextCommand): | |
""" | |
Strip whitespace from the end of each line in the file. | |
""" | |
def run(self, edit): | |
trailing_white_space = self.view.find_all("[\t ]+$") | |
trailing_white_space.reverse() | |
for r in trailing_white_space: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from datetime import datetime | |
import urllib.request | |
import re | |
# grab the word list | |
words_url = 'https://www.powerlanguage.co.uk/wordle/main.c1506a22.js' | |
req = urllib.request.Request(words_url, data=None, | |
headers={ | |
'User-Agent': 'Wordle "Solver" 1.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sum an array, optionally providing a function to call on each element of the | |
// array to retrieve the value to sum | |
Array.prototype.sum = function(fn) { | |
return this.reduce(function(accum, elem) { | |
return accum + (fn ? fn(elem) : elem); | |
}, 0); | |
}; | |
// flatten an array | |
// [1,2,[3,4]] -> [1,2,3,4] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIImage+Resize.swift | |
// Port of UIImage+Resize.m | |
// from http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/ | |
// | |
import Foundation | |
import UIKit | |
extension UIImage { |
NewerOlder