Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
echo hello world
@yamavol
yamavol / resp.rs
Created April 8, 2023 06:36
StringJsonfiyService (not working because trait boundray RespBody is not convertible to actual bytes (required by http::body::to_bytes))
#[derive(Clone)]
pub struct StringJsonifyService<S> {
inner: S,
}
/// Service implementation
impl<S, B, ResBody> Service<Request<B>> for StringJsonifyService<S>
where
S: Service<Request<B>, Response = Response<ResBody>> + Clone + Send + 'static,
S::Future: Send + 'static,
@yamavol
yamavol / perlin.js
Created February 5, 2023 11:19
2d perlin & fbm implementation for learning
const MAX_PERIOD = 256;
const RANDOM_SEED = 12345678;
const OCTAVE = 4;
const LACUNARITY = 2.0;
const ATTENUATION = 0.6;
/**
* @generator
* @param {number} seed a 32bit integer
@yamavol
yamavol / python_scope.py
Created October 29, 2022 13:52
Example of python function referencing a outer scope variable
def check():
print(a) # referencing undefined variable?
if True:
a = 1
# when True : 1
# when False: name 'a' is not defined
check()
@yamavol
yamavol / block_heuristics.py
Created August 5, 2022 07:00
Another worthless program
import re
import sys
"""
parse size representing string and returns digits and unit in tuple
## Example
Input: "128mb"
Output: (128, "mb")
"""
def parse_size_string(line: str):
@yamavol
yamavol / hex.rs
Created July 22, 2022 05:58
Hex code
///
/// Hex Program
///
/// Prints binary data of a specified file to stdout.
///
fn main() {
let args: Vec<_> = std::env::args().collect();
if args.len() < 2 {
@yamavol
yamavol / isupper.c
Created June 24, 2022 07:58
Do not trust stdlib function for lexical analysis because it refers locale
#include <stdio.h>
#include <locale.h>
#include <ctype.h>
int main(void) {
if (setlocale(LC_ALL, "De_DE") == NULL) {
puts("cannot set locale");
}
printf("is A umlaut upper?: %d", isupper(196));
return 0;
@yamavol
yamavol / rsa.py
Created June 7, 2022 15:05
RSA encryption and decryption
# from Crypto.Util.number import *
from Cryptodome.Util.number import *
mb = b'a secret message to be encrypted'
m = bytes_to_long(mb)
p = getPrime(256)
q = getPrime(256)
n = p * q
@yamavol
yamavol / euclidean.py
Last active June 7, 2022 07:53
learn Euclidean algorithms
from typing import Tuple
"""
Euclidean Algorithm
Finds GCD(Greatest Common Divisor) from two integers.
The algorithm is built on the proof that states common divisors of (A,B)
is equal to (B,R) where R is the remainder of A = BQ + R. When R is 0,
A = BQ, B is the greatest common divisor of (A,B) because A and B is both
@yamavol
yamavol / PlayRedux.tsx
Created August 11, 2020 05:29
Learning Redux in Typescript
import React, { useCallback } from 'react'
import { createStore, Action, combineReducers, Dispatch } from 'redux'
import { Provider, useDispatch, useSelector } from 'react-redux'
// Action Type List.
// This ID is used to identify different actions.
export const ActionTypes = {
Increment: "INCREMENT",
Decrement: "DECREMENT",
} as const;