Skip to content

Instantly share code, notes, and snippets.

View xlab's full-sized avatar
:octocat:
Hacking

Max Kupriianov xlab

:octocat:
Hacking
View GitHub Profile
@xlab
xlab / gist:f424553333847db9f4cf
Last active August 29, 2015 14:04
Convert c-array int32[] to go-slice []int32
func arrayToSliceInt32(ptr unsafe.Pointer, size int) (ints []int32) {
hdr := reflect.SliceHeader{
Data: uintptr(ptr),
Len: size,
Cap: size,
}
cints := *(*[]int32)(unsafe.Pointer(&hdr))
ints = make([]int32, size)
// TODO: bech this
copy(ints, cints)
@xlab
xlab / floatpoint_golang_mk802.txt
Last active August 29, 2015 14:04
mk802 notes
$ go test -bench=BenchmarkUint -run=XXX
PASS
BenchmarkUint32Div7 20000000 126 ns/op
BenchmarkUint32Div37 20000000 126 ns/op
BenchmarkUint32Div123 20000000 126 ns/op
BenchmarkUint32Div763 20000000 126 ns/op
BenchmarkUint32Div1247 20000000 126 ns/op
BenchmarkUint32Div9305 20000000 126 ns/op
BenchmarkUint32Div13307 20000000 126 ns/op
BenchmarkUint32Div52513 20000000 126 ns/op
@xlab
xlab / mapred_builtins.js
Created September 5, 2014 22:19
Riak MapReduce built-in functions
/** Helper functions start **/
var RiakHelper = function() {
return {
numericSorter: function(first, second) {
return first - second;
}
};
}();
<snippet>
<content><![CDATA[
type ${1:type}s []*${1:type}
func (s ${1:type}s) Len() int { return len(s) }
func (s ${1:type}s) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s ${1:type}s) Less(i, j int) bool { return s[i].${2:field} < s[j].${2:field} }
]]></content>
<tabTrigger>gosort</tabTrigger>
<scope>source.go</scope>
@xlab
xlab / keybase.md
Created October 1, 2014 14:27
Keybase proof

Keybase proof

I hereby claim:

  • I am xlab on github.
  • I am xlab (https://keybase.io/xlab) on keybase.
  • I have a public key whose fingerprint is 8F39 7B4E 96AB 1977 5C15 C3C6 DE3F 4FEA 5B0A DCE5

To claim this, I am signing this object:

@xlab
xlab / Dockerfile
Last active August 29, 2015 14:08 — forked from lox/Dockerfile
FROM progrium/busybox
ADD https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt /etc/ssl/ca-bundle.pem
@xlab
xlab / gist:1e40af2eac8783ce50d1
Last active August 29, 2015 14:19
skarademir/naturalsort VS xlab/handysort
Testcase from https://github.com/skarademir/naturalsort/blob/master/naturalsort_test.go
BenchmarkNaturalSort 50000 28738 ns/op
BenchmarkHandySort 3000000 517 ns/op
A real battle-case from https://github.com/xlab/handysort/blob/master/strings_test.go
(10000 random alphanumeric strings)
BenchmarkStringSort 500 2665145 ns/op
BenchmarkHandyStringSort 100 11817051 ns/op
BenchmarkNaturalStringSort 1 1013808894 ns/op
@xlab
xlab / each100ms.go
Last active August 29, 2015 14:23
goprofile graphs
memstats := cmd.Flag.Lookup("memstats").Value.String()
if memstats != "" {
interval := cmd.Flag.Lookup("meminterval").Value.Get().(time.Duration)
context.fileMemStats, err = os.Create(memstats)
if err != nil {
return err
}
context.fileMemStats.WriteString("# Time\tHeapSys\tHeapAlloc\tHeapIdle\tHeapReleased\n")
@xlab
xlab / friendlistsave.c
Created June 26, 2015 08:26
friendlistsave.c
static uint32_t friends_list_save(const Messenger *m, uint8_t *data)
{
uint32_t i;
uint32_t num = 0;
for (i = 0; i < m->numfriends; i++) {
if (m->friendlist[i].status > 0) {
struct SAVED_FRIEND temp;
memset(&temp, 0, sizeof(struct SAVED_FRIEND));
temp.status = m->friendlist[i].status;
@xlab
xlab / conversions.go
Created July 11, 2015 16:29
CGO helpers
// Glow automatically generated OpenGL binding: http://github.com/go-gl/glow
package gl
import (
"C"
"fmt"
"log"
"reflect"
"strings"