Skip to content

Instantly share code, notes, and snippets.

@sorensen
sorensen / tic-tac-toe.py
Created December 5, 2018 22:19
hackerrank tic-tac-toe solution
#!/bin/python
import random
# ------------------------------------------------------------------------------
# Constants
# ------------------------------------------------------------------------------
# Moves
_ = 0
X = 1
@sorensen
sorensen / tendon.js
Created July 23, 2015 18:12
Backbone / DOM Bindings
/*!
* (c) 2015 Beau Sorensen
* MIT Licensed
* For all details and documentation:
* https://github.com/sorensen/tendon.js
*/
// TODO: Verify on-change detection for all HTML element types
;(function() {
@sorensen
sorensen / LICENSE.txt
Last active August 29, 2015 14:17 — forked from 140bytes/LICENSE.txt
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@sorensen
sorensen / memory-store.js
Created May 14, 2014 17:08
Memory store with limit
'use strict';
/*!
* Module dependencies.
*/
var config = {}
, cache = {}
, timeouts = {}
, limit = config.size_limit
@sorensen
sorensen / obj-flatten.js
Created April 23, 2014 16:33
Object flatten
/**
* Object flattener
* http://stackoverflow.com/questions/19098797/fastest-way-to-flatten-un-flatten-nested-json-objects
*
* @param {Object} obj to flatten
* @return {Object} flattened obj
*/
function flatten(data) {
var result = {}
@sorensen
sorensen / get-args.sh
Created April 2, 2014 15:18
Bash argv setup
APPLE=
BANANA=
CARROT=
DINOSAUR=false
ELEPHANT=false
while true; do
case "$1" in
-a | --apple ) APPLE=$2; shift 2 ;;
-b | --banana ) BANANA=$2; shift 2 ;;
@sorensen
sorensen / argv.js
Created April 1, 2014 23:07
Get argv input
var argv = process.argv
, slice = Array.prototype.slice
function getArg() {
var args = slice.call(arguments)
for (var i = 0; i < args.length; i++) {
var name = args[i]
, idx = argv.indexOf(name)
@sorensen
sorensen / defined.js
Created April 1, 2014 23:02
Find first defined argument
/**
* Get first defined argument
*
* @param {...} any argument(s)
* @return {Any} first defined argument
*/
exports.defined = function() {
var args = Array.prototype.slice.call(arguments);
@sorensen
sorensen / example.js
Last active December 31, 2015 02:19
date format
var val = someUserInput
// Check to see if a valid timestamp was used
if (!isNaN(+val)) {
if (val.length === 13 || val.length === 10) {
return new Date(val.length === 10 ? +val * 1000 : +val);
}
}
// Check if the string could be parsed by the date formatter
@sorensen
sorensen / backbone-constructor.js
Created November 13, 2013 20:08
Backbone constructor override.
;['View'
, 'Model'
, 'Collection'
, 'Router'
].forEach(function(klass) {
var original = Backbone[klass]
Backbone[klass] = original.extend({
constructor: function() {
// Custom logic here...
return original.apply(this, arguments);