Skip to content

Instantly share code, notes, and snippets.

@sspencer
sspencer / keybase.md
Created October 26, 2021 21:37
Keybase proof

Keybase proof

I hereby claim:

  • I am sspencer on github.
  • I am steve_spencer (https://keybase.io/steve_spencer) on keybase.
  • I have a public key ASAmiGpUUaDFLwkAnpEZySbGDBM_2b1ZqbF0Iq01hBl0AQo

To claim this, I am signing this object:

@sspencer
sspencer / log.go
Created September 10, 2016 23:47
Make function logging stand out
// Golang UK Conference 2016 - Mat Ryer - Idiomatic Go Tricks
func foo() error {
log.Println("----------")
defer log.Println("----------")
// ... do stuff ...
}
@sspencer
sspencer / timer.go
Created September 10, 2016 23:46
Time a function
// Golang UK Conference 2016 - Mat Ryer - Idiomatic Go Tricks
func StartTimer(name String) func() {
t := time.Now()
log.Println(name, "started")
return func() {
d := time.Now().Sub(t)
log.Println(name, "took", d)
}
}
package command
import (
"fmt"
"net"
"os"
)
const (
message = "This process is already running in SOLO mode."
// MarzulloAlgorithm in JavaScript
//
// Not quite what I need which is a list of ranges that contain a specified number.
//
'use strict';
function Point(name, point, type) {
this.name = name;
this.point = point;
this.type = type;
// From: http://tomasz.janczuk.org/2013/05/multi-line-strings-in-javascript-and.html
function multiline(fn) {
return fn.toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1].trim();
}
// NOTE: exported objects are Strings, not functions
exports.getTour = multiline(function() {/*
SELECT
*
FROM
var crappy_xml = "<tag>some forget to encode & others &lt;do not&gt;</tag>";
// negative lookahead
crappy_xml.replace(/&(?!(\S+;))/g, '&amp;')
@sspencer
sspencer / closure.sh
Created April 22, 2013 23:10
Shell function to send JS file thru closure. Usage: closurejs file.js
closurejs()
{
curl -s --data output_info=compiled_code --data-urlencode js_code@${1} http://closure-compiler.appspot.com/compile
}
@sspencer
sspencer / repl.js
Created April 10, 2013 19:52
Simple standalone NodeJS REPL.
// Simple embedded REPL
var repl = require("repl");
repl.start({
prompt: "karma> ",
input: process.stdin,
output: process.stdout,
eval: function(cmd, context, filename, callback) {
// cmd comes thru as "(ls\n)", get back to original "ls"
callback("You typed: " + cmd.substring(1, cmd.length-1).trim());
@sspencer
sspencer / SomeNetworkOperation.m
Created August 1, 2012 01:57
Override MKNetworkOperation so 4xx response body available in the error handler
// Register your NetworkOperation class after creating your network engine
// someEngine = [[SomeEngine alloc] initWithHostName:SOME_API customHeaderFields:nil];
// [someEngine registerOperationSubclass:[SomeNetworkOperation class]];
// ------ SomeNetworkOperation.h ------
#import "MKNetworkOperation.h"
@interface SomeNetworkOperation : MKNetworkOperation
@end