This file contains hidden or 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 itertools | |
#ugly one-liner | |
def _ugly_split_at(pred, seq): | |
return list(itertools.ifilter( | |
None, | |
[ | |
( | |
(seq[idx:idx+1] + list(itertools.takewhile(lambda x: not pred(x), seq[idx+1:]))) | |
if idx == 0 or pred(el) | |
else [] |
This file contains hidden or 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
"Copy all matches to a vim search and paste in new buffer separated by lines | |
"Source this file to try it out. | |
"Let's say you have a python file and want to find all the methods/properties | |
"on self mentioned in a file (commence esoteric example): | |
"class Student(object): | |
" def __init__(self, name): | |
" self.name = name | |
" def set_gpa(self, gpa): |
This file contains hidden or 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
"I recorded a macro of the command. These are the keystrokes I hit to do one line | |
"To do all lines, I recorded the macro in register q (starting on the first line of names.csv) | |
"then did 2@q to repeat macro twice more. | |
"This assumes the template is in the same dir and is very brittle | |
"You should use a templating engine like genshi for non-trivial templating, but just wanted to show that this is possible | |
"Creates $email.html file for each email address. | |
0"ayt,f,l"by$:new^M;read template.html^M:%s;\$EMAIL;^Ra;g^M:s;$NAME;^Rb;g^M:w! ^Ra.html^M:bd^Mj |
This file contains hidden or 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
"These lines map a hotkey that allow you to easily execute the current line or | |
"selection by hitting F9. It's a cheesy hack that made demoing while reading | |
"through this more simple. | |
" | |
"This is also why commands start with colons. Normally colons would be | |
"unnecessary if trying to execute these in your vimrc. | |
:nnoremap <F9> "ayy@a | |
:vnoremap <F9> "ay@a | |
"Marks {{{ |
This file contains hidden or 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
"with your cursor on a line or a block selected, type `:HL` | |
"to remove, on each line call :sign unplace | |
highlight HL ctermbg=darkgray | |
sign define hl linehl=HL | |
let s:highlightLineSignId = 74000 | |
function! g:HighlightLine() | |
execute 'sign place' s:highlightLineSignId 'line='.line(".") 'name=hl' 'file='.expand("%") | |
let s:highlightLineSignId += 1 | |
endfunction | |
command! HL call g:HighlightLine() |
This file contains hidden or 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
#tl: list sessions | |
alias tl='tmux ls' | |
#tn <name>: create a session named <name> | |
alias tn='tmux -2 new -s' | |
#ta <name>: attach to a session named <name> | |
alias ta='tmux -2 attach -t' | |
This file contains hidden or 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
nnoremap <silent> <leader>gm :tab split<CR>:Glistmod<CR> | |
nnoremap <silent> <c-s-j> :call g:DiffNextLoc()<CR> | |
nnoremap <silent> <c-s-k> :call g:DiffPrevLoc()<CR> | |
command! Glistmod only | call g:ListModified() | Gdiff | |
function! g:ListModified() | |
let old_makeprg=&makeprg | |
let old_errorformat=&errorformat | |
let &makeprg = "git ls-files -m" | |
let &errorformat="%f" |
This file contains hidden or 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 sys, re #thumbtack pycon tetris challenge. "dense" solution by @mattboehm | |
def shift_down(col):#shift piece down 1 space | |
loc = "".join(col[::-1]) | |
space = loc.find("#") - 1 | |
return col if loc == -2 else list(loc[:space] + loc[space+1:] + ".")[::-1] | |
def top_row_blank(board):#check if the top row has only . | |
return all(tile == "." for tile in board[0]) | |
def find_piece(board):#Replace the X's for the piece with # | |
board, marked_board = board[:], [] | |
while top_row_blank(board):#skip top blank rows |
This file contains hidden or 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
function! SplitRegex() | |
tabnew | |
setlocal buftype=nofile bufhidden=hide noswapfile | |
let numlines=len(@") | |
execute "normal! V".numlines."pggjl" | |
let tmp=@z | |
let @z="hv0r wlv$r j" | |
execute "normal! ".(numlines-2)."@z" | |
let @z=tmp | |
execute "normal! gglv$r\<space>" |
This file contains hidden or 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
#!/usr/bin/env bash | |
if [ "$#" -ne 2 ] | |
then | |
echo "move a directory to a new location. | |
While normally, git mv old-dir new-dir should work, let's say you do that and then try to merge in another branch where someone's added new files to old-dir. | |
these files will stay in old-dir, and we need a way to merge their (arbitrarily deeply nested) contents into new-dir. This script uses cp -r to merge the contents, | |
followed by git add/rm. When you do git status, it should now show that all those files have been moved. | |
Warning: script will add the whole target directory, including uncommitted changes on files that existed before it ran." | |
echo "usage: $0 <old-dir> <new-dir>" |
OlderNewer