Skip to content

Instantly share code, notes, and snippets.

@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;
$ 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 / 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
@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 / 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 / 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.