Skip to content

Instantly share code, notes, and snippets.

@tmc
tmc / gist:f1364bcee04d1192278dd2f297cf116f
Last active June 19, 2021 21:47
Pure Go VRF implementation benchmarking
goos: linux
goarch: amd64
pkg: github.com/algorand/go-algorand/crypto
cpu: Intel(R) Xeon(R) CPU @ 2.30GHz
BenchmarkVrfVerifyGo-2 signal: interrupt
FAIL github.com/algorand/go-algorand/crypto 1.863s
goos: linux
goarch: amd64
pkg: github.com/algorand/go-algorand/crypto
cpu: Intel(R) Xeon(R) CPU @ 2.30GHz

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

@rcarmo
rcarmo / benchmark.py
Last active December 16, 2015 06:49
Go benchmark
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Main application script
Created by: Rui Carmo
License: MIT (see LICENSE for details)
"""
import os, sys
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@nathanborror
nathanborror / gist:2884560
Created June 6, 2012 20:29
Mediator Pattern
define([], function(obj) {
var channels = {};
if (!obj) obj = {};
obj.subscribe = function(channel, subscription) {
if (!channels[channel]) channels[channel] = [];
channels[channel].push(subscription);
return channels[channel].length -1;
};
@mcroydon
mcroydon / sillyproto.go
Created January 12, 2012 00:01
Performance-oriented silly text-based protocol server in go.
package main
import (
"bufio"
"flag"
"fmt"
"io"
"log"
"net"
"net/textproto"
@carljm
carljm / postactivate
Created July 12, 2011 18:21
Yo dawg, I heard you like Ruby...
#!/bin/bash
# This hook is run after every virtualenv is activated.
export OLD_GEM_HOME=$GEM_HOME
export GEM_HOME=$VIRTUAL_ENV/gems/
export GEM_PATH=
export PATH=$VIRTUAL_ENV/gems/bin:$PATH
@codysoyland
codysoyland / temporary_settings.py
Created June 21, 2011 21:47
Context manager for monkey-patching django settings (useful in unit tests)
# Example usage:
# with temporary_settings(CELERY_ALWAYS_EAGER=True):
# run_task.delay() # runs task with eager setting enabled.
from contextlib import contextmanager
from django.conf import settings
@contextmanager
def temporary_settings(**temp_settings):
orig_settings = {}
@DavidYKay
DavidYKay / gist:912765
Created April 10, 2011 21:52
"Can Code Be Like Literature" - Jeremy Ashkenas
Jeremy
Absolutely brilliant
both technically
and oratorically
He wrote CoffeeScript
1st place 5k
21 min, 3 seconds
<7min mile
Big picture
@erikfrey
erikfrey / gist:865355
Created March 11, 2011 02:20
Threadpool crashes gevent
from threadpool import ThreadPool
import random
import gevent
import gevent.pool
iterations = 1000000
max_stack_depth = 50
def source(tp):
for i in xrange(0, iterations):