Skip to content

Instantly share code, notes, and snippets.

View juniorbird's full-sized avatar

Wade Armstrong juniorbird

View GitHub Profile
@juniorbird
juniorbird / composefunctions.php
Last active June 21, 2016 23:01
Composing functions in PHP
<?php
$sorted_arr = function ($range_to_sort) {
// Annoyingly, PHP can't return the sorted array from a sort
// Do it manually
usort($range_to_sort, function ($a, $b)
{
@juniorbird
juniorbird / forloop.py
Last active June 17, 2016 22:40
A simple implementation of Merge Ranges in Python, using a for loop
def free_times(calendar_list):
output = []
# This is easier with a list sorted by start time
# sort() is mergesort, with O(n) = n log n
# which is fast enough to not manually sort.
calendar_list.sort(key = lambda event: event[0])
for index in range(len(calendar_list)):
if (index > 0):
@juniorbird
juniorbird / reduce.py
Last active June 17, 2016 22:47
A simple implementation of Merge Ranges in Python, using reduce
from functools import reduce
def merge_arrays(accumulator, new):
# Since Python doesn't have multiline lambdas
# we define our reducer function here
last = len(accumulator) - 1
if (new[0] <= accumulator[last][1]):
start = accumulator[last][0]
@juniorbird
juniorbird / reduce.js
Last active March 25, 2022 22:23
A simple implementation of Reduce in Javascript
'use strict';
function reducer(array, callback, initializer) {
let accumulator = (initializer === undefined) ? 0 : initializer;
for (let i = 0; i < array.length; i++) {
accumulator = callback(accumulator, array[i]);
}
return accumulator;
@juniorbird
juniorbird / git-rebase-todo
Created June 2, 2016 03:02
Sample git rebase todo
pick 019325e 0.1.0
pick a4b689d Fetch all dependencies
squash 714a49d Matches keywords to Docker repos
pick d2d1ca3 parseDependencies returns an object of dependencies.
squash e3b6cd9 Clean up packageParser
squash 57acd67 Initial commit
squash 3f3e05e Rough out how we'll make Dockerfiles
squash 9e10b94 Can check for, make Docker files
squash a27b0ee Write docker files
pick a0980b8 Build Dockerfiles
@juniorbird
juniorbird / minty.js
Created March 18, 2016 22:27
Minty Example
const minty = require('./index.js');
const path = require('path');
function hello(a,b,c) {
console.log(a);
var d = b + c;
console.log(d);
}
minty.file(path.join(__dirname, '/lib/test.js'));
@juniorbird
juniorbird / sayings.md
Last active June 24, 2018 19:36
Sayings

Sayings worth remembering

On life

  • "He who quotes others is an idiot" - Thomas Jefferson
  • "Wine we need for health, and the health we need to drink vodka." - Viktor Chernomyrdin
  • "To answer before listening -- that is folly and shame." - Proverbs 18:13
  • "Some name it disappointment and become poorer, others name it experience and become richer" - Siegmund Warburg
  • "If we want to fully experience love and belonging, we must believe that we are worthy of love and belonging." - Brene Brown
  • In some ways suffering ceases to be suffering at the moment it finds a meaning, such as the meaning of a sacrifice." - Viktor Frankl
@juniorbird
juniorbird / jsperfs.md
Last active March 9, 2016 18:05
All my JSPerfs

My JSPerfs

Sometimes, I want to know what's fast. Usually I google it. But, in the below cases, I decided I needed to try it myself.

  • Fastest Factorial - what's the cost of doing it recursively? Turns out While is 10x faster.
  • Fastest way to find type - instanceof seems good. JQuery uses constructor. Prototype.toString is probably the most safe and compatible.
  • Speed of Sorts, when written as recursive or using a while loop.
@juniorbird
juniorbird / main.js
Last active January 16, 2016 07:16
JSON parser (objects are broken)
/* --------------------------------------------------------------------------- */
// Utility Functions
function dequote(str) {
// We need to remove excess quotes
// This seems hacky but I've run through a bunch of test cases and it appears to be what's needed
var newstring;
// Replace any escaped quotes
newstring = str.replace(/\\"/g, '"');
// The whole string will be wrapped in quotes. Unwrap.
@juniorbird
juniorbird / phoneregex.txt
Last active December 8, 2015 16:18
Regex to match all common US phone number formats
(?:1[\-\s])?(?:\(?(\d{3})[\-\)\s]?(?:[\s\.])?)?\d{3}[-\s\.]\d{4}