Skip to content

Instantly share code, notes, and snippets.

@Jc2k
Jc2k / README.md
Last active July 22, 2024 21:26
Database rollback options in Django

Batching migrations

The idea here is that if you know which migrations were in version 2.0.3 of your project and which were in version 2.0.4 then setA - setB gives you the list of migrations you need to undo.

Django migrations give you a directed acyclic graph which describes how to get from the current database state to the target state. But there is no mechanism by which you can perform tasks like revert all the migrations that just ran in the last deployment.

Here is a quick recipe for batching Django migrations to allow you to do things like that.

Before you tag your project you do:

@Jc2k
Jc2k / .bash_profile
Last active March 24, 2024 14:42
GPG Cheat Sheet
if [ -f "${HOME}/.gpg-agent-info" ]; then
. "${HOME}/.gpg-agent-info"
export GPG_AGENT_INFO
export SSH_AUTH_SOCK
export SSH_AGENT_PID
fi
@Jc2k
Jc2k / schedule.py
Last active April 1, 2016 13:06
Get totals for how many hours an engineer spends on call for a given PagerDuty schedule
from __future__ import print_function, division
from decimal import Decimal
import argparse
import datetime
import getpass
import sys
from dateutil.parser import parse
from dateutil.relativedelta import relativedelta
@Jc2k
Jc2k / newrelic_to_git.py
Created March 21, 2016 11:31
Generate a git repo out of a python packages releases
import os
import subprocess
import sys
import requests
from pip.index import PackageFinder
p = PackageFinder([], ["https://pypi.python.org/simple"], session=requests.Session())
versions = p._find_all_versions("newrelic")
versions = sorted(
versions,
@Jc2k
Jc2k / find_tags.py
Created March 21, 2016 14:05
Find the first tag a file was in and the last tag it was changed in
import subprocess
tags = [
subprocess.check_output(["git", "rev-list", "--max-parents=0", "HEAD"]).strip()
]
tags.extend(
subprocess.check_output(["git", "tag", "-l"]).split(),
)
added = {}
@Jc2k
Jc2k / post.md
Last active June 27, 2018 07:02
My first alexa skill

Backend

I used the alexandra python package. See https://pypi.python.org/pypi/alexandra. It abstracts away dealing with HTTP or Lambda and you just use decorators to map Alexa intents to python functions. Here is my test.py:

import alexandra

app = alexandra.Application()
name_map = {}

@app.launch

@Jc2k
Jc2k / walkthrough.md
Last active November 20, 2017 05:51
Installing cowrie with systemd on Ubuntu 16.04

This is a quick demo of using twisted enpoints with cowrie to be able to use systemd socket activation. This has been tested on a fresh install of Ubuntu 16.04.2:

Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-62-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

Last login: Tue May 2 23:47:09 2017
@Jc2k
Jc2k / connection.py
Last active March 19, 2020 17:27
homekit_controller fixes
#
# Copyright 2019 aiohomekit team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@Jc2k
Jc2k / connection.py
Last active March 24, 2020 17:12
Extra instrumentation
#
# Copyright 2019 aiohomekit team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@Jc2k
Jc2k / geoip.rb
Created March 3, 2021 12:55
Version of logstash-filter-geoip that reloads automatically
# In your Dockerfile:
# COPY geoip.rb /usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-filter-geoip-6.0.3-java/lib/logstash/filters/geoip.rb
# encoding: utf-8
require "logstash/filters/base"
require "logstash/namespace"
require "logstash-filter-geoip_jars"
# The GeoIP filter adds information about the geographical location of IP addresses,