Skip to content

Instantly share code, notes, and snippets.

Avatar
🐞

Ben Lopatin bennylope

🐞
View GitHub Profile
@andyrbell
andyrbell / scanner.sh
Last active Jun 8, 2021
Make a pdf look scanned using ImageMagick
View scanner.sh
# use ImageMagick convert
# the order is important. the density argument applies to input.pdf and resize and rotate to output.pdf
convert -density 90 input.pdf -rotate 0.5 -attenuate 0.2 +noise Multiplicative -colorspace Gray output.pdf
@maxogden
maxogden / bibtex.png
Last active Jun 6, 2021
How to make a scientific looking PDF from markdown (with bibliography)
@asfaltboy
asfaltboy / conftest.py
Last active Dec 9, 2020
A pytest fixture to test Django data migrations
View conftest.py
# based on https://gist.github.com/blueyed/4fb0a807104551f103e6
# and on https://gist.github.com/TauPan/aec52e398d7288cb5a62895916182a9f (gistspection!)
from django.core.management import call_command
from django.db import connection
from django.db.migrations.executor import MigrationExecutor
import pytest
@jcjones
jcjones / letsencrypt-renew.sh
Last active Oct 11, 2016
Cron script to renew Let's Encrypt certs using the official client
View letsencrypt-renew.sh
#!/bin/bash
# This is free and unencumbered software released into the public domain.
#
# This script is designed to be run daily by cron. Please run it with randomness in its timing to
# avoid load spikes at Let's Encrypt. One example, running between midnight at 2 AM, would be:
#
# 0 0 * * * sleep $[(RANDOM % 115)+5]m ; /usr/sbin/letsencrypt-renew.sh
#
# If you aren't using Nginx, adjust the startServer and stopServer methods to suit. Also, you could
# use the webroot method.
@grantmcconnaughey
grantmcconnaughey / pdf.py
Last active Feb 8, 2021 — forked from zyegfryed/pdf.py
Outputting PDFs with Django 1.8 and FDFgen
View pdf.py
# -*- coding: utf-8 -*-
import codecs
import subprocess
from fdfgen import forge_fdf
from django.core.exceptions import ImproperlyConfigured
from django.template import engines
from django.template.backends.base import BaseEngine
from django.template.engine import Engine, _dirs_undefined
View Makefile
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@burlresearch
burlresearch / .muttrc
Created Nov 19, 2014
Mutt IMAP setup for Google Apps account
View .muttrc
set realname = "Scott Burlington"
set from = "scott@burlresearch.com"
set imap_user = "scott@burlresearch.com"
set imap_pass = "XXX"
set smtp_url = "smtp://scott@burlresearch.com@smtp.gmail.com:587/"
set smtp_pass = "XXX"
set folder = imaps://imap.gmail.com/
set spoolfile = "+INBOX"
set postponed = "+[Gmail]/Drafts"
@danishabdullah
danishabdullah / Postgres kill all idle in transaction.md
Last active May 7, 2021
Postgres kill all idle in transaction
View Postgres kill all idle in transaction.md

given a database named db:

SELECT pg_terminate_backend(pid) 
FROM pg_stat_activity 
WHERE datname='db'
  AND state = 'idle in transaction'
@miraculixx
miraculixx / fieldselect.py
Last active Jun 7, 2017
select tastypie fields returned by the api
View fieldselect.py
class FieldSelectionMixin(object):
"""
add ability to Resource to query specific fields. This works by
removing any fields not in the fields list provided by the fields
query parameter.
Programming Use:
class MyResource(FieldSelectionMixin, ModelResource):
...
(as with any normal resource)
@senko
senko / maybe.py
Last active Mar 19, 2021
A Pythonic implementation of the Maybe monad
View maybe.py
# maybe.py - a Pythonic implementation of the Maybe monad
# Copyright (C) 2014. Senko Rasic <senko.rasic@goodcode.io>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#