Skip to content

Instantly share code, notes, and snippets.

@ryanjadhav
ryanjadhav / classNameCodeShift.js
Created June 5, 2017 22:04
class name code shift for use with jscodeshift
'use strict';
var _ = require('lodash');
module.exports = function(file, api, options) {
const j = api.jscodeshift;
const root = j(file.source);
let hasModifications = false;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
.clock {
border: 1px solid black;
width: 400px;
@ryanjadhav
ryanjadhav / braintree_countries.json
Created May 29, 2015 18:22
braintree_countries.json
[
{
"name": "Afghanistan",
"code": "AF"
},
{
"name": "Åland",
"code": "AX"
},
{
@ryanjadhav
ryanjadhav / copy_braintree_codes.js
Last active August 29, 2015 14:22
copy_braintree_codes.js
// Copies braintree webpage table into a more easily to consume json object.
// Steps:
// 1: go to https://developers.braintreepayments.com/ios+ruby/reference/general/countries
// 2: include jquery on the page
// 3: execute js below
// grabs all country codes and puts it into a json object like so: {name: 'United States', code: 'US' }
var json = []; $('table').find('tr').each(function(i, el) { json.push({'name': $(el).find('td:nth(0)').html(), 'code': $(el).find('td:nth(1)').html()} ) }); copy(json);
function logSomething(str) {
console.log(str);
}
window.addEventListener('resize', throttle(logSomething.bind(null, 'nothing'), 250));
window.addEventListener('resize', debounce(logSomething.bind(null, 'something'), 250));
function throttle(fn, interval) {
var later;
var timerId;
@ryanjadhav
ryanjadhav / simple-debounce.js
Created April 21, 2015 05:57
Simple debounce
// ** Simple Debounce **
//
// returns a new function that will execute once and only once coalescing
// multiple sequential calls into a single execution at either the very
// beginning or end.
function debounce(callback, delay, immediate) {
var timeout;
return function() {
var context = this;
@ryanjadhav
ryanjadhav / simple-throttle.js
Last active August 29, 2015 14:19
Simple Throttle
// ** Simple Throttling **
//
// returns a new function that will execute your function
// no more than once every `interval` milliseconds.
function throttle(fn, interval) {
var later, timerId;
return function() {
var now = +new Date();
if (later && now < (later + interval)) {
@ryanjadhav
ryanjadhav / nestedNumberArray.js
Created February 12, 2014 21:05
Sum of Nested number array
var nestedNumbers = [1,2,3,[1,2,3,[12]]];
var sumOfArray = function(arr, sum) {
for (var i = 0; i < arr.length; i++) {
if (typeof arr[i] === 'object' && arr[i].length) {
sum = sumOfArray(arr[i], sum);
} else {
sum += arr[i];
}
}
@ryanjadhav
ryanjadhav / event_aggregator.js
Last active December 27, 2015 17:59
Simple Event Aggregator
// ---- Code ----
var EventAggregator = function() {
this.events = {};
}
EventAggregator.prototype.trigger = function (msg) {
var args = Array.prototype.splice.call(arguments, 1);
for(var i = 0, len = this.events[msg].length; i < len; i++) {
this.events[msg][i].apply(this, args);
@ryanjadhav
ryanjadhav / terminal_config
Created July 10, 2012 18:06
Terminal Configuration
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
export PS1='\W\$ '