Skip to content

Instantly share code, notes, and snippets.

View peterkappus's full-sized avatar

Peter Kappus peterkappus

View GitHub Profile
@peterkappus
peterkappus / weekdone-rest-client.rb
Last active June 21, 2016 21:30
A draft ruby wrapper for the WeekDone REST API
class WeekDoneClient
require 'rest-client'
# Initializes a new client object
#
# @param token [String] The auth token
# @return WeekDoneClient
def initialize(token)
@token = token
end
@peterkappus
peterkappus / omniauth-weekdone.rb
Last active June 21, 2016 20:59
A draft OmniAuth strategy for WeekDone.
#A draft OmniAuth Strategy for Weekdone
#TODO: Write some tests
#TODO: Package as a gem and submit for addition to the strategy list https://github.com/intridea/omniauth/wiki/List-of-Strategies
#See the contribution guide: https://github.com/intridea/omniauth/wiki/Strategy-Contribution-Guide
require 'omniauth-oauth2'
require 'omniauth'
module OmniAuth
module Strategies
@peterkappus
peterkappus / data_copy.js
Created June 20, 2016 15:45
Google Sheets script for copying data between sheets.
function copyValues(source_name,dest_name,range_name) {
// Get Spreadsheets
var key = "<YOUR_SPREADSHEET_KEY>";
var source_sheet = SpreadsheetApp.openById(key).getSheetByName(source_name);
var target_sheet = SpreadsheetApp.openById(key).getSheetByName(dest_name);
var lastRow = source_sheet.getLastRow();
// Set Ranges
@peterkappus
peterkappus / names.txt
Created June 6, 2016 14:46
Popular given names from around the world. Taken from https://en.wikipedia.org/wiki/List_of_most_popular_given_names in June 2016
Aada
Aadya
Aaliyah
Aaradhya
Aarav
Aaron
Aasha
Abbas
Abbie
Abdallah
@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
@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 / 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 / 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 / .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 / 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")