Skip to content

Instantly share code, notes, and snippets.

{
"adformat": null,
"afmt": "251",
"at": "2_3",
"c": "WEB",
"cbr": "Chrome",
"cbrver": "48.0.2564.103",
"cgr": true,
"cl": "114833142",
"cmt": "3639.449",
@vayam
vayam / CGO.md
Created October 10, 2015 01:11 — 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

source The source IP address is hashed and divided by the total
weight of the running servers to designate which server will
receive the request. This ensures that the same client IP
address will always reach the same server as long as no
server goes down or up. If the hash result changes due to the
number of running servers changing, many clients will be
directed to a different server. This algorithm is generally
used in TCP mode where no cookie may be inserted. It may also
be used on the Internet to provide a best-effort stickiness
to clients which refuse session cookies. This algorithm is
/*
* Qualys test program to check for presence of GHOST vulnerability
* For more info: http://www.openwall.com/lists/oss-security/2015/01/27/9
*/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
{"app":"iMovie(2669)","state":"upload_complete","note":"invalid ticket","ticket":"92a60c5733a8c0ff32edd3d5a17cc94f","found":true,"enabled":1,"ts":1400732418,"ip":"70.76.92.117","hn":"10.90.128.53"}
{"app":"iMovie(2669)","state":"upload_complete","note":"invalid ticket","ticket":"62cdd3bbe0d4cea76381897821a1de74","found":true,"enabled":1,"ts":1400745251,"ip":"68.65.32.68","hn":"10.90.128.51"}
{"app":"Final Cut Pro(9735)","state":"upload_complete","note":"invalid ticket","ticket":"3fccb716ae1bc1c997319d8a0aefdcae","found":true,"enabled":1,"ts":1400763479,"ip":"99.39.114.252","hn":"10.90.128.52"}
@vayam
vayam / extract_token_query_param
Created December 23, 2013 21:09
extract token query param
vcl_recv {
#Extrac query param token
set resp.http.token = regsub(req.url, "^.*(\?|&)token=([^&]*)(&{0,1}.*|$)", "\2");
}
@vayam
vayam / fnvtest.md
Last active December 18, 2015 07:29
fnv hash test

http://play.golang.org/p/Olj-v2jBeu

php implementation that works on both 32bit and 64bit

$hash_key = "pwnd";
$to_hash = "Naren";
$buf = str_split($hash_key.$to_hash);
$hash = 2166136261; #offset32
foreach ($buf as $chr)
@vayam
vayam / gist:5614199
Last active December 17, 2015 12:59
TUS GET/HEAD Flow with Entity-Receive Header

Upload Client

HEAD /files/24e533e02ec3bc40c387f1a0e460e216 HTTP/1.1
Host: tus.example.org
Entity-Receive: available

Response:

HTTP/1.1 200 Ok