Skip to content

Instantly share code, notes, and snippets.

View Swivelgames's full-sized avatar

Joseph Dalrymple Swivelgames

View GitHub Profile
@Swivelgames
Swivelgames / getCurrentStack.js
Created November 22, 2016 04:25
getCurrentStack
const getCurrentStack = () => {
try {
throw new Error();
} catch(e) {
return e.stack.replace(/[\n\r]+/g,'').match(/at\s+([^\s:]+)/g).map(v => v.replace(/at\s+/,''));
}
};
@Swivelgames
Swivelgames / camelCase.js
Last active December 2, 2016 04:44
camelCase: Like camelCase npm package, formats hyphen, period, underscore, or space separated strings in camelCase.
const camelCase = (...args) => {
let str = args.join("-")
.replace(/[ _.-]+[A-Za-z]{1}/g,
(m) => m.replace(/[^A-Za-z]/g, '').toUpperCase()
).replace(/[ _.-]/g, '');
return str[0].toLowerCase() + str.substr(1);
}
var str = "__foo___bar____---";
@Swivelgames
Swivelgames / dump.js
Last active December 2, 2016 06:46
Get All BrowserFS IndexedDB Data
var res, ret;
db
.transaction(['browserfs'], 'readwrite')
.objectStore('browserfs')
.getAll()
.onsuccess =
(event) => {
res = event.target.result.map( (arrBuff) => {
if(arrBuff.byteLength !== 66) return new TextDecoder('utf-8').decode(new Uint8Array(arrBuff));
@Swivelgames
Swivelgames / watcher.js
Created January 11, 2017 20:58
Project Watcher
var path = require('path');
var watch = require('node-watch');
var fs = require('fs-extra');
watch('./', file => {
const src = path.join('./', file);
const dest = path.join('/Volumes/projects/PROJECT_FOLDER/', file);
fs.copy(
src, dest,
@Swivelgames
Swivelgames / findNeedle.js
Created December 17, 2016 06:32
A Needle in the Haystack
var a = "a";
var b = "b";
var c = "c";
var d = "d";
var e = "e";
var f = "f";
var g = "g";
var h = "h";
var i = "i";
var j = "j";
@Swivelgames
Swivelgames / mapChildrenToObject.js
Created April 6, 2017 19:04
React Utility: mapChildrenToObject
const mapChildrenToObject = (children) => (
children.reduce((v, cV) => {
let { name } = cV.type;
if (!name) return v;
if (name === 'Connect') {
name = cV.type.displayName.replace(/Connect\((\w+)\)/g, '$1');
}
return Object.assign({}, v,
v[cV.type.name] ? {
@Swivelgames
Swivelgames / script.js
Created September 25, 2017 16:55
Obj Flatten, then Reduce Promises
const obj = { "foo": { "bar": "0", "pew": "hell world" }, "quux": { "baz": "1", "world": "wonderful" }};
const flatObj = Object.keys(obj).reduce((retObj, key) => Object.assign({},
retObj,
Object.keys(obj[key]).reduce((deepRetObj, deepKey) => Object.assign({},
deepRetObj,
{ [`${key}.${deepKey}`]: obj[key][deepKey] }
), {})
), {});
@Swivelgames
Swivelgames / toTwelveHour.js
Last active November 13, 2017 17:46
24 to 12 hour clock
/* golf */
const toTwelveHour = time => {
const [hr,min] = time.split(':');
return `${hr>12?hr-12:hr==0?12:hr}:${min}${hr>12?'PM':'AM'}`;
}
/* expanded utility */
const toTwelveHour = (time) => {
const [hour, min] = time.split(':');
const suffix = hour > 12 ? 'PM' : 'AM';
@Swivelgames
Swivelgames / FirebaseUpdateCfg.js
Created January 22, 2018 17:43
Firebase Configuration Updater
#!/usr/bin/env node
/* eslint-disable import/no-extraneous-dependencies, no-console */
const path = require('path');
const yargs = require('yargs');
const fs = require('fs');
const { spawn } = require('child_process');
const argv = yargs
.option('f', {
alias: 'file',
@Swivelgames
Swivelgames / hidePRfilesWithExtension.md
Last active April 10, 2018 20:59
Hide Files with FILE_EXTENSION when previewing PRs

Hide files with certain extension when previewing PR’s on Github

Usage

Change FILE_EXTENSION and then paste into Developer Tools console and execute.

Hidden feature: Automatically steals your information and uploads it to Chinese servers. I mean, uh… use this to hack someone’s facebook account! :D