Skip to content

Instantly share code, notes, and snippets.

/* written by worc, with revisions by merrycakes */
var ZipcodePopover = (function () {
var region, fragment, zipcodeMessage, zipcodeInput, countySelect, countyMessage,
okButton, target, validControlKeys;
fragment = {};
/* I've got this idea to pass in keys we want to filter for or against */
validControlKeys = [8, 37, 39, 13, 27];
@worc
worc / gist:137cabe08ee8d865c29b
Created August 14, 2014 22:28
observer pattern example JS
PortalServices['PersonalizationObserverable'] = PortalServices['PersonalizationObserverable'] || {
version : '2.0.0',
personalization : {},
observers : [],
addObserver : function(observer) {
this.observers.push(observer)
},
removeObserver : function(observer) {
var index = this.observers.indexOf(observer);
if(index > -1) {
@worc
worc / rc.xml
Last active August 29, 2015 14:16
openbox rc file
<?xml version="1.0" encoding="UTF-8"?>
<openbox_config xmlns="http://openbox.org/3.4/rc" xmlns:xi="http://www.w3.org/2001/XInclude">
<resistance>
<strength>10</strength>
<screen_edge_strength>20</screen_edge_strength>
</resistance>
<focus>
<focusNew>yes</focusNew>
<!-- always try to focus new windows when they appear. other rules do
apply -->
@worc
worc / commit-msg
Last active June 27, 2016 21:56
commit message hook to add branch name to commit message
#!/bin/sh
#TODO add a function to parse the regex match out
# Get the commit message file and the name of the branch that we're working on.
# Also grab the branch description for good measure in case we end up using that later.
MESSAGE_FILE=$1
COMMIT_MESSAGE=$(cat $MESSAGE_FILE)
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
BRANCH_DESC=$(git config branch."$BRANCH_NAME".description)
@worc
worc / .python_aliases
Created November 5, 2015 18:14
python web server alias
# -u flushes messages to the output, is a workaround to get mintty on windows to display server messages
alias pws='python -u -m http.server'
@worc
worc / objectsToArray.js
Created July 25, 2016 18:45
es5 and es6 one-liners to convert an object list to an array of objects
Object.keys(objectsList).map(key => objectsList[key]);
Object.keys(objectsList).map(function(key) {
objectsList[key];
});
var superformula = function(phi, a, b, m, n1, n2, n3) {
return Math.pow(
Math.pow(Math.abs(Math.cos(m * phi / 4) / a, n2)) + Math.pow(Math.abs(Math.sin(m * phi / 4) / b, n3)),
-1/n1);
}
@worc
worc / Shuffle.js
Last active February 21, 2018 18:16
Knuth Shuffle for Arrays
/**
* from stackoverflow: "How to randomize (shuffle) a JavaScriptArray?"
* https://stackoverflow.com/q/2450954/769780
*
* "The de-facto unbiased shuffle algorithm..."
* https://stackoverflow.com/a/2450976/769780
*/
export default (array) => {
let currentIndex = array.length, temporaryValue, randomIndex;
@worc
worc / webpack.config.js
Created October 24, 2017 00:40
bad webpack config that still works?
const path = require('path');
module.exports = [
{
name: 'local build',
entry: path.resolve(__dirname, 'src.babel.js'),
target: 'web',
output: {
path: path.join(__dirname, 'dist/js'),
filename: 'dist.js'
@worc
worc / ShuffledDeckGenerator.js
Created February 21, 2018 18:17
Iterator over a shuffled array forever
import shuffle from './shuffle';
export default function* (list) {
let index = 0;
shuffle(list);
while (list) {
if (index >= list.length) {
shuffle(list);
index = 0;