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 / HOWTO
Last active August 29, 2015 14:26
$ go run main.go
@xlab
xlab / util.go
Last active August 29, 2015 14:26
CGO util from Go-SQLite
// Copyright 2013 The Go-SQLite Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package sqlite3
/*
#include "sqlite3.h"
*/
import "C"
@xlab
xlab / main.go
Created July 27, 2015 10:47
golang closer with manners webserver
package main
import (
"io"
"log"
"net/http"
"time"
"github.com/braintree/manners"
"github.com/xlab/closer"
@xlab
xlab / Makefile
Created July 24, 2015 22:30
A Makefile for Golang projects (via @cznic)
.PHONY: all clean cover cpu editor internalError later mem nuke todo
grep=--include=*.go --include=*.l --include=*.y
all: editor
go vet
golint
make todo
clean:
1. Founder has all permissions.
2. Everyone in the chatroom can verify that public key X is indeed founder's key, it's a property of the chatroom and no peer stores it i.e. the chatroom itself contains that information somewhere, presumably in its ID (we don't rely on chatroom peers storing that data because they can came up with whatever they want i.e. say that the key X is not founder's key; we want that verification to be 100% exact and to work with even 1 peer in the chatroom).
3. To give permissions to user A, founder gives user A data which tells what permission level does A have (if we are going to have permission levels in tox at all). The data is signed by founder's private key.
4. Now A can show anyone that signed by founder data from the step (3) as a proof of her having permissions (anyone can verify that it was indeed signed by founder by (2)), so A can exercise her rights over everyone in the chatroom.
5. If A gives permissions to B, 1) A sends her founder-signed data to B to show that she i
@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"
@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 / 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 / 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 / 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