Skip to content

Instantly share code, notes, and snippets.

View ddrscott's full-sized avatar

Scott Pierce ddrscott

View GitHub Profile
#!/usr/bin/env ruby
require 'csv'
ARGF.each_line do |line|
a,b,c = *CSV.parse_line(line)
print CSV.generate_line([c,b,a])
end
@ddrscott
ddrscott / push_it.mp3
Last active April 4, 2017 10:31
"Push It" by Salt'N Pepa circa 1986
@ddrscott
ddrscott / postgresql93.rb
Last active November 3, 2017 16:46
Postgres Formula 9.3.14
class PostgresqlAT93 < Formula
desc "Relational database management system"
homepage "https://www.postgresql.org/"
version = "9.3.19"
url "https://ftp.postgresql.org/pub/source/v#{version}/postgresql-#{version}.tar.bz2"
sha256 "fb9e872cd9e927ba331690d86bc63dcb5a596acb7a536fa0518a3c7d43ac2fb5"
head do
url "https://git.postgresql.org/git/postgresql.git", :branch => "REL9_3_STABLE"
@ddrscott
ddrscott / readme.md
Created May 12, 2017 19:24
Wrapper scripts around the excellent WordNet CLI tools.

WordNet

WordNet® is a large lexical database of English. Nouns, verbs, adjectives and adverbs are grouped into sets of cognitive synonyms (synsets), each expressing a distinct concept. Synsets are interlinked by means of conceptual-semantic and lexical relations. The resulting network of meaningfully related words and concepts can be navigated with the browser. WordNet is also freely and publicly available for download. WordNet's structure makes it a useful tool for computational linguistics and natural language processing.

TL;DR - Dictionary and thesaurus for engineers

Installation

# install dependency
brew cask install xquartz
 
@ddrscott
ddrscott / fzf_config.zsh
Created May 16, 2017 18:38
FZF with highlighted source preview
# FZF Stuff
export FZF_DEFAULT_COMMAND='ag -g ""'
# `highlight` preview options
# WARNING: depends on `brew install highlight`
export FZF_HIGHLIGHT_PREVIEW_OPTS="--height 100% --preview '(highlight -O ansi -l {} 2> /dev/null || cat {} || tree -C {}) 2> /dev/null' --preview-window=up:40%"
# When pressing CTRL-T, only search file names (not directories)
# and display highlighted source in preview window
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
@ddrscott
ddrscott / fzf_spell.zsh
Created May 16, 2017 18:40
FZF `spell` command with dictionary preview
# WARNING: depends on `brew install wn`
# Default `fold` to screen width and break at spaces
function fold {
if [ $# -eq 0 ]; then
/usr/bin/fold -w $COLUMNS -s
else
/usr/bin/fold $*
fi
}
@ddrscott
ddrscott / random.sh
Last active June 9, 2017 21:04
Random 10th `e` opens unicorns in browser in the background
#!/bin/zsh
heart(){
zle self-insert
if [ $((RANDOM % 10)) -eq 0 ]; then
(head -$((${RANDOM} % $(wc -l < /usr/share/dict/words) + 1)) /usr/share/dict/words | tail -1 | sed -E -e "s~(.*)~https://google.com/search?tbm=isch\&q=\1~" | xargs open -g &)
fi
}
zle -N heart
bindkey 'e' heart
@ddrscott
ddrscott / v-space-widget.zsh
Last active May 18, 2017 22:35
`v<Space>` zsh binding as a shortcut for `vim <CTRL-T>some_file_name<Enter>`
#!/bin/zsh
v-space-widget(){
zle self-insert;
if [[ $LBUFFER == 'v ' ]]; then
zle fzf-file-widget && zle accept-line
fi
}
zle -N v-space-widget
bindkey ' ' v-space-widget
alias v='vim'
@ddrscott
ddrscott / randpoop.sh
Last active September 27, 2018 19:06
#!/bin/zsh
poop(){
zle self-insert
if [ $((RANDOM % 10)) -eq 0 ]; then
(printf "\e[s\e[$((${RANDOM} % $LINES + 1));$((${RANDOM} % $COLUMNS + 1))H\xF0\x9F\x92\xA9\e[u" &)
fi
}
zle -N poop
bindkey 'e' poop
@ddrscott
ddrscott / open3_demo.rb
Created July 30, 2017 17:21
open3 async test
require 'open3'
require 'benchmark'
Thread.abort_on_exception = true
lamb = lambda do |input, out, _thread|
output_thread = Thread.new do
log 'output thread started'
out.each_line do |line|
log line.strip