Skip to content

Instantly share code, notes, and snippets.

View SiestaMadokaist's full-sized avatar

Rama Patria Himawan SiestaMadokaist

View GitHub Profile
@SiestaMadokaist
SiestaMadokaist / .bashrc
Created November 13, 2022 14:59
.bashrc for devcontainer
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
sudo tee /etc/yum.repos.d/mongodb-org-5.0.repo << EOF
[mongodb-org-5.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/8/mongodb-org/5.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-5.0.asc
EOF
sudo tee /etc/yum.repos.d/pritunl.repo << EOF
@SiestaMadokaist
SiestaMadokaist / wordle.ts
Last active January 28, 2022 07:12
Listing Possible words from wordle https://www.powerlanguage.co.uk/wordle/
interface IGuess {
word: string;
score: string;
};
const A = 'a'.charCodeAt(0);
export class Wordle {
/**
* 0 = possible
* 1 = impossible
@SiestaMadokaist
SiestaMadokaist / sudogen.ts
Created June 9, 2020 05:52
sudoku generator
class MySet<T> extends Set<T> {
static of<T>(...xs: T[]): MySet<T> {
return new this<T>(xs);
}
intersect(other: MySet<T>): MySet<T> {
const result = new MySet<T>();
for (const entry of this.values()) {
if (other.has(entry)) { result.add(entry); }
}
@SiestaMadokaist
SiestaMadokaist / factory.ts
Created May 22, 2019 07:33
FactoryType typescript
import Axios, { AxiosInstance } from 'axios';
abstract class BaseRequest {
abstract request(): AxiosInstance;
}
class Host1 extends BaseRequest {
request(): AxiosInstance { throw new Error('not implemented'); }
// todo
buyProduct() {
@SiestaMadokaist
SiestaMadokaist / GenericStream.ts
Created January 31, 2019 10:16
GenericStream
import { Readable, Transform, Writable } from 'stream';
export type Callback = (error: Error | null | undefined) => void;
export type TCallback = (error?: Error | undefined ) => void;
export abstract class GReadable<T1> extends Readable {
constructor(props: any = {}){
super({ ...props, objectMode: true });
};
_read(){}
@SiestaMadokaist
SiestaMadokaist / UserTransaction.md
Last active September 24, 2018 04:49
Nonce-based Transactional Database

Table UserTransactions

account_id {String} nonce {Integer} updates {Integer} balance {Integer} previous {Integer} Description {String}
0000001 0 0 0 0 Initialization
0000001 1 10 10 0 Deposit from ....

Constraint:

  • UNIQUE(AccountId, Nonce) prevent double spending
@SiestaMadokaist
SiestaMadokaist / FundBalancer.js
Created February 13, 2018 08:28
FundBalancing
const FundData = require('./FundData');
class FundBalancer {
constructor(){
this.state = { data: [] }
};
insert({ owner, current, expected }){
const fd = new FundData({ owner, current, expected });
this.data().push(fd);
}
# x - 2.y + z = 9
# 2.x - y = 4
# y + z = 12
[x] [1, -2, 1] [9]
[y] * [2, -1, 0] = [4]
[z] [0, 1, 1] [12]
# if we want to find out the x, y, and z, we can just
class LinearEquation
attr_reader(:eq)
extend Memoist
def initialize(&eq)
raise ArgumentError, "equation must be passed" unless block_given?
@eq = eq
end
def raw_equations