Skip to content

Instantly share code, notes, and snippets.

View westonwatson's full-sized avatar

Weston Watson westonwatson

View GitHub Profile
@westonwatson
westonwatson / querystring.js
Last active December 15, 2015 21:39
parse a(n) URI and return an object with the Key Value pairs. Original Code from the Answer here: http://stackoverflow.com/questions/979975/how-to-get-the-value-from-url-parameter. Check the history for any modifications or compare to the original in the before mentioned Question URL.
//I refactored this to except a parameter, as I would like to parse many URI Queries
function parseQueryString(query) {
//let's use an object, arrays aren't always the best for Key Value Pairs IMHO
var query_string = {};
//original code didn't take in params.
//use "window.location.search.substring(1)" to get the current URI request.
//this splits each Key Value pair by the "&" seperator
var vars = query.split("&");
@westonwatson
westonwatson / datatags.js
Last active December 15, 2015 22:59
similar to my datafill.js gist, uses data attributes instead of DOM id's
datatags = function (dataObject,parentName){
if(typeof(dataObject) == 'object') {
for(var item in dataObject) {
var value = dataObject[item];
var targetId = parentName ? (parentName + "-" + item) : (item);
targetId = '[data-'+targetId+']';
var currentSelection = $(targetId);
if (typeof(value) == 'string' || typeof(value) == 'number' || typeof(value) == 'boolean'){
@westonwatson
westonwatson / encode_numeric_ids.php
Created April 11, 2013 19:30
encode numeric id's in URI/URL's
<?php
function encode_web_display_url($url_to_encode){
if ($url_to_encode){
//boom
$request = explode('/',urldecode($_SERVER['REQUEST_URI']));
//loop
foreach($request as $request_slice){
if (is_numeric($request_slice)){
//convert
@westonwatson
westonwatson / remove-all-gems.sh
Created April 24, 2013 18:11
purge entire gem list, runs uninstall on all installed Gems.
gem list | cut -d " " -f1 | xargs sudo gem uninstall -aIx
@westonwatson
westonwatson / datediff.sql
Created June 6, 2013 12:11
sql datediff example
SELECT
CAST(DATEDIFF(d, GETDATE(), GETDATE()+1) AS VARCHAR) + ':' +
CAST(DATEDIFF(hh, GETDATE(), GETDATE()+1) AS VARCHAR) + ':' +
CAST(DATEDIFF(mi, GETDATE(), GETDATE()+1) AS VARCHAR) + ':' +
CAST(DATEDIFF(ss, GETDATE(), GETDATE()+1) AS VARCHAR)
--"d" will give you difference in Days
--"hh" will give you difference in Hours
--"mi" will give you difference in Minutes
--"ss" will give you difference in Seconds.
@westonwatson
westonwatson / rake_task.rake
Last active December 19, 2015 13:58
import using FasterCSV
namespace :db do
desc "load user data from csv"
task :load_csv_data => :environment do
require 'fastercsv'
FasterCSV.foreach("data.csv") do |row|
User.create(
:user_name => row[0],
:email => row[1],
@westonwatson
westonwatson / in-memory-local-storage-shim.js
Created July 19, 2013 12:30
a simple in memory localStorage pollyfill
(function (isStorage) {
if (!isStorage) {
var data = {},
undef;
window.localStorage = {
setItem : function(id, val) { return data[id] = String(val); },
getItem : function(id) { return data.hasOwnProperty(id) ? data[id] : undef; },
removeItem : function(id) { return delete data[id]; },
clear : function() { return data = {}; }
};
cd ~/Downloads
sudo apt-get update
sudo apt-get install build-essential chrpath git-core libssl-dev libfontconfig1-dev
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 1.9
./build.sh
@westonwatson
westonwatson / node-install.sh
Last active December 21, 2015 07:19
amp node install
apt-get update
apt-get -y install rpcbind nfs-common
apt-get -y install libfontconfig
apt-get -y install squid3
mkdir /import
#mount -t nfs -o proto=tcp,port=2049 export.domain.com:/export /import
mv /etc/squid3/squid.conf squid.conf
apt-get -y install apache2-utils
apt-get -y install git
wget http://phantomjs.googlecode.com/files/phantomjs-1.9.1-linux-x86_64.tar.bz2
@westonwatson
westonwatson / install.imagemagick.sh
Created August 27, 2013 14:46
install imagemagick and ruby lib
sudo apt-get install imagemagick librmagick-ruby