Skip to content

Instantly share code, notes, and snippets.

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)
@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"
@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 / 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;
},
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");
if (process.argv.length !== 3) {
console.log("Usage:", process.argv[1], "num")
return;
}
var garland = function (word) {
var degree = 0;
for (var i = 1; i < word.length; ++i) {
var front = word.slice(0, i);
for (var j = 1; j <= i; ++j) {
@larryprice
larryprice / prime.js
Created August 5, 2015 02:04
determine whether a number is prime
if (process.argv.length !== 3) {
console.log("Usage:", process.argv[1], "num")
return;
}
var primeNum = parseInt(process.argv[2]);
if (isNaN(primeNum)) {
console.log("is not even a number, let alone prime");
return;
}
@larryprice
larryprice / debounce.js
Last active November 17, 2015 19:32
How does _'s debounce work?
var _ = {};
_.debounce = function (func, wait, immediate) {
var timeout, start, that, args;
var later = function () {
if (Date.now() - start >= wait && !immediate) {
func.apply(that, args);
timeout = null;
}
<div id="content" style="margin-bottom: 1.5em;">Welcome</div>
<button id="continue" onclick="nextPage()">
Continue
</button>
<script type="text/javascript" async>
function nextPage() {
var content = document.getElementById("content"),
nextPage = 1;
if (content.innerHTML === "Welcome") {
updatePageContent(nextPage);
@larryprice
larryprice / Dockerfile
Created June 26, 2015 14:01
Golang dockering with gpm vendoring
FROM golang:1.4
# install gpm
RUN git clone https://github.com/pote/gpm.git /tmp/gpm
WORKDIR /tmp/gpm
RUN ./configure && make install
# sets the working directory to the application source for convenience
ADD . /go/src/github.com/larryprice/myapp
WORKDIR /go/src/github.com/larryprice/myapp