Skip to content

Instantly share code, notes, and snippets.

@mholt
mholt / transcript
Created February 26, 2016 18:42
Is it necessary to consume response body before closing it (net/http client code)?
mholt [9:10 AM]
When using http.Get(), is it really necessary to read the full response body just to close it later?
[9:10]
The docs keep saying `Caller should close resp.Body when done reading from it.` and I keep seeing code like this:
```
io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
```
@armon
armon / reap.sh
Created February 21, 2015 01:10
Reap Graphite nodes using Consul members
#!/bin/bash
# Store the live members
consul members | grep alive | awk '{ print $1 }' > /tmp/alive.txt
# Clean-up the collectd metrics
cd /data/graphite/whisper/collectd
ls | awk '{print substr($1, 0, index($1, "_node_")) }' > /tmp/monitored.txt
for NODE in `cat /tmp/monitored.txt`; do if grep -q $NODE /tmp/alive.txt; then echo $NODE alive; else echo $NODE dead; sudo rm -Rf ${NODE}_node_*; fi; done
@debasishg
debasishg / gist:8172796
Last active March 15, 2024 15:05
A collection of links for streaming algorithms and data structures

General Background and Overview

  1. Probabilistic Data Structures for Web Analytics and Data Mining : A great overview of the space of probabilistic data structures and how they are used in approximation algorithm implementation.
  2. Models and Issues in Data Stream Systems
  3. Philippe Flajolet’s contribution to streaming algorithms : A presentation by Jérémie Lumbroso that visits some of the hostorical perspectives and how it all began with Flajolet
  4. Approximate Frequency Counts over Data Streams by Gurmeet Singh Manku & Rajeev Motwani : One of the early papers on the subject.
  5. [Methods for Finding Frequent Items in Data Streams](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.187.9800&rep=rep1&t
@kylelemons
kylelemons / timestubs.go
Created December 18, 2013 19:25
Example of how to stub out time.Now
package foo
import "time"
// in your main package
var timeNow = time.Now
// in the _test.go:
func init() {
// Panic if any tests cause timeNow to be called without stubbing it out
@kierdavis
kierdavis / nq2nt.sh
Created July 30, 2012 00:04
Sed command to remove context URIs from n-quads to make it n-triples
sed 's|<[^>]*> \.$|.|' input.nq > output.nt
@jboner
jboner / latency.txt
Last active May 5, 2024 03:12
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@kylelemons
kylelemons / piping.go
Last active July 4, 2022 01:25 — forked from dagoof/piping.go
piping exec.Cmd in golang (example sorts all regular files under a directory by their extension)
package main
import (
"bytes"
"exec"
"log"
"os"
)
// Pipeline strings together the given exec.Cmd commands in a similar fashion
@kwijibo
kwijibo / VoID_to_LDA_script.php
Created August 24, 2011 11:21
converts VoID to Linked Data API Config
<?php
define('DCT_DESCRIPTION', 'http://purl.org/dc/terms/description');
define('MORIARTY_ARC_DIR', 'arc/');
define('MORIARTY_ALWAYS_CACHE_EVERYTHING', 'cache');
define('MORIARTY_HTTP_CACHE_DIR', 'cache');
define('VOID_NS', 'http://rdfs.org/ns/void#');
define('VOID_SPARQL', VOID_NS.'sparqlEndpoint');
define('VOID_EXAMPLE', VOID_NS.'exampleResource');
define('API','http://purl.org/linked-data/api/vocab#' );
@kierdavis
kierdavis / gist:1034725
Created June 19, 2011 20:42
Simple Brainf*ck Single-Digit Adder
++++++++++[>++++++>+++<<-]>++...>++.[-]<[-]<,>++++++[<-------->-]++++++++++[>+>++++++>+++<<<-]>.>++...>++.[-]<[-]<[-]<,>++++++[<-------->-]<[<+>-]++++++++++[>+>++++++++>+++++++++++>++++++++++>+++>++++++<<<<<<-]>.>++++.>+.+++++.>---.<--------.>>++.<++++++++.++++++++++.>>--.<.>[-]<[-]<[-]<[-]<[-]<[-]<++++++[<++++++++>-]<.

Idiot-Proof Git Aliases