Skip to content

Instantly share code, notes, and snippets.

View pads's full-sized avatar

Ben Paddock pads

View GitHub Profile
@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();
@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 / 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 / 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 / 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 / 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 / config.js
Created June 26, 2015 16:00
Angular Bootstrap Dynamic Popover Placement
$tooltipProvider.setTriggers({
// other trigger config
'customOpen':'customClose'
});
@pads
pads / Arguments assignment fix
Created November 29, 2012 16:59
@FND's suggested fix for arguments assignment
var args = Array.prototype.slice.apply(arguments);
args[2] = false;
@pads
pads / configure_npm.sh
Last active December 15, 2015 02:39
Various scripts to install TiddlySpace on a barebones Ubuntu server.
#!/bin/sh
#
# Run this script before installing twikifier/twsock and after installing node
#
npm config set registry http://registry.npmjs.org/
# Omit this step if a proxy is not needed
npm config set proxy http://<host>:<port>
@pads
pads / ts-import-space.sh
Last active December 16, 2015 15:59
Export tiddlers from the public and private bags of a space belonging to one instance of TiddlySpace and import them onto a different instance of TiddlySpace.
#!/bin/sh
USAGE="Usage: `basename $0` <src_space_url> <src_space> <src_user>
<src_pwd> <dest_space_url> <dest_space> <dest_user> <dest_pwd>
Overwrite SRC_TS_CHALLENGER and/or DEST_TS_CHALLENGER
to use a custom authentication method.
The default is tiddlywebplugins.tiddlyspace.cookie_form
"