Skip to content

Instantly share code, notes, and snippets.

View joeyjiron06's full-sized avatar

Joey Jiron joeyjiron06

View GitHub Profile
@joeyjiron06
joeyjiron06 / .gitignore
Last active November 18, 2019 20:48
A chow chow test
node_modules/
@joeyjiron06
joeyjiron06 / localStorage.js
Last active October 19, 2018 04:12
Enhanced version of localStorage that saves and returns objects and primitives
/**
* An enhanced version of localStorage. It's returns typed values for each key.
* One function it does not perform is the enumerating of all the values in
* localStorage and does not provide keys. You can use the localStorage for that
*/
const ls = {};
/**
* @param {string} key - the key of the item to remove from localstorage
// inspired by https://github.com/pauldijou/redux-act
// TODO: talk about motivations, boilerplate, no action conflicts
// TODO: README
const ActionTypes = new Set();
function actionCreater(type) {
if (ActionTypes.has(type)) {
throw new Error('action type already created '+ type);
}
@joeyjiron06
joeyjiron06 / lint-staged.js
Last active September 9, 2018 00:50
Lint Staged files before committing
// use husky to add a precommit hook to your package.json like this
// npm install husky --save
// then in package.json do this under scripts
// "precommit": "node scripts/lint-staged.js",
// this file is soooo much less code and requires way less dependencies than lint-staged
// ideas taken from here https://github.com/okonet/lint-staged
const getStagedGitFiles = require('staged-git-files');
const { CLIEngine } = require('eslint');
@joeyjiron06
joeyjiron06 / .babelrc
Last active December 19, 2019 03:58
A simple Dispatcher
{
"presets": ["@babel/preset-env"]
}
@joeyjiron06
joeyjiron06 / package.json
Last active November 29, 2018 19:35
poller.js - simple javascript poller
{
"name": "poller",
"version": "1.0.0",
"description": "",
"main": "poller.js",
"dependencies": {},
"devDependencies": {
"chai": "^4.1.2",
"mocha": "^5.1.1"
},
@joeyjiron06
joeyjiron06 / cookieParser.js
Created April 11, 2018 19:56
Parse a cookie string
function parseCookie(cookie) {
let result = {};
cookie.split(';').forEach((kvPair) => {
let split = kvPair.split('=');
let key = split[0].trim();
let val = split[1].trim();
result[key] = val;
});
@joeyjiron06
joeyjiron06 / ips.js
Last active April 3, 2018 21:14
A little script that prints the IP addresses for your computer
const os = require("os");
const ifaces = os.networkInterfaces();
const ips = [];
for (let ifname in ifaces) {
ifaces[ifname].forEach(function(iface) {
if ("IPv4" !== iface.family || iface.internal) {
return;
}
ips.push({
@joeyjiron06
joeyjiron06 / TaskRunner
Created February 8, 2018 18:32
A simple utility for running tasks
A simple utility for running tasks. To run the test just install jest
npm install jest
jest taskRunner.js
@joeyjiron06
joeyjiron06 / Throttler.js
Last active November 21, 2017 20:26
A simple throttler utility function
/**
* A simple throttle utility function. Usefull for expensive methods that
* might be called very rapidly in succession
* @param {number} delay - delay in millis to throttle the function callback
* @param {function} fn - the callback to invoke when throttled
* @return {function} a method to invoke many times during a period that you would like to throttle
*/
module.exports = function throttler(delay, fn) {
if (typeof delay !== 'number') {
throw new Error('you must pass in a number');