Skip to content

Instantly share code, notes, and snippets.

View kodejuice's full-sized avatar

Sochima Biereagu kodejuice

View GitHub Profile
@kodejuice
kodejuice / weighted_stocks.py
Last active August 29, 2023 12:17
I use this script to know the amount of stocks i need to buy given a certain amount
# Sochima Biereagu (@kodejuice), 2023
# I use this script to know the amount of stocks i need to buy given a certain amount
# I have weighted all the stocks listed here
# The stocks listed are mostly Nigeria, China, Japan, India stocks plus some other stocks in US
# Last updated: Aug 2023
"""
Usage
python weighted_stocks.py [amt] [...categories]
@kodejuice
kodejuice / partition_rank_unrank.py
Last active August 28, 2023 12:58
Return the rank of a partition with k parts which sums up to n, and also convert back
from functools import lru_cache
def p_single(n, k=0):
k = k or n
'''Return total number of partition for integer N of length k'''
dp = [[0 for j in range(k+1)] for i in range(n+1)]
for i in range(n+1):
for j in range(k+1):
if i == 0 and j == i:
@kodejuice
kodejuice / permuation_rank_unrank.py
Created March 24, 2023 07:48
Permutation ranking / unranking
from functools import lru_cache, reduce
from collections import Counter
f_memo = {0: 1}
@lru_cache(maxsize=None)
def F(n):
'''Compute Factorial'''
if n in f_memo:
@kodejuice
kodejuice / perf_test.cc
Created July 30, 2018 22:18
A minimal C++ code perfomance tester
/**
A minimal code perfomance tester for C++ that aids in measuring the execution speed of parts of your program,
it reports the (operatations per second) as opposed to the traditional (time taken to run) approach,
the programs repeatedly runs the given function for a couple of seconds,
and returns the number of operations it could perform in a single second (cycles per second).
See Example/Sample usage at bottom of code
@kodejuice
kodejuice / bible_verses.json
Created September 28, 2022 10:09
All verses of the KJV bible in a single array
This file has been truncated, but you can view the full file.
[{"verse":"1 Chronicles 1:1 (KJV)","text":"Adam, Sheth, Enosh,"},{"verse":"1 Chronicles 1:2 (KJV)","text":"Kenan, Mahalaleel, Jered,"},{"verse":"1 Chronicles 1:3 (KJV)","text":"Henoch, Methuselah, Lamech,"},{"verse":"1 Chronicles 1:4 (KJV)","text":"Noah, Shem, Ham, and Japheth."},{"verse":"1 Chronicles 1:5 (KJV)","text":"The sons of Japheth; Gomer, and Magog, and Madai, and Javan, and Tubal, and Meshech, and Tiras."},{"verse":"1 Chronicles 1:6 (KJV)","text":"And the sons of Gomer; Ashchenaz, and Riphath, and Togarmah."},{"verse":"1 Chronicles 1:7 (KJV)","text":"And the sons of Javan; Elishah, and Tarshish, Kittim, and Dodanim."},{"verse":"1 Chronicles 1:8 (KJV)","text":"The sons of Ham; Cush, and Mizraim, Put, and Canaan."},{"verse":"1 Chronicles 1:9 (KJV)","text":"And the sons of Cush; Seba, and Havilah, and Sabta, and Raamah, and Sabtecha. And the sons of Raamah; Sheba, and Dedan."},{"verse":"1 Chronicles 1:10 (KJV)","text":"And Cush begat Nimrod: he began to be mighty upon the earth."},{"verse":"1 Chronicl
@kodejuice
kodejuice / brainfuck.c
Last active September 1, 2022 14:45
A simple brainfuck interpreter written in C
char * brain_fuck(char * code, char * input){
const int BUFSIZE = 30000;
int * ptr = (int *) malloc(BUFSIZE * sizeof(int)),
i_sz = strlen(input), c_sz = strlen(code),
idx = -1, j = 0, o = 0;
char cmd, * output = (char *) malloc(BUFSIZE);
while (idx++ < c_sz){
cmd = code[idx];
@kodejuice
kodejuice / javascript_object_iteration.js
Last active July 23, 2022 20:32
Iterate over JavaScript objects like its a Map, with the for...of statement
Object.prototype[Symbol.iterator] = function* (){
let c = 0;
const [key, values] = [Object.keys(this), Object.values(this)];
while (c < keys.length) {
yield [keys[c], values[c++]]
}
}
// usage
let obj = {

Keybase proof

I hereby claim:

  • I am kodejuice on github.
  • I am kodejuice (https://keybase.io/kodejuice) on keybase.
  • I have a public key whose fingerprint is 4EF1 0FDD F84F 3BCC 8E0C 1888 F5FB A1CC C744 DCF9

To claim this, I am signing this object: