Skip to content

Instantly share code, notes, and snippets.

View artyom's full-sized avatar

Artyom Pervukhin artyom

View GitHub Profile
@artyom
artyom / go.mod
Created May 9, 2024 12:48
SQLite application defined function in Go, combined with generated column
module sqlite-generated-columns
go 1.22.3
require modernc.org/sqlite v1.29.9
require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
@artyom
artyom / chat.go
Created March 12, 2016 22:06
Example of interactive terminal in Go
package main
import (
"fmt"
"io"
"log"
"os"
"golang.org/x/crypto/ssh/terminal"
)
@artyom
artyom / result.txt
Created February 6, 2024 11:14
rate.Sometimes vs time.Ticker
goos: darwin
goarch: arm64
pkg: ids-rewrite-experiment
BenchmarkSometimes/ticker-8 387814022 2.915 ns/op
BenchmarkSometimes/sometimes-8 44387656 27.03 ns/op
@artyom
artyom / rpc-tls-client.go
Last active October 9, 2023 15:44
Go RPC over TLS.You have to create the following keys: certs/client.crt, certs/client.key, certs/server.crt, certs/server.key. client.crt and server.crt should be signed with ca.crt, which should be concatenated to both client.crt and server.crt. It's easier to do with easy-rsa: http://openvpn.net/index.php/open-source/documentation/howto.html#pki
package main
import (
"crypto/tls"
"crypto/x509"
"log"
"net/rpc"
)
func main() {
Description: Tailscale SSH sessions recorder
Parameters:
VPC:
Type: AWS::EC2::VPC::Id
Description: VPC ID
Subnets:
Type: List<AWS::EC2::Subnet::Id>
Description: VPC subnets
@artyom
artyom / result.txt
Created July 10, 2014 14:39
Golang XOR performance for 8/64 bytes long integers
$ go test -bench .
PASS
Benchmark8 1000000 1093 ns/op 936.69 MB/s
Benchmark64 20000000 134 ns/op 7603.74 MB/s
ok _/private/tmp/x 3.944s
@artyom
artyom / ssh-mux.go
Created February 25, 2017 17:26
Example ssh server with both interactive terminal & sftp support
package main
import (
"bufio"
"bytes"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
@artyom
artyom / gist:3368367
Created August 16, 2012 08:24
Persistent SSH_AUTH_SOCK for using with screen/tmux
# put this to your $HOME/.bashrc
# so you can safely use screen or tmux while preserving ssh-agent forwarding features
# of your ssh sessions
test "${SSH_AUTH_SOCK:-}" && test $SSH_AUTH_SOCK != $HOME/.ssh_auth_sock && {
test -L $HOME/.ssh_auth_sock && \
test "$(readlink $HOME/.ssh_auth_sock)" = $SSH_AUTH_SOCK || \
ln -sf $SSH_AUTH_SOCK $HOME/.ssh_auth_sock
export SSH_AUTH_SOCK=$HOME/.ssh_auth_sock
}
@artyom
artyom / newerthan.sh
Created September 12, 2012 14:19
Check if file is newer than X minutes
#!/bin/sh -eu
usage () { printf "%s file [time-in-minutes]\n" ${0##*/} >&2 ; }
test $# -eq 0 && { usage ; exit 2 ; }
WHAT=$1
test -e $WHAT || { echo "$WHAT not found" >&2 ; exit 2 ; }
MINUTES=${2:-30}
case ${0##*/} in
older*)
test $(($(date +%s)-$(stat --printf "%Y\n" "$WHAT"))) -gt $(($MINUTES*60))
@artyom
artyom / gist:5090351
Created March 5, 2013 13:35
Locking shell script stub
#!/bin/sh
set -eu
LOCKFILE=/var/lock/${0##*/}.lock
fail () { echo "FAILED: $@" >&2 ; exit 1 ; }
exec 9>$LOCKFILE
flock -xn 9 || fail "Cannot acquire lock: $LOCKFILE"
trap 'rm -f $LOCKFILE' 0