Skip to content

Instantly share code, notes, and snippets.

Go's arrays are values. An array variable denotes the entire array; it is not a pointer to the first array element (as would be the case in C). This means that when you assign or pass around an array value you will make a copy of its contents. (To avoid the copy you could pass a pointer to the array, but then that's a pointer to an array, not an array.) One way to think about arrays is as a sort of struct but with indexed rather than named fields: a fixed-size composite value.

func swap(a, b *int) {
*a, *b = *b, *a
}
func insertionSort(arr []int) {
for idx := range arr {
for j := idx; j > 0 && arr[j-1] > arr[j]; j-- {
arr[j], arr[j-1] = arr[j-1], arr[j]
}
}
}
var http = require('http');
var fs = require('fs')
var util = require('util');
http.createServer(function(req, res) {
var path = './test.mp4';
var stat = fs.statSync(path);
var total = stat.size;
if (req.headers.range) {
var range = req.headers.range;
@linfongi
linfongi / gist:7097535317eab333038e
Created January 30, 2016 00:56 — forked from mcastilho/gist:e051898d129b44e2f502
Cheap MapReduce in Go
package main
import (
"bufio"
"encoding/csv"
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
SELECT
t.relname AS table_name,
i.relname AS index_name,
a.attname AS column_name
FROM
pg_class t,
pg_class i,
pg_index ix,
pg_attribute a
WHERE
  • unicode and rune
  • resizing factor of slice