Skip to content

Instantly share code, notes, and snippets.

View peterkappus's full-sized avatar

Peter Kappus peterkappus

View GitHub Profile
@peterkappus
peterkappus / haml-sass builder
Created August 24, 2011 23:33
Haml/Sass builder script (great for Wordpress themes & other HTML-like templates)
require 'digest/md5'
=begin
About:
This script automatically runs on a 2-second loop, searches the current directory for haml & sass files that have been modified since the last iteration and builds them as needed into a file with the same name minus the .haml/sass extension. I wrote it so I could use Haml & Sass to develop Wordpress themes.
How-to:
1) Name your source files with the extension you'd like them to have, then add ".haml" or ".sass" as appropriate...
For example: index.php.haml and styles.css.sass
@peterkappus
peterkappus / capirb.txt
Last active January 10, 2021 11:52
Quick start for using Capybara in IRB with Chromedriver
# copy and paste this into your terminal to start an IRB session and use Capybara's DSL to write tests interactively
# Thanks to Tom Clements
# http://tom-clements.com/blog/2012/02/25/capybara-on-the-command-line-live-browser-testing-from-irb/
# I prefer using chrome...
# First you need to install the chromedriver https://sites.google.com/a/chromium.org/chromedriver/downloads
# Unzip, and move the executable somewhere in your path...
# e.g.
mv ~/Downloads/chromedriver /usr/local/bin
@peterkappus
peterkappus / get_json.rb
Created May 23, 2012 13:39
Get JSON: Simple wrapper to get JSON from a URL
require 'json'
require 'net/http'
def get_json(url)
JSON.parse(Net::HTTP.get_response(URI.parse(url)).body)
end
@peterkappus
peterkappus / dabblet.css
Created July 30, 2012 21:28
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height: 100%;
@peterkappus
peterkappus / fix_utf8.rb
Last active August 29, 2015 14:04
Fix those annoying "invalid byte sequence in UTF-8" errors when parsing CSVs, etc. Just strips out undef/invalid chars. Use with caution.
#Fix those annoying "invalid byte sequence in UTF-8" errors when parsing CSVs, etc.
#prints to STDOUT where you can redirect to a new file, etc.
#NOTE: this just strips out invalid/undef characters which may be a Very Bad Thing™ - YMMV
#suggestions welcome...
#also fix annoying newlin chars created by excel... replace \r with \r (weird but works)
input_file = ARGV[0] or raise "No input file specified"
puts IO.read(input_file).encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '').gsub(/\r/,"\r")
@peterkappus
peterkappus / .bash_profile
Last active August 29, 2015 14:11
Simple command line logger/todo adder
#handy bash functions to easily add things to text files
#todo list
td() { echo $@ >> /path/to/your/todo.txt; }
#log (with date time stamp)
log() { echo $(date) $@ >> /path/to/your/log.txt;}
@peterkappus
peterkappus / Gemfile
Created August 18, 2015 22:20
Rails 4 Gemfile with Sass, bootstrap, slim, postgresql, kaminari
#my rails 4 gemfile with
#bootstrap
#sass
#postgresql
#slim templates
#puma
#blahblahblah :)
#for heroku, make a Procfile like so:
# web: bundle exec rails server -p $PORT
@peterkappus
peterkappus / csv_to_flare.rb
Last active January 26, 2022 23:06
Turn a multi-column CSV file into the nested "flare.json" structure required by D3 for a collapsible tree diagram like this: https://bl.ocks.org/mbostock/4339083
# What: Turn a multi-column CSV file into the nested "flare.json" structure required by D3 for a collapsible tree diagram like this: https://bl.ocks.org/mbostock/4339083
# I couldn't find a generic way to do this so I wrote this script. Help & comments welcome!
# How: Nested hashes group the data. Then a recurive function builds a new hash with the correct format for the JSON.
# Caveats: Currently supports up to 4 levels/columns of depth
# TODO: make it generically support n-levels
# Who: Peter Kappus (http://kapp.us)
# CSV Format:
# Create a CSV called "data.csv" with any headers you like. It might look like this:
# group_name, team_name, person_name
@peterkappus
peterkappus / actuals_converter.html
Created March 9, 2016 17:57
Simple HTML/JS tool to convert actuals data from finance format to the format required by the Del Ops reporting tools.
<body xonload="convert()">
<script language="javascript">
function convert(){
source_rows = document.getElementById('raw_input').value.split("\n")
headers = source_rows.shift().split("\t");
//rows now contains only data
data = []
for(i in source_rows){
interim_row_data = {}
@peterkappus
peterkappus / build_for_society6.rb
Last active March 9, 2016 23:15
Easily convert an SVG file into the various files required to sell things on Society 6.
#usage: ruby build... [INPUT_FILE]
#what it does: makes a folder named after the input file and builds the necessary versions for S6
#requirements: rsvg-convert to rasterise the SVG and imagemagick to make the versions
file = ARGV[0] or abort ("No input file specified.")
big_width = 6500
basename = File::basename(file,".svg")
Dir::mkdir(basename,0700) unless File.exists? basename