Skip to content

Instantly share code, notes, and snippets.

View pads's full-sized avatar

Ben Paddock pads

View GitHub Profile
@pads
pads / update_shrinkwrap.sh
Last active February 24, 2017 10:55
The NPM shrinkwrap dance
#!/bin/sh
if [ "$#" -ne 1 ]; then
echo "Usage: update_shrinkwrap.sh <package-name@version|git-repo#version>"
exit 1;
fi
npm cache clean
npm prune
rm -rf node_modules
@pads
pads / config.js
Created June 26, 2015 16:00
Angular Bootstrap Dynamic Popover Placement
$tooltipProvider.setTriggers({
// other trigger config
'customOpen':'customClose'
});
@pads
pads / multi_csv_processor.rb
Created April 3, 2015 10:05
Processing some CSV files for some Psychology PhD statistics work
require 'csv'
# Iterate through each CSV file in the current folder
Dir.glob('*.csv') do |csv_filename|
# Create and open a new file to store the modified rows
csv_output_file = CSV.open("modified-#{csv_filename}", 'wb')
# Open the current file by filename
CSV.open(csv_filename, 'r') do |csv_contents|
# Iterate through each row in the CSV file
csv_contents.each do |row|
@pads
pads / processor.rb
Last active August 29, 2015 14:13
Find the location(s) of the max value in two result sets within a CSV of survey results
require 'csv'
csv_contents = CSV.read('Data.csv')
# Shift 3 rows of headers to get to the data
csv_contents.shift
csv_contents.shift
csv_contents.shift
set1 = []
set2 = []
@pads
pads / recursive-rollback.coffee
Created December 18, 2014 13:58
Ember Recursive Model Rollback
# Ember data does not dirty the parent model if any of it's children change so
# no rollback can occur for a child. This fixes this by resetting a child's
# data to the internal data tracked by the parent model.
DS.Model.reopen
rollbackBelongsTo: (relationshipName) ->
thisName = @constructor.typeKey
relationshipInstance = @get relationshipName
# Rollback any attributes that were changed in the relationship
relationshipInstance.rollback()
@pads
pads / relationship-rollback.coffee
Last active February 7, 2016 14:31
Dynamically rollback Ember model relationships
App.MyModel.eachRelationship (name, relationship) ->
relationshipInstance = modelInstance.get name
if relationshipInstance
if relationship.kind is 'belongsTo'
relationshipInstance.rollback()
else if relationshipInstance.content and relationship.kind is 'hasMany'
relationshipInstance.content.forEach (record) ->
record.rollback()
@pads
pads / Hole 1
Created November 28, 2014 09:24
WMRUG Code Golf Solutions
puts gets.to_i.to_s(2)
#
# Best solution found:
#
#puts"%b"%gets
@pads
pads / bot.js
Created November 28, 2014 09:17
BrumJS Rock Paper Scissors Bot
var hands = [
'rock',
'paper',
'scissors',
'water',
'dynamite'
];
var opponents = []
@pads
pads / di-console.js
Created April 16, 2014 10:21
Angular Dependency Injection - Console Access
var injector = angular.element('[data-ng-app="myAppName"]').injector();
var dependency = injector.get('myDependencyName');
dependency.doSomething();
function NewPane(sub, socketuri, dontcache) {
var type = sub.charAt(0),
uri = '/search?q=',
cached = localStorage.getItem('tapas'),
socket, title, el;
cached = (cached && cached.split(',')) || [];
cached.push(sub);
if (!dontcache) {
localStorage.setItem('tapas', cached.join(','));
}