Skip to content

Instantly share code, notes, and snippets.

@lonetwin
lonetwin / ShowGitHubURL
Last active December 29, 2015 10:59
Vim function to echo the currently edited file's github url
function ShowGitHubURL()
" Function to echo the github URL for the currently open file at the
" current line number. This is useful if for example, you want to quickly
" share the URL for the file you're working on via, email / IRC etc.
"
" This can also be easily extended to open the browser with the displayed
" URL using tips such as http://vim.wikia.com/wiki/VimTip306
"
" You may add a mapping like this to bind this function to a keystroke:
" map <Leader>gh :call ShowGitHubURL()<CR>
@lonetwin
lonetwin / guitar_scales.py
Created September 26, 2013 18:19
Python functions to generate the names of the notes for various musical scales, meant to be used for quick reference when practising the guitar.
#!/usr/bin/env python
notes = ['a', 'a#', 'b', 'c', 'c#', 'd', 'd#', 'e', 'f', 'f#', 'g', 'g#'] * 2
chroma = lambda x: [ i for i in notes[ notes.index(x): ] + notes[ :notes.index(x) ] ] + [x]
major = lambda x: ( chroma(x)[:5] + [chroma(x)[5]] + chroma(x)[5:12] )[::2] + [x]
major_penta = lambda x: [ i for idx, i in enumerate(major(x)) if idx not in (3, 6) ]
minor_penta = lambda x: ( major_penta( notes[ notes.index(x) + 3 ])[:-1] * 2)[-6:]
"""
# for example
@lonetwin
lonetwin / pythonrc.py
Last active February 11, 2020 19:55
lonetwin's pimped-up pythonrc - Now at https://github.com/lonetwin/pythonrc
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# The MIT License (MIT)
#
# Copyright (c) 2015 Steven Fernandez
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@lonetwin
lonetwin / print_table.py
Last active May 7, 2021 15:42
print out ascii tables in python using data in the form: [ ('column 0 title', 'column 1 title' ..), ('row 0, column 0 data', 'row 0, column 1 data' ...) ...]
# I needed to print out ascii tables from data in the form:
# [ ('column 0 title', 'column 1 title' ..),
# ('row 0, column 0 data', 'row 0, column 1 data' ...) ...]
#
# and surprisingly it got complicated because of variable lengths of the data.
# I googled for 'standard' ways of doing this and I found suggestions like:
# http://stackoverflow.com/questions/5909873/python-pretty-printing-ascii-tables
# ...which were a bit dated and hard to read or full scale modules like:
#
# http://pypi.python.org/pypi/texttable/
@lonetwin
lonetwin / zodb_undo.py
Created June 23, 2011 09:33
Snippet to undo zodb transactions upto a specific point in the past
#!/usr/bin/python
# zodb_undo.py - Snippet to undo zodb transactions upto a specific point in the past
zodb_file = "var/karl.db"
undo_back_to = (2011, 6, 15, 11, 00, 00, 00, 00, 00) # time tuple
import time
import transaction
from ZODB import FileStorage, DB