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 / gist:73319a000985e2125ab03daa8dc1173e
Last active April 8, 2023 11:48
Bitwise min/max (golang)
type Integer interface {
int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64
}
func minBitwise[T Integer](a, b T) T {
_a := uint64(a)
_b := uint64(b)
c := -((_a - _b) >> 63)
return T(_a&c | _b&^c)
}
@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],
@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/[email protected]"
echo "CA's self-signed certificate"
openssl x509 -in ca-cert.pem -noout -text
@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 / 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 / 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 / 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 / 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 / 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 / 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