Skip to content

Instantly share code, notes, and snippets.

View cleoold's full-sized avatar
🤔
thonking

midori cleoold

🤔
thonking
View GitHub Profile
@cleoold
cleoold / day of week (arithmetic).rkt
Created December 6, 2018 19:53
Gives you what day it is
;; given a date after Gregorian calendar being effective
;; returns the day of the week
;; input format: yyyymmdd
;; date->day-of-week: Nat -> Sym
(define (date->day-of-week date)
(cond [(= (w date) 0) 'Sunday]
[(= (w date) 1) 'Monday]
[(= (w date) 2) 'Tuesday]
@cleoold
cleoold / fibonacci.rkt
Created December 6, 2018 19:56
Fibonacci sequence with offsets and weights
;; Fibonacci with offsets and weights
;; F(0) = A
;; F(1) = B
;; F(n) = xF(n-2) + yF(n-1)
(define (weighted-fibonacci n A B x y)
(cond
[(= n 0) A]
[(= n 1) B]
[else
@cleoold
cleoold / sum of polynomial.rkt
Created December 9, 2018 03:17
The sum of a polynomial
;; computes the result of a given polymonial using Horner's method
;; a Poly (polynomial) is one of
;; * (cons Num null)
;; * (cons Num poly)
;; format of the polynomial
;; (list a-0 a-1 a-2 ... a-n) corresponds to
;; (a-0)+(a-1)x^1+(a-2)x^2+...+(a-n)x^n

Created notes for Racket

I recently created a note that has some useful functions written in Racket language. They will sometimes be useful to me and, I think, some others. Please refer to https://github.com/cleoold/rktbsl

@cleoold
cleoold / folder_size.py
Created May 11, 2019 10:47
Getting the size of a folder in Python
import os
def getFolderSize(folder):
totalSize = 0
for eachfile in os.listdir(folder):
currPos = os.path.join(folder, eachfile)
if os.path.isfile(currPos):
totalSize += os.path.getsize(currPos)
else:
totalSize += getFolderSize(currPos)
return totalSize
@cleoold
cleoold / permutation.py
Created May 12, 2019 15:51
getting all permutations in python with eval
# getting all permutations of N items in lst in python with eval
# iterable Int -> [(...) (...) ...]
def permute(lst, N):
if N == 0 or N > len(lst):
return []
elif N < 0:
raise ValueError('Second argument must be non-negative.')
item = tuple(('i' + str(d) for d in range(N))) # tuple
itemStr = '(' + ','.join(item) + ')' # str
forSentence = ' '.join(' for ' + i + ' in _lst ' for i in item).replace('_lst', str(list(lst))) # str
@cleoold
cleoold / .cshrc
Created January 7, 2020 20:52
a tcsh console coloring setting
alias ls ls -GF
setenv EDITOR nano
setenv PAGER less
set prompt='\n%? %{\033[38;5;25m%}[%w %D %T]%{\033[0m%} %{\033[38;5;22m%}%n@%m %{\033[38;5;75m%}%~ >%{\033[0m%} '
@cleoold
cleoold / pipe.c
Created January 12, 2020 21:41
C pipe system call
/**
* write string into pipe, read after
*/
#include <assert.h>
#include <unistd.h>
#include <stdio.h>
#include <strings.h>
#define SIZE 99
@cleoold
cleoold / index.html
Last active January 24, 2020 18:13
minimal reactjs page
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Clock</title>
</head>
<body>
@cleoold
cleoold / stringutil.cpp
Last active January 27, 2020 00:00
C++ string join and split util
#include <string>
#include <vector>
#include <iostream>
#include <cassert>
/** splits str into vector of substrings, str is not changed */
std::vector<std::string> StringSplit(std::string str, const std::string delim)
{
std::vector<std::string> res;