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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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%} ' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* write string into pipe, read after | |
*/ | |
#include <assert.h> | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <strings.h> | |
#define SIZE 99 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
OlderNewer