Skip to content

Instantly share code, notes, and snippets.

View pvva's full-sized avatar
🚀
You are who you choose to be

Pavel Varyukhichev pvva

🚀
You are who you choose to be
View GitHub Profile
@pvva
pvva / latency.txt
Created December 6, 2018 21:14 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@pvva
pvva / go-os-arch.md
Created February 23, 2019 18:11 — forked from asukakenji/0-go-os-arch.md
Go (Golang) GOOS and GOARCH

Go (Golang) GOOS and GOARCH

All of the following information is based on go version go1.8.3 darwin/amd64.

A list of valid GOOS values

(Bold = supported by go out of the box, ie. without the help of a C compiler, etc.)

  • android
  • darwin
@pvva
pvva / rtree_test.go
Created July 4, 2019 08:32
benchmark on several different GoLang RTree implementations
package rtree
import (
"math"
"math/rand"
"testing"
"github.com/dhconnelly/rtreego"
rtreego2 "github.com/patrick-higgins/rtreego"
rtreego3 "github.com/tidwall/rtree"
@pvva
pvva / evenSplitter.go
Created July 26, 2019 15:22
split group of objects based on their values, so that total value (sum) of all objects in every group is close to each other
package main
import (
"fmt"
"sort"
)
type VInt int
func (vi VInt) Value() int {
@pvva
pvva / rnn1.py
Created November 3, 2019 17:39
rnn1
class CharRnn(nn.Module):
def __init__(self, vocab_size, n_fac, n_hidden):
super().__init__()
self.e = nn.Embedding(vocab_size, n_fac)
self.rnn = nn.RNN(n_fac, n_hidden)
self.l_out = nn.Linear(n_hidden, vocab_size)
self.n_hidden = n_hidden
def forward(self, inp):
b_size, v_size = inp.size()
@pvva
pvva / rnn1_2.py
Created November 3, 2019 17:41
rnn1_2
def detach_from_history(h):
if type(h) == torch.Tensor:
return h.detach()
return tuple(detach_from_history(v) for v in h)
class CharRnn(nn.Module):
def __init__(self, vocab_size, n_fac, n_hidden, batch_size):
super().__init__()
@pvva
pvva / rnn2.py
Created November 3, 2019 17:42
rnn2
class CharRnn(nn.Module):
def __init__(self, vocab_size, n_fac, n_hidden, batch_size, layers=2):
super().__init__()
self.e = nn.Embedding(vocab_size, n_fac)
self.rnn = nn.LSTM(n_fac, n_hidden, layers, dropout=0.1)
self.l_out = nn.Linear(n_hidden, vocab_size)
self.n_hidden = n_hidden
self.layers = layers
self.init_hidden_state(batch_size)
@pvva
pvva / p_value.rs
Last active May 30, 2022 21:15
2 sided p-value (rust)
// Standard normal cumulative distribution function.
fn normal_dist(z: f64) -> f64 {
let t = 1.0 / (1.0 + 0.2316419 * z.abs());
let d = 0.3989423 * (-z * z / 2.0).exp();
let p =
t * d * (0.3193815 + t * (-0.3565638 + t * (1.781478 + t * (-1.821256 + t * 1.330274))));
1.0 - p
}
@pvva
pvva / gen-certs.sh
Created September 27, 2022 12:45 — forked from notmedia/gen-certs.sh
Creating Self-Signed certificates
rm *.pem
rm *.srl
rm *.cnf
# 1. Generate CA's private key and self-signed certificate
openssl req -x509 -newkey rsa:4096 -days 365 -nodes -keyout ca-key.pem -out ca-cert.pem -subj "/C=FR/ST=Occitanie/L=Toulouse/O=Test Org/OU=Test/CN=*.test/emailAddress=test@gmail.com"
echo "CA's self-signed certificate"
openssl x509 -in ca-cert.pem -noout -text
@pvva
pvva / gist:549bc47fd16483dd65f5c21852187761
Created February 25, 2023 18:46
Example of the cross sector balance calculation with separate "trade" sector.
import numpy as np
np.set_printoptions(suppress=True)
ec_cnt = 2 # end consumer industries count (always last in the Q)
precision = 2
# cross industry consumption coefficients (0..1) with trade (=1) - given
A = np.array([
[0, 0.2, 0, 0, 0],