Skip to content

Instantly share code, notes, and snippets.

View pielgrzym's full-sized avatar
☂️

Q pielgrzym

☂️
View GitHub Profile
class BasketBase(type):
def __new__(mcs, classname, bases, class_dict):
class_dict['actions'] = {}
class_dict['basketactions'] = {}
for elem in class_dict:
if elem.startswith("action_"):
class_dict['actions'][elem.replace("action_","")] = class_dict[elem]
if elem.startswith("basketaction_"):
class_dict['basketactions'][elem.replace("basketaction_","")] = class_dict[elem]
for elem in class_dict.keys():
function! PyLintCwindow()
" some comment
if g:pymode_lint_cwindow == 1
let g:pymode_lint_cwindow = 0
else
let g:pymode_lint_cwindow = 1
endif
endfunction
function rconfirm(){
if [[ ${SSH_CONNECTION:0} != 0 ]];then
local confirm
echo " ___ "
echo "{o,o}"
echo "|)__)"
echo "-\"-\"-"
echo "O RLY?"
read -q confirm
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
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>
redir => lsoutput
!ls /home/pielgrzym/.vimsessions
redir END
return split(lsoutput, '\r')[1:]
#!/bin/zsh
i=1
sp="/-\|"
echo -n ' '
while true
do
printf "\b${sp:i++%${#sp}:1}"
done
better_which(){
tput smcup
local -i i="$1"
shift
while : ; do
tput clear
"$@"
sleep $i
trap 'break' 2
done
@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
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