Skip to content

Instantly share code, notes, and snippets.

View pielgrzym's full-sized avatar
☂️

Q pielgrzym

☂️
View GitHub Profile
### Keybase proof
I hereby claim:
* I am pielgrzym on github.
* I am pielgrzym (https://keybase.io/pielgrzym) on keybase.
* I have a public key whose fingerprint is 661F 1ECA AD56 830A 98CC AC29 6549 E7D0 F0EB 09F8
To claim this, I am signing this object:
class OV
def vals
['a', 'b', 'c']
end
# this will make this work:
# OV.new == 'a'
# true
# OV.new == 'b'
# true
import sys
import functools
class der(object):
def __init__(self, h):
if isinstance(h, float):
self.h = h
else:
self.h = sys.float_info.epsilon*1000
def mean(Z):
def sr(x, y):
cnt = x[1] + 1
return x[0]+y, cnt, (x[0]+y)/cnt
return reduce(sr, Z, [0,0,0])[2]
assert mean([1,2,3]) == 2
assert mean([1.5, 2.5, 3.5]) == 2.5
assert mean([1]) == 1
assert mean([-2.0, 2.0, 0.0]) == 0
@pielgrzym
pielgrzym / watch-todo.sh
Last active December 10, 2015 12:38
Using inotifywait.
watch_todo(){
tput smcup
while : ; do
tput clear
echo -n "${bg[cyan]}[[[ TODO: ]]]$reset_color\n"
if [[ -n $1 ]]; then
todo.sh "$@"
else
todo.sh ls
fi
better_which(){
tput smcup
local -i i="$1"
shift
while : ; do
tput clear
"$@"
sleep $i
trap 'break' 2
done
#!/bin/zsh
i=1
sp="/-\|"
echo -n ' '
while true
do
printf "\b${sp:i++%${#sp}:1}"
done
redir => lsoutput
!ls /home/pielgrzym/.vimsessions
redir END
return split(lsoutput, '\r')[1:]
function! RunDoctests()
let fname = expand('%:p')
:w<cr> :vne
:set ft=python
:set buftype=nofile
:setlocal noswapfile
:exec ':silent r!python2 -m doctest -f' fname
endfunction
autocmd FileType python nnoremap T :call RunDoctests()<cr>
global !p
def fb(string, c=0):
'''Count brackets'''
left_bracket = string.find("(")
if left_bracket > -1:
string = string[left_bracket + 1:]
right_bracket = string.find(")")
if right_bracket > -1:
if string[:right_bracket].find("(") == -1:
c += 1