Skip to content

Instantly share code, notes, and snippets.

View namlet's full-sized avatar

Nathan Loyer namlet

View GitHub Profile
@namlet
namlet / gist:c7558cdd99b429c373cd
Created March 26, 2015 18:35
Take jQuery.serializeArray() and map to custom Object
var serializedArray = [
{name: 'location', value:'Location one'},
{name: 'location', value:'Location two'}
]
// in practice
// var serializedArray = $(form).serializeArray();
var mappedObject = serializedArray.map(function(location){
return { location: location.value };
@namlet
namlet / gist:48dc789425b3e0b10d7b
Created January 13, 2015 20:39
Standard Ajax Call Setup
// Setup default behavior (in some init script probably)
$(document).ajaxError(function( event, jqxhr, settings, thrownError ) {
console.log('Ajax Error: ' + thrownError);
console.log('Ajax Error jqXHR: ' + jqxhr);
console.log('Ajax settings: ' + settings);
});
$.ajaxSetup({
dataType: json,
@namlet
namlet / gist:a3b5a98513f5b810ae64
Created October 23, 2014 21:08
brew doctor output
brew doctor
Warning: /usr/local/etc isn't writable.
This can happen if you "sudo make install" software that isn't managed by
by Homebrew. If a brew tries to write a file to this directory, the
install will fail during the link step.
You should probably `chown` /usr/local/etc
Warning: /usr/local/share isn't writable.
This can happen if you "sudo make install" software that isn't managed by
<script>
var handler = StripeCheckout.configure({
key: '*****',
//image: '/square-image.png',
token: function(token, args) {
// Use the token to create the charge with a server-side script.
// You can access the token ID with `token.id`
console.log(token);
console.log(args);
var pkg = {'token':token, 'args':args};
exports.charge = function(req, res){
var pkg = req.body;
var token = pkg.token;
console.log("POST BODY");
console.log(req.body);
var charge = rk.stripe.charges.create({
amount: 3999, // amount in cents, again
currency: "usd",
card: token.id,
exports.charge = function(req, res){
var pkg = req.body;
var token = pkg.token;
console.log("POST BODY");
console.log(req.body);
var charge = rk.stripe.charges.create({
amount: 3999, // amount in cents, again
currency: "usd",
card: token.id,
@namlet
namlet / gist:4332119
Created December 18, 2012 21:21
Get query string parameters from any URI or path.
function getUrlVars(path) {
var vars = {};
var parts = path.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
@namlet
namlet / gist:4112326
Created November 19, 2012 17:56
Twilio connection parameters example
var params = {
'name' : name,
'direction' : 'inbound'
};
connection = Twilio.Device.connect( params );
console.log(connection.parameters);
connection.error(function(error){
console.log("connection error!");
@namlet
namlet / array.remove.js
Created March 29, 2012 19:52
Remove an item from an array by value
Array.prototype.remove = function(itemToRemove) {
var i = 0;
while (i < this.length) {
if (this[i] == itemToRemove) {
this.splice(i,1)
} else {
i++;
}
}
return this;
@namlet
namlet / rightAlign.js
Created June 20, 2011 19:12
Align labels right-justified by making them all the same width as the largest one.
var max = 0;
jQuery("label").each(function(){
if ($(this).width() > max) max = $(this).width();
});
jQuery("label").width(max);