Skip to content

Instantly share code, notes, and snippets.

View Swivelgames's full-sized avatar

Joseph Dalrymple Swivelgames

View GitHub Profile
@Swivelgames
Swivelgames / A_Random_Gradient_Generator.js
Last active July 18, 2016 13:05
Random color gradient generator
import RGBAFader from "./RGBAFader.js";
var x = new RGBAFader();
var y = new RGBAFader();
var interval = setInterval( () => {
y.accuate();
x.accuate();
var rgbX = "rgb(";
@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 / object-watch.js
Last active November 16, 2016 22:02 — forked from eligrey/object-watch.js
object.watch polyfill in ES5
/*
* object.watch polyfill
*
* 2012-04-03
*
* By Eli Grey, http://eligrey.com
* Modified by Joseph Dalrymple, http://swivel.in
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
@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 / 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 / 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 / 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 / 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 / Sorting Results By Date Relevance, Bias Towards Future.md
Last active February 12, 2019 21:58
Sorting Results By Date Relevance, Bias Towards Future

Sorting Results By Date Relevance, Bias Towards Future

The purpose of this script is to demonstrate a sort function (@26-32) that reorders an array (dates => sortedDates) based on proximity to a specified date (search and d3o), with a bias towards future dates.

Use case includes searching for a history-related item in the past given a date. This functions serves to find the closest item relative to a date resolved from speech. For example, it is the assumption that when a user requests an item by date using "Last Tuesday", where no item exists on the date resolved from "Last Tuesday", that the user's bias will be towards the closest date more future to the one specified. This is based off of the additional assumption that the requester's memory is more likely to mistake "Wednesday" for "Tuesday", rather than "Monday" for "Tuesday" because "Wednesday" is closer to the current date, and thus their memory of it was likely to be more vivid.

These assumptions are not supported by any studies or scientif