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 / impersonate.go
Created September 30, 2014 16:46
A demonstration example for http://stackoverflow.com/a/26124494
// A demonstration example for http://stackoverflow.com/a/26124494
// It runs a goroutine locked to an OS thread on Windows
// then impersonates that thread as another user using its name
// and plaintext password, then reverts to the default security
// context before detaching from its OS thread.
package main
import (
"log"
"runtime"
@kostix
kostix / find_first_file.c
Last active September 5, 2023 09:16
FindFirstFile/FindNextFile
#include <stdlib.h>
#include <stdio.h>
#include <locale.h>
#define WIN32_LEAN_AND_MEAN
#define _UNICODE
#include <windows.h>
int print_sys_error(DWORD last_error)
{
@kostix
kostix / get-fixed-volume-mounts.go
Created July 9, 2020 19:51
Getting the list of fixed volumes and their mounts
package main
import (
"errors"
"log"
"strings"
"syscall"
"unsafe"
)
@kostix
kostix / Makefile
Last active October 29, 2022 10:40
Writing C string to a C-allocated buffer from Go
CC = /usr/bin/i686-w64-mingw32-gcc
GOOS = windows
GOARCH = 386
CGO_ENABLED = 1
export CC GOOS GOARCH CGO_ENABLED
.PHONY: all build run clean
all: run
package main
/*
#include <stdio.h>
struct real_client {
int x;
};
typedef struct Client{
@kostix
kostix / README.md
Created December 10, 2021 18:23
Low-level parsing of an AppStore Receipts DER-encoded block (malformed)
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 / 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"
@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