Skip to content

Instantly share code, notes, and snippets.

View 0xdeafbeef's full-sized avatar
🦀

Vladimir 0xdeafbeef

🦀
  • Belgrade
  • 03:13 (UTC +02:00)
View GitHub Profile
@0xdeafbeef
0xdeafbeef / jj.fish
Last active October 25, 2024 13:27 — forked from bnjmnt4n/jj.fish
Fish completions for Jujutsu
# Additional Fish completions for Jujutsu
# https://gist.github.com/bnjmnt4n/9f47082b8b6e6ed2b2a805a1516090c8
# TODO: passthru other args? E.g.. --at-operation, --repository
function __jj
command jj --ignore-working-copy --color=never --quiet $argv 2> /dev/null
end
# Aliases
# Based on https://github.com/fish-shell/fish-shell/blob/cd71359c42f633d9d71a63591ae16d150407a2b2/share/completions/git.fish#L625.
#!/bin/sh --
sysd=/etc/systemd/system
set -e
mkdir -p "$sysd/systemd-suspend.service.d"
cat > "$sysd/systemd-suspend.service.d/99-trigger-system-back-after-suspend.conf" <<'EOF'
[Service]
@0xdeafbeef
0xdeafbeef / hist.rs
Created May 19, 2023 10:24
print hist
fn print_hist(histogram: &Histogram) {
fn print_percentile(percentile: f64, hist: &Histogram) {
let bucket = hist.percentile(percentile).unwrap();
println!(
"Percentile {}% from {} to {} => {} count",
percentile,
bucket.low(),
bucket.high(),
bucket.count()
@0xdeafbeef
0xdeafbeef / parse-transaction.rs
Created February 18, 2023 14:58
parse-transaction.rs
use anyhow::Result;
use everscale_jrpc_client::JrpcClientOptions;
use tracing::log;
#[tokio::main]
async fn main() -> Result<()> {
env_logger::builder()
.filter(Some("everscale_jrpc_client"), log::LevelFilter::Debug)
.init();
let client = everscale_jrpc_client::JrpcClient::new(
@0xdeafbeef
0xdeafbeef / typecheck.rs
Created February 17, 2023 16:43
Find expected types for sqlx
#[cfg(test)]
mod test {
#[tokio::test]
async fn test() {
use sqlx::Executor;
let pool = sqlx::mysql::MySqlPoolOptions::new()
.connect(std::env!("DATABASE_URL"))
.await
.unwrap();
@0xdeafbeef
0xdeafbeef / Rabin.hs
Created December 4, 2019 21:00
Rabin
isPrime :: Int -> Bool isPrime n = millerRabinTest n (factorizeN (n-1)) {- factorizeN finds a number s and odd number d such that n -1 = (2^s)d by succesively dividing n by two if it is even. -} factorizeN :: Int -> (Int, Int) factorizeN n = fN n 0 where fN n s | even n = fN (n `div` 2) (s + 1) | otherwise = (n,s) {- this is the main function. it takes w values from a set of witnesses and checks if n passes the test. If it doesn't, n is not prime, if it does for all w, it is probably prime. -} millerRabinTest :: Int -> (Int,Int) -> Bool millerRabinTest n (d,s) = and [test n (expmod w d n) s | w <- onesToCheck] {- this is the test that is used in the millerRabinTest function. it sees if w^d = 1 mod n or n-1 mod n, if not it multiplies by two and checks again for a total of s-1 times. If it is never true then the number is not prime -} test :: Int -> Int -> Int -> Bool test n w s | w `elem` [1,n-1] = True | otherwise = or [ (expmod w (2^k) n) `elem` [1,n-1]| k <- [1..s]] {- set of witnesses that should make the
def jacobi(a, n):
assert(n > a > 0 and n%2 == 1)
t = 1
while a != 0:
while a % 2 == 0:
a /= 2
r = n % 8
if r == 3 or r == 5:
t = -t
a, n = n, a
@0xdeafbeef
0xdeafbeef / .py
Created March 14, 2019 20:10
legendre
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def isPrime(a):
return all(a % i for i in xrange(2, a))
# http://stackoverflow.com/a/14793082/562769
def factorize(n):
factors = []
@0xdeafbeef
0xdeafbeef / gist:5a35fc5f50b507b39089d3d39a79e969
Created January 22, 2018 14:26
Finds minimum code distance in BCH codes
public class MinDistanceSolver {
public static void main(String[] args) {
double currentRowState, p = 2.555 * Math.pow(10, -3), q = 1 - p, pTransformation = Math.pow(10, -11); // Данные
int dMinimum = 1, n = 31, k = 1; //Данные
double pInhibition; // Данные
System.out.println("-------------------------------------------------------"); //декоратор
do { //расчет Д минимум
System.out.print(dMinimum + " ");
currentRowState = combinator(n, dMinimum) * Math.pow(p, dMinimum) * Math.pow(q, n - dMinimum) * (((dMinimum + 1) * q) / ((dMinimum + 1) - ((n + 1) * p)));
System.out.println(currentRowState);