Skip to content

Instantly share code, notes, and snippets.

@amagee
amagee / gist:20720187155f7e383d7b89ca9acb9d42
Created November 22, 2016 23:47
IPython export history as text
%history -g -f <filename>
# http://stackoverflow.com/a/16595367/223486
find . -not \( -path ./node_modules -prune \) -name '*.js
# Note that the behaviour is different if you reverse the -name and -not arguments.
sudo apt-get --reinstall install virtualbox-dkms
# http://askubuntu.com/a/768310/211502
# for example...
for MODULENAME in vboxdrv vboxnetflt vboxnetadp vboxpci; do
openssl req -new -x509 -newkey rsa:2048 -keyout MOK.priv -outform DER -out MOK.der -nodes -days 36500 -subj "/CN=Descriptive name/"
sudo /usr/src/linux-headers-$(uname -r)/scripts/sign-file sha256 ./MOK.priv ./MOK.der $(modinfo -n $MODULENAME)
sudo mokutil --import MOK.der
-- http://stackoverflow.com/a/36023359/223486
Executable in psql shell:
DO $$ DECLARE
r RECORD;
BEGIN
-- if the schema you operate on is not "current", you will want to
-- replace current_schema() in query with 'schematodeletetablesfrom'
-- *and* update the generate 'DROP...' accordingly.
@amagee
amagee / jinja2template.py
Last active June 25, 2017 02:14
Jinja2 template string
>>> import jinja2
>>> jinja2.Template("{{ variable }}").render(variable="value")
'value'
>>> import jinja2, json
>>> t = jinja2.Template("{{ a | json }}")
>>> t.environment.filters['json'] = json.dumps
>>> t.render(a="\n\n\n")
'"\\n\\n\\n"'
@amagee
amagee / ag_examples.sh
Last active March 6, 2017 02:26
Useful ag examples
# Grep for text but don't filter lines, just highlight the matches
ag <search> --passthrough
# Show a number of lines after the match
ag <search> -A <num>
# One result per line (ie. don't group by filename.. useful for piping to `wc -l`)
ag <search> --nogroup
# Case sensitive
@amagee
amagee / deb_extract_unextract.sh
Created June 4, 2016 11:45
How to extract a .deb file and repackage it
% ar x file.deb
(Creates control.tar.gz data.tar.xz debian-binary)
% ar file.deb control.tar.gz data.tar.xz debian-binary
(Recreates file.deb from those three files)
@amagee
amagee / localecompare_example.js
Created June 3, 2016 01:54
Javascript case insensitive string sort without toLowerCase etc
>>> 'a'.localeCompare('A', 'en', {sensitivity: 'base'})
0
Input:
<div className="daily-timesheet">
<h1>Hello</h1>
<MyWidget />
<SaveStatus />
</div>
Output:
@amagee
amagee / SortedListWithKey_bisect_right.py
Created May 5, 2016 03:02
Demo of SortedListWithKey.bisect_right
def f():
lst = SortedListWithKey([1,4,8,16], lambda k: k)
for i in range(0, 20):
print(i, lst[max(lst.bisect_right(i) - 1, 0)])
>>> f()
0 1
1 1
2 1
3 1