Skip to content

Instantly share code, notes, and snippets.

@cdosborn
cdosborn / integral.py
Last active December 27, 2015 12:49
Integral approximation using the trapezoidal, midpoint, and simpson approximation technique.
# the midpoint approximation of the integral of x*x from [0 1], with 10 subdivisions
# integral.midpoint(lambda x: x*x,0,1,10)
def trapezoidal(f, start, end, n, _area=0, _n=0):
if _n is 0:
return trapezoidal(f, start, end, n, _area, n)
elif n is 0:
return _area
else:
delta_x = (end - start) / (_n * 1.0)

#lit - a modern literate programming tool

Lit has several notable features:

  • All prose can expressed in Markdown or plaintext
  • Supports all programming languages in theory
  • Literate constructs defined by indentation
  • Watch literate files for changes

Install

@cdosborn
cdosborn / hash-table.js
Created September 19, 2014 17:18
A simple hash table implementation.
function Map() {
var dict = {};
return {
add_key_value_pair: function(key, value) {
dict[key] = value;
},
get_value: function(key) {
var val = dict[key];
if (val === undefined) {
@cdosborn
cdosborn / Combinations.hs
Last active August 29, 2015 14:07
Recursion Spider Weasel
choose :: [a] -> Int -> [[a]]
choose _ 0 = [[]]
choose [] k = []
choose (x:xs) k = thoseWith ++ thoseWithout
where
thoseWith = map (x :) (choose xs (k - 1))
thoseWithout = choose xs k
@cdosborn
cdosborn / words
Created April 27, 2015 03:51
Ogden's Basic English (850 words)
come get give go keep let make put seem take be do have say see send may will about across after against among at before between by down from in off on over through to under up with as for of till than a the all any every little much no other some such that this I he you who and because but or if though while how when where why again ever far forward here near now out still then there together well almost enough even not only quite so very tomorrow yesterday north south east west please yes account act addition adjustment advertisement agreement air amount amusement animal answer apparatus approval argument art attack attempt attention attraction authority back balance base behavior belief birth bit bite blood blow body brass bread breath brother building burn burst business butter canvas care cause chalk chance change cloth coal color comfort committee company comparison competition condition connection control cook copper copy cork cotton cough country cover crack credit crime crush cry current curve dama
" Make switching buffers easy
nmap <Leader>b :ls<CR>:buffer!<Space>
imap \ <Esc>
vmap \ <Esc>
inoremap <C-\> \
nnoremap \ :noh<CR>
map <down> <C-d>zz
map <up> <C-u>zz
nnoremap <tab> zz

vim-tips

Whenever something feels tedious in vim, it's generally a sign of not full grokking vim. There's a better way.

Help

:help
:help {topic}

:help buff

@cdosborn
cdosborn / hyper-stats-ascii-name.txt
Last active August 29, 2015 14:22
hyper-stats splash name
,---, ___ ___
,--.' | ,-.----. ,--.'|_ ,--.'|_
| | : \ / \ __ ,-. ,---,. | | :,' | | :,'
: : : | : | ,' ,'/ /| ,' .' | .--.--. : : ' : : : ' : .--.--.
: | |,--. .--, | | .\ : ,---. ' | |' |,---.' ,/ / '.;__,' / ,--.--. .;__,' / / / '
| : ' | /_ ./| . : |: | / \ | | ,'| | | : /`./| | | / \ | | | | : /`./
| | /' :, ' , ' : | | \ : / / |' : / : : .'| : ;_ :__,'| : .--. .-. |:__,'| : | : ;_
' : | | /___/ \: | | : . |. ' / || | ' : |.' \ \ `. ' : |__ \__\/: . . '
@cdosborn
cdosborn / pager.awk
Last active May 13, 2022 23:06
pager.awk
#!/usr/local/bin/gawk -f
BEGIN {
for (i in ARGV) {
if (ARGV[i] == "--sep") {
sep = ARGV[i + 1];
"echo \'" sep "\'" | getline sep
}
ARGV[i] = "";
}
# Big ideas
#
# - 2 types of shell tools
# - Compute (ls, rm, find, grep, vim ..)
# - Format (sort, tail, cut, uniq, sed, ..)
# - awk is the ultimate formatting tool
# - a complete prog lang for text processing
# - handle state on the cmd line
# - 2 major datatypes