Skip to content

Instantly share code, notes, and snippets.

View kostix's full-sized avatar

Konstantin Khomoutov kostix

  • TradingView
  • Saint-Petersburg, Russia
View GitHub Profile
@kostix
kostix / tempfile\tempfile.go
Last active February 11, 2016 14:21
`tempfile` Go package mimicking mkstemp(3) and mkstemps(3) libc calls
package tmpfile
import (
"bytes"
"errors"
"os"
"sync/atomic"
"time"
)
@kostix
kostix / netapi32.go
Created March 9, 2016 23:36
Wrapping Win32 API NetSessionEnum() in Go
package main
import (
"log"
"syscall"
"unicode/utf16"
"unsafe"
"time"
)
@kostix
kostix / ifspace.go
Created April 4, 2016 15:18
Getting Ethernet interface speed on Linux using Go via cgo
package main
/*
#include <stdio.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <linux/sockios.h>
#include <linux/if.h>
@kostix
kostix / hello.go
Last active August 19, 2018 18:20
A real test for cgo code https://github.com/dyu/ffi-overhead
package main
/*
#cgo CFLAGS: -Wall -O2 -fPIC
#cgo linux CFLAGS: -DLINUX=1
#cgo LDFLAGS: -Lnewplus -lnewplus -Wl,-rpath='$ORIGIN'/newplus
#include <stdlib.h>
#include "newplus/plus.h"
*/
import "C"
@kostix
kostix / drvs.go
Created July 6, 2020 18:08
Get fixed DOS drives in Windows
package main
import (
"errors"
"fmt"
"log"
"syscall"
"unsafe"
)
@kostix
kostix / mpc.sh
Created September 21, 2021 18:27
mpc wrapper with a bit of interactivity
#!/bin/sh
set -e -u
mpc=/usr/bin/mpc
if [ $# -lt 1 ]; then
"$mpc" "$@"
exit $?
fi
@kostix
kostix / resp.go
Last active October 5, 2021 14:56
Freeing a C resource produced by Go code
package main
/*
#include <stdlib.h>
typedef struct {
char *response;
} Resp;
*/
import "C"
twosums$ go test -bench=. -run=none -benchmem .
goos: linux
goarch: amd64
BenchmarkTwoSum1-8 14698284 149 ns/op 16 B/op 1 allocs/op
BenchmarkTwoSum2-8 7724497 138 ns/op 16 B/op 1 allocs/op
PASS
ok _/home/kostix/tmp/twosums 3.508s
@kostix
kostix / README.md
Created December 10, 2021 18:23
Low-level parsing of an AppStore Receipts DER-encoded block (malformed)
package main
/*
#include <stdio.h>
struct real_client {
int x;
};
typedef struct Client{