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
@fabiolimace
fabiolimace / UUIDv6.sql
Last active June 4, 2024 14:52
Functions for generating UUIDv6 and UUIDv7 on PostgreSQL
/*
* MIT License
*
* Copyright (c) 2023-2024 Fabio Lima
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@nakov
nakov / CryptoUtils.js
Last active November 16, 2018 22:26
JS Crypto Utils - secp256k1 EC cryptography and blockchain functions
const CryptoJS = require("crypto-js");
const EC = require('elliptic').ec;
const secp256k1 = new EC('secp256k1');
function publicKeyToAddress(pubKey) {
let address = CryptoJS.RIPEMD160(pubKey).toString();
return address;
}
function privateKeyToPublicKey(privKey) {
@mattatz
mattatz / Easing.hlsl
Created January 19, 2018 04:37
Easing functions for HLSL.
#ifndef _EASING_INCLUDED_
#define _EASING_INCLUDED_
float ease_linear(float x) {
return x;
}
float ease_in_quad(float x) {
float t = x; float b = 0; float c = 1; float d = 1;
return c*(t/=d)*t + b;
@vurtun
vurtun / defl.c
Last active June 13, 2023 21:30
Full deflate/inflate implementation in ~300 LoC
/* ===============================================================
* SDEFL
* ===============================================================
* public domain - no warranty implied; use at your own risk
* References:
https://bitbucket.org/rmitton/tigr/src/be3832bee7fb2f274fe5823e38f8ec7fa94e0ce9/src/tigr_inflate.c?at=default&fileviewer=file-view-default
https://github.com/github/putty/blob/49fb598b0e78d09d6a2a42679ee0649df482090e/sshzlib.c
https://www.ietf.org/rfc/rfc1951.txt
*/
#include <stdlib.h>

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

@17twenty
17twenty / GoWithC.go
Last active July 11, 2016 04:29
Cross Compiling and Language Interop oh my!
package main
import (
"./binding"
"fmt"
)
func main() {
binding.PrintHello()
binding.Seed(1)
fmt.Println(binding.Random())
@doochik
doochik / gist:575b94b20765b028dc70
Created November 26, 2014 16:25
IE10/11 can't execute blob-js with 114688 bytes size
var text = "var a = '";
for (var i = text.length; i < 114686; i++) {
text += '1';
}
text += "';";
console.log('text size:', text.length);
var blob = new Blob([text], {type: 'text/javascript'});
var url = URL.createObjectURL(blob);
var script = document.createElement('script');
@nurupo
nurupo / bootstrap_node_info.py
Last active August 29, 2015 14:02
Gets version and MOTD info from a Tox DHT bootstrap node, if such are set.
#!/usr/bin/env python
"""
Copyright (c) 2014 by nurupo <nurupo.contributions@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@lox
lox / Dockerfile
Created June 23, 2014 07:46
Getting a golang binary with x.509 to run under busybox
FROM progrium/busybox
ADD https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt /etc/ssl/ca-bundle.pem
@cryptix
cryptix / client.go
Created June 22, 2014 11:09
multipart upload with io.Pipe
package main
import (
"io"
"log"
"mime/multipart"
"net/http"
"os"
"path/filepath"
"runtime"