Skip to content

Instantly share code, notes, and snippets.

View jhargis's full-sized avatar

Jay Hargis jhargis

  • Heroku
  • Portland, OR
View GitHub Profile
@jhargis
jhargis / README.md
Last active February 15, 2017 03:09
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
jhargis / supervisor.conf
Created August 30, 2016 22:52 — forked from tsabat/supervisor.conf
Sample supervisor config file
; Sample supervisor config file.
[unix_http_server]
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
jhargis / rdio_pl_export.js
Created November 20, 2015 01:20 — forked from nloko/rdio_pl_export.js
Export Rdio playlist as CSV
javascript:(function() {
var bookmarklet = {
init: function() {
this.parse();
},
parse: function() {
page = "";
/* you must be viewing songs ie. http://www.rdio.com/people/nloko/collection/songs/
when exporting a collection and this will only export the songs loaded in view,
@jhargis
jhargis / imagewiththumbnails_updateable.py
Last active August 29, 2015 14:27 — forked from valberg/imagewiththumbnails_updateable.py
Django create thumbnail form ImageField and save in a different ImageField - now with updating!
# Extension of http://www.yilmazhuseyin.com/blog/dev/create-thumbnails-imagefield-django/
# Note: image_folder and thumbnail_folder are both a callable (ie. a lambda that does a '/'.join())
class Image(Media):
image = models.ImageField(
upload_to=image_folder
)
thumbnail = models.ImageField(
@jhargis
jhargis / django-cherrypy.py
Created May 20, 2015 15:13
another way to run django on the cherrypy server
# http://www.defuze.org/archives/262-hosting-a-django-application-on-a-cherrypy-server.html
# Python stdlib imports
import sys
import logging
import os, os.path
# Third-party imports
import cherrypy
from cherrypy.process import wspbus, plugins
from cherrypy import _cplogging, _cperror
@jhargis
jhargis / serve.py
Last active August 29, 2015 14:21 — forked from nigma/serve.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import webbrowser
from threading import Timer
os.environ["DJANGO_SETTINGS_MODULE"] = "webapp.settings"
import cherrypy
@jhargis
jhargis / mk_playlist.py
Created May 16, 2015 12:07
Convert Grooveshark playlist files into .pls files for import into soundiiz.com
#!/usr/bin/python
# -*- coding: utf-8 -*-
#"SongName","ArtistName","AlbumName"
"""Convert Grooveshark playlist into .pls file for import into any music
service supported by http://soundiiz.com
usage: put this file in the same directory as the playlist you want to
convert. rename the file to tracks.csv then
@jhargis
jhargis / create_pls.py
Created May 16, 2015 12:03
create pls playlist files
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Create ``.pls`` playlists from music filenames.
Specify a path to be recursively searched for music files.
According to an `unofficial PLS format specification`__, the attribute
``NumberOfEntries`` can be placed *after* all entries. This allows to iterate
through filenames without keeping details for each entry in memory.
@jhargis
jhargis / django_bulk_export.py
Last active June 13, 2018 17:43
django and psycopg2 with server side cursors for memory efficient large bulk data exports
import uuid
import psycopg2
from psycopg2.extras import DictCursor
from django.conf import settings
from django.db import models
from django.contrib.auth.models import User
class classproperty(object):
from psycopg2.extras import DictCursor
from django.db import connections
def get_cursor(alias='default', cursor_factory=None):
# map from django's ORM layer to the raw DB cursor.
wrapped_conn = connections[alias]
# hack to ensure connection is immediately opened:
if wrapped_conn.connection is None: