This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = {}; | |
_.throttle = function (func, wait, options) { | |
var initial; | |
return function () { | |
if (!initial || new Date() - initial >= wait) { | |
initial = new Date(); | |
func.apply(this, arguments); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |