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 / boltdb_put_perf.md
Last active March 3, 2016 22:34
BoltDB Put Performance Results

Batch size = 400

Keys are sorted.

See the results below.

@xlab
xlab / CGO.md
Created January 4, 2016 21:43 — forked from dwbuiten/CGO.md

Problems & Solutions for Interaction Between C and Go

At Vimeo, on the transcoding team, we work a lot with Go, and a lot with C, for various tasks such as media ingest. This means we use CGO quite extensively, and consequently, have run into bits that are perhaps not very well documented, if at all. Below is my effort to document some of the problems we've run into, and how we fixed or worked around them.

Many of these are obviously wrong in retrospect, but hindsight is 20/20, and these problems do exist in many codebases currently.

Some are definitely ugly, and I much welcome better solutions! Tweet me at @daemon404 if you have any, or have your own CGO story/tips, please! I'd love to learn of them.

Table of Contents

@xlab
xlab / pool.go
Created December 23, 2015 17:40
import "time"
type Session struct {
ID string
CreatedAt time.Time
}
type SessionPool struct {
size int
ttl time.Duration
var nodeParentPairs = [];
var sourceXML;
function prepareWebKitXMLViewer(noStyleMessage)
{
var html = createHTMLElement('html');
var head = createHTMLElement('head');
html.appendChild(head);
var style = createHTMLElement('style');
style.id = 'xml-viewer-style';
head.appendChild(style);
@xlab
xlab / bytes_split.go
Last active April 4, 2022 17:21
Golang split byte slice in chunks sized by limit
func split(buf []byte, lim int) [][]byte {
var chunk []byte
chunks := make([][]byte, 0, len(buf)/lim+1)
for len(buf) >= lim {
chunk, buf = buf[:lim], buf[lim:]
chunks = append(chunks, chunk)
}
if len(buf) > 0 {
chunks = append(chunks, buf[:len(buf)])
}
Говорил Керниган Пайку: Ты погодь язык свой писать, покамест три книжки со мной в соавторстве не напишешь!
Написал Роб Пайк один язык с каналами, отнес его Кернигану, а тот лишь в бороду ухмыляется
Рассстроился молодой Роб, но виду не подал.
Пошел писать терминал графический и вышел он у него краше некуда. Да только к тому времени люди про терминалы уже и думать забыли (edited)
Тогда решил уже повзрослевший Пайк второй язык написать, да не просто написать а в наикрутейшем редакторе
А так как такого не было, написал свой
А потом написал в нем второй свой язык.
И пошел гордый собой свой язык, написанный в новом супер редакторе Кернигану показывать
А тот как увидел – стал языком цокать, да только не на язык глядючи, а на редактор.
Хорош у тебя редактор вышел, говорит. Молодец!
@xlab
xlab / GoWithC.go
Last active September 2, 2015 20:31 — forked from 17twenty/GoWithC.go
Cross Compiling and Language Interop oh my!
package main
import (
"./binding"
"fmt"
)
func main() {
binding.PrintHello()
binding.Seed(1)
fmt.Println(binding.Random())
@xlab
xlab / cgo_multi_arrays.c
Last active August 25, 2015 22:52
How CGO sees muti arrays when used as vars and as function params.
char a1; // type of a1 is C.char
char *a2; // type of a2 is *C.char
char a3[1]; // type of a3 is [1]C.char
char a4[1][2]; // type of a4 is [1][2]C.char
char a5[1][2][3]; // type of a5 is [1][2][3]C.char
char *a6[1][2][3]; // type of a6 is [1][2][3]*C.char
char **a7[1][2][3]; // type of a7 is [1][2][3]**C.char
char ***a8[1][2]; // type of a8 is [1][2]***C.char
char *a9[1][2]; // type of a9 is [1][2]*C.char
char **a10[1]; // type of a0 is [1]**C.char
@xlab
xlab / gist:e21f535ac45a42cb937c
Last active August 29, 2015 14:27 — forked from davecheney/gist:6740651
gccgo on armv7
localhost(~/src) % gccgo -v
Using built-in specs.
COLLECT_GCC=gccgo
COLLECT_LTO_WRAPPER=/opt/libexec/gcc/arm-linux-gnueabihf/4.8.2/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../gccgo/configure --prefix=/opt --enable-languages=c,c++,go --with-ld=/usr/bin/ld --enable-shared --without-included-gettext --enable-threads=posix --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libitm --with-system-zlib --with-cloog --enable-cloog-backend=ppl --disable-cloog-version-check --disable-ppl-version-check --enable-multiarch --enable-multilib --disable-sjlj-exceptions --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb --disable-werror --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 4.8.2 20130927 (prerelease) (GCC)
localhost(~/src) % go run -compiler gccgo helloworld.go
Hello gccgo
@xlab
xlab / test.h
Last active August 29, 2015 14:26
#pragma once
enum Options {
One, Two, Three
};
const char *hello = "hello world!";