Skip to content

Instantly share code, notes, and snippets.

@respectTheCode
respectTheCode / static_server.js
Created February 27, 2012 20:36 — forked from ryanflorence/static_server.js
Node.JS static file web server. Put it in your path to fire up servers in any directory, takes an optional port argument.
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs"),
mime = require("mime")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
@pjz
pjz / testdoc
Created March 14, 2012 01:21
golang docstring access
#!/usr/bin/gorun
package main
import "os"
import "fmt"
import "strings"
import "go/doc"
import "go/token"
import "go/parser"
@krasin
krasin / hello_xml.go
Created March 29, 2012 06:45
An example of parsing XML in Go
package main
import (
"encoding/xml"
"fmt"
"log"
)
const data = `<Note>
<To>Tove</To>
@moraes
moraes / AnideaforblocksemanticsinGostexttemplate.rst
Created July 9, 2012 14:08
An idea for {{block}} semantics in Go's text/template

{{block}} in text/template

We can achieve what is known as "template inheritance" in other template engines using the {{block}} tag. A {{block}} is a replaceable fragment inside a template. Here's an example:

{{define "Base"}}

<p>A header</p>

{{block body}}

@WayneHaworth
WayneHaworth / grok_vi.mdown
Created August 14, 2012 14:43 — forked from nifl/grok_vi.mdown
Grok Vim - an excellent summary of a few Vim features, which also exposes elegant uses of the commands

###Answer by Jim Dennis on Stack Overflow

#Your problem with Vim is that you don't grok vi.

You mention cutting with yy and complain that you almost never want to cut whole lines. In fact programmers, editing source code, very often want to work on whole lines, ranges of lines and blocks of code. However, yy is only one of many way to yank text into the anonymous copy buffer (or "register" as it's called in vi).

The "Zen" of vi is that you're speaking a language. The initial y is a verb. The statement yy is a simple statement which is, essentially, an abbreviation for 0 y$:

0 go to the beginning of this line. y yank from here (up to where?)

@akisaarinen
akisaarinen / ImperativePong.scala
Created September 22, 2012 14:27
Imperative Pong
package pong.imperative
sealed trait Event
class PongConnection {
def isConnected(): Boolean = sys.error("not implemented")
def readEvent(): Event = sys.error("not implemented")
def moveUp(): Unit = sys.error("not implemented")
def moveDown(): Unit = sys.error("not implemented")
def shootMissile(): Unit = sys.error("not implemented")
@akisaarinen
akisaarinen / FunctionalPong.scala
Created September 22, 2012 14:29
Functional Pong
package pong.functional
sealed trait Event
sealed trait Action
object Action {
case object MoveUp extends Action
case object MoveDown extends Action
case object ShootMissile extends Action
}
@getify
getify / 1.js
Created November 13, 2012 00:19
illustrating some potential issues with adding `let` to code which already has `var` used in it...
// var: poor stylistic form, but no leakage
function foo() {
bar = 3;
if (true) {
var bar = 5;
}
}
// let: will leak an auto-global
function foo() {
@getify
getify / 1.js
Created November 13, 2012 14:04
more "mental tax": interpreting code that uses `let` in many nested blocks
/*
not terribly difficult to predict which statements print what.
*/
function foo() {
var a, b, c, d;
if (true) {
if (true) {
a = 1;
package bcomposes.twitter
import twitter4j._
object StatusStreamer {
def main(args: Array[String]) {
val twitterStream = new TwitterStreamFactory(Util.config).getInstance
twitterStream.addListener(Util.simpleStatusListener)
twitterStream.sample
Thread.sleep(2000)