Skip to content

Instantly share code, notes, and snippets.

@jnm
jnm / passy.html
Created July 17, 2013 18:58
Bulk password generator based on http://passphra.se/
<html>
<head>
<script>
/*
* A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
* in FIPS 180-1
* Version 2.2 Copyright Paul Johnston 2000 - 2009.
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
* Distributed under the BSD License
* See http://pajhome.org.uk/crypt/md5 for details.
@jnm
jnm / vzdump-du.sh
Last active December 20, 2015 00:19
Show total vzdump backup disk usage per container/virtual machine
for i in $(ls -1 vzdump* | cut -f -3 -d - | sort | uniq); do echo -n $(du -c --block-size=1G $(eval echo '$i*') | tail -n 1 | cut -f 1); echo -e "\t$i"; done | sort -n
@jnm
jnm / container-disk-use.sh
Created March 11, 2014 13:57
Show OpenVZ containers' disk use in GB and as percentage of the host's total disk space. Tested with Proxmox VE.
#!/bin/bash
# jnm 20140311
TOTAL_AVAILABLE=$(df /var/lib/vz | grep '/var/lib/vz$' | awk '{ print $2 }')
vzlist -o ctid,numproc,status,ip,hostname,diskspace -s diskspace | awk "
{
printf \$0 \"\t\"
if(NR==1)
{
print \"in G\tas % of host\"
}
@jnm
jnm / gist:3f932b1cbbaf90557482
Created May 6, 2014 02:15
line_profiler thing
def get_report(self, report_view, context):
import line_profiler
profiler = line_profiler.LineProfiler()
profiler.add_function(self.arse_get_report)
profiler.enable_by_count()
out = self.arse_get_report(report_view, context)
profiler.print_stats()
return out
$ mkdir /tmp/empty
$ cd /tmp/empty
$ ls -la
total 8
drwxrwxr-x 2 john john 4096 jun 9 13:31 .
drwxrwxrwt 11 root root 4096 jun 9 13:31 ..
$ echo 'print "trololo"' > dumb.py
$ python
Python 2.7.5+ (default, Feb 27 2014, 19:37:08)
[GCC 4.8.1] on linux2
@jnm
jnm / change-owner-all-tables.sql
Last active October 15, 2018 18:31
Change owner of all tables in a database using pure PostgreSQL
DO
$$
DECLARE
row record;
BEGIN
FOR row IN SELECT table_name FROM information_schema.tables
WHERE table_schema <> 'pg_catalog' AND table_schema <> 'information_schema' AND table_catalog = 'kobotoolbox'
LOOP
EXECUTE 'ALTER TABLE ' || quote_ident(row.table_name) || ' OWNER TO kobo;';
END LOOP;
@jnm
jnm / download-loop.html
Last active September 11, 2015 15:22
Test a connection by repeatedly downloading a file
<html>
<head><title>download test</title></head>
<body>
<input type="text" id="status" style="width: 100%">
<div id="log"></div>
<script>
/*
mostly cookbooked from
https://developer.mozilla.org/en/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Monitoring_progress
import requests
import sys
import xml
import hashlib
import getpass
import datetime
from collections import OrderedDict
from django.conf import settings
@jnm
jnm / mongo_keys.js
Created July 15, 2016 14:46
Get all the keys from all documents in a Mongo collection
// mapReduce idea credit: http://stackoverflow.com/a/2308036
db.instances.mapReduce(
function() {
// map
for(var key in this) {
emit(key, null);
}
},
function(key, values) {
// reduce
<div class="tumblr-post" data-href="https://embed.tumblr.com/embed/post/1GjIG-_i_PMG0qAkoklkwQ/161507154717" data-did="2bd38ed99a4c97a215bb75c2085abf410fffcbbc"><a href="http://nancy-elsner-archive.tumblr.com/post/161507154717/a-gay-icon-batmanissue455oct1990">http://nancy-elsner-archive.tumblr.com/post/161507154717/a-gay-icon-batmanissue455oct1990</a></div> <script async src="https://assets.tumblr.com/post.js"></script>