Skip to content

Instantly share code, notes, and snippets.

@bradland
bradland / csvanalyze.rb
Last active Aug 29, 2015
Boilerplate CSV analysis script
View csvanalyze.rb
#!/usr/bin/env ruby
require 'csv'
require 'ostruct'
require 'optparse'
require 'i18n'
require 'set' # this should only be required until i18n updates to new rev
require 'active_support/core_ext/string/inflections'
I18n.enforce_available_locales = true # I18n spams warn unless this is set
@bradland
bradland / base642ip
Created Mar 5, 2014
Convert IP address to/from base64 encoded format for BOOTP DHCP configuration in OS X Server (or other applications).
View base642ip
#!/usr/bin/env ruby
# Based on answer found here:
# http://stackoverflow.com/questions/7618598/unpack-base64-encoded-32bit-integer-representing-ip-address
require 'base64'
class App
def run(arg)
base642ip(arg)
View secure_password_generation_with_openssl.md

Secure Password Generation with OpenSSL

In an excellent write-up on [using Chef to provision a Rails/Postgres server][chefwriteup], I ran across this a [code comment][deployuser] with a suggested use of OpenSSL:

    {
      "id": "deploy",
      // generate this with: openssl passwd -1 "plaintextpassword"
      "password": "",
      // the below should contain a list of ssh public keys which should
      // be able to login as deploy
View sub.js
javascript:function replace(e){e=e.replace(/witnesses/gi,"dudes I know");e=e.replace(/allegedly/gi,"kinda probably");e=e.replace(/new study/gi,"tumblr post");e=e.replace(/rebuild/gi,"avenge");e=e.replace(/space/gi,"spaaace");e=e.replace(/google glass/gi,"virtual boy");e=e.replace(/smartphone/gi,"pokédex");e=e.replace(/electric/gi,"atomic");e=e.replace(/senator/gi,"elf-lord");e=e.replace(/car/gi,"cat");e=e.replace(/election/gi,"eating contest");e=e.replace(/congressional leaders/gi,"river spirits");e=e.replace(/homeland security/gi,"homestar runner");e=e.replace(/could not be reached for comment/gi,"is guilty and everyone knows it");return e}function replace_all_on_page(){function e(t){if(t.childNodes.length>0)for(var n=0;n<t.childNodes.length;n++)e(t.childNodes[n]);if(t.nodeType==Node.TEXT_NODE){window.el=t;t.textContent=replace(t.textContent)}}var t=document.getElementsByTagName("html")[0];e(t)}replace_all_on_page()
View doc_cache.rb
require 'google_drive'
require 'yaml'
require 'app_support'
require 'fileutils'
module DocCache
class Package < Struct.new(:name, :rows, :ws, :version, :created_at)
include AppSupport::Inflector
VERSION = '1.0.0'
DATA_DIR = File.join(Sinatra::Application::settings.root, 'data')
@bradland
bradland / whatismyip.rb
Last active Dec 27, 2015
Tells you your IP address and a xip.io address to the same for common Ruby app server ports
View whatismyip.rb
#!/usr/bin/env ruby
require 'net/http'
require 'uri'
require 'fileutils'
class App
# The website configured for this constant should serve text/plain with
# nothing but the IP address. Feel free to substitute your own.
IP_URL = 'http://wtfismyip.com/text'
@bradland
bradland / fancy_ps1.sh
Created Oct 18, 2013
Add this to your profile (.bashrc or .bash_profile).
View fancy_ps1.sh
########
# BEGIN PS1
# Sexy Solarized Bash Prompt, inspired by "Extravagant Zsh Prompt"
# Screenshot: http://img.gf3.ca/d54942f474256ec26a49893681c49b5a.png
if tput setaf 1 &> /dev/null; then
tput sgr0
if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then
BASE03=$(tput setaf 234)
@bradland
bradland / install_ruby.sh
Last active Dec 24, 2015
A reasonable Ruby install script. Includes "essential" deps.
View install_ruby.sh
# This build script will build Ruby 2.0.0-p247. You will need su to
# root or sudo as required.
# This build tested against Debian 7.0 64-bit arch, installed from net-inst image.
# These aren't specifically Ruby deps; more for building software in general
# (you probably already have them)
apt-get install -y build-essential autoconf
# These deps will support common libraries like yaml and give you the best irb experience.
@bradland
bradland / ssh-copy-id
Created Aug 14, 2013
ssh-copy-id script for OS X
View ssh-copy-id
#!/bin/sh
# Shell script to install your public key on a remote machine
# Takes the remote machine name as an argument.
# Obviously, the remote machine must accept password authentication,
# or one of the other keys in your ssh-agent, for this to work.
ID_FILE="${HOME}/.ssh/id_rsa.pub"
if [ "-i" = "$1" ]; then
View relnum-toggle.vim
" C-n to toggle relative/normal line numbers
function! NumberToggle()
if(&relativenumber == 1)
set number
else
set relativenumber
endif
endfunc
nnoremap <C-n> :call NumberToggle()<cr>