Skip to content

Instantly share code, notes, and snippets.

if (process.argv.length !== 4) {
console.log("Usage:", process.argv[1], "b start")
return;
}
var b = parseInt(process.argv[2]),
start = parseInt(process.argv[3]);
if (isNaN(b) || isNaN(start)) {
console.log("need numbers");
@larryprice
larryprice / more-underscore.js
Last active August 29, 2015 14:27
Quick and dirty "blind" implementation of the functionality found at https://github.com/trevorparscal/more-underscore
var _ = {
objectify: function (arr) {
var o = {},
vals = arguments['0'];
for (var i = 1; i < arguments.length; ++i) {
if (i > vals.length) break;
o[arguments[i.toString()]] = vals[i - 1];
}
return o;
},
@larryprice
larryprice / throttle.js
Created August 13, 2015 12:34
mimicing _.throttle
var _ = {};
_.throttle = function (func, wait, options) {
var initial;
return function () {
if (!initial || new Date() - initial >= wait) {
initial = new Date();
func.apply(this, arguments);
}
@larryprice
larryprice / main.go
Last active February 21, 2018 00:43
Sample code used for blog post on parsing XML with Go
// Sample code used for blog post on parsing XML with Go
// https://larry-price.com
//
// Go Playground: https://play.golang.org/p/qiSoxxb5tp
package main
import (
"encoding/xml"
"fmt"
package main
import "golang.org/x/tour/tree"
import "fmt"
func walk(t *tree.Tree, ch chan int) {
if t == nil {
return
}
walk(t.Left, ch)
package main
import (
"fmt"
)
type Fetcher interface {
// Fetch returns the body of URL and
// a slice of URLs found on that page.
Fetch(url string) (body string, urls []string, err error)
@larryprice
larryprice / salesman.go
Last active January 28, 2016 15:05
Traveling salesman in go
package main
import (
"bufio"
"fmt"
"math"
"math/rand"
"os"
"strconv"
"strings"
@larryprice
larryprice / dining_philosophers.go
Last active March 4, 2016 20:30
Dining philosophers with mutexes in go
package main
import (
"fmt"
"sync"
"time"
)
type Philosopher struct {
Name string
@larryprice
larryprice / dining_philosophers.go
Last active March 4, 2016 20:23
Dining philosophers with channels
package main
import (
"fmt"
"time"
)
type Philosopher struct {
Name string
}
@larryprice
larryprice / stdin_thief.py
Last active August 17, 2016 19:10
Light script to demonstrate lxc.attach_wait hoarding stdin even after it's finished
#!/usr/bin/env python3
import lxc
import time
import os
CONTAINER_NAME='xenial'
CONTAINER_PATH='%s/.cache/libertine-container' % os.environ["HOME"]
def lxc_work():