Skip to content

Instantly share code, notes, and snippets.

Jay Hargis jhargis

  • Heroku
  • Portland, OR
Block or report user

Report or block jhargis

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View postgres_queries_and_commands.sql
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
jhargis /
Last active Aug 24, 2018 — forked from mage2k/gist:747674bb8a1a970007952adc283a857c
Trick for removing table bloat without requiring a full table lock and production halt

Given a table bar that we need to compact while maximizing availability of the data in it and minimize load/IO during compaction.

First, if there are any tables with foriegn key columns referencing columns in bar those foreign keys need to be disabled, e.g:


Now we can work on compacting the data by copying it to a new table.

SQL to create a new, empty table and have the current table inherit from it:

View .screenrc
caption string "%?%F%{= Bk}%? %C%A %D %d-%m-%Y %{= kB} %t%= %?%F%{= Bk}%:%{= wk}%? %n "
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]'
jhargis /
Created Oct 26, 2017
simple signal handler example
import sys
import signal
# custom signal handler
def signal_handler(signal, frame):
print 'Interrupt caught. Exiting.'
# register
signal.signal(signal.SIGINT, signal_handler)
jhargis /
Created Mar 29, 2017 — forked from arobb/
Install macOS Sierra in VirtualBox on macOS host

Step 1 (Creating a bootable macOS Sierra ISO for VirtualBox):

  1. hdiutil attach /Applications/Install\ macOS\ Sierra\ Public\ -noverify -nobrowse -mountpoint /Volumes/install_app
  2. hdiutil create -o /tmp/Sierra.cdr -size 7316m -layout SPUD -fs HFS+J
  3. hdiutil attach /tmp/Sierra.cdr.dmg -noverify -nobrowse -mountpoint /Volumes/install_build
  4. asr restore -source /Volumes/install_app/BaseSystem.dmg -target /Volumes/install_build -noprompt -noverify -erase
  5. rm /Volumes/OS\ X\ Base\ System/System/Installation/Packages
  6. cp -rp /Volumes/install_app/Packages /Volumes/OS\ X\ Base\ System/System/Installation/
  7. cp -rp /Volumes/install_app/BaseSystem.chunklist /Volumes/OS\ X\ Base\ System/BaseSystem.chunklist
youtube-dl --extract-audio --audio-format mp3 <video URL>
youtube-dl -i "<Youtube URL>" -o "%(title)s.%(ext)s" --extract-audio --audio-format "mp3" --audio-quality "192k"
jhargis /
Last active Feb 15, 2017
letsencrypt certbot nginx easy setup and renewals

Prerequisites : the letsencrypt CLI tool

This method allows your to generate and renew your Lets Encrypt certificates with 1 command. This is easily automatable to renew each 60 days, as advised.

You need nginx to answer on port 80 on all the domains you want a certificate for. Then you need to serve the challenge used by letsencrypt on /.well-known/acme-challenge. Then we invoke the letsencrypt command, telling the tool to write the challenge files in the directory we used as a root in the nginx configuration.

I redirect all HTTP requests on HTTPS, so my nginx config looks like :

server {
jhargis / supervisor.conf
Created Aug 30, 2016 — forked from tsabat/supervisor.conf
Sample supervisor config file
View supervisor.conf
; Sample supervisor config file.
file=/tmp/supervisor.sock ; (the path to the socket file)
;chmod=0700 ; sockef file mode (default 0700)
;chown=nobody:nogroup ; socket file uid:gid owner
;username=user ; (default is no username (open server))
;password=123 ; (default is no password (open server))
;[inet_http_server] ; inet (TCP) server disabled by default
jhargis / rdio_pl_export.js
Created Nov 20, 2015 — forked from nloko/rdio_pl_export.js
Export Rdio playlist as CSV
View rdio_pl_export.js
javascript:(function() {
var bookmarklet = {
init: function() {
parse: function() {
page = "";
/* you must be viewing songs ie.
when exporting a collection and this will only export the songs loaded in view,
jhargis /
Last active Aug 29, 2015 — forked from valberg/
Django create thumbnail form ImageField and save in a different ImageField - now with updating!
# Extension of
# Note: image_folder and thumbnail_folder are both a callable (ie. a lambda that does a '/'.join())
class Image(Media):
image = models.ImageField(
thumbnail = models.ImageField(
You can’t perform that action at this time.