Skip to content

Instantly share code, notes, and snippets.

@orientalperil
orientalperil / test_unmanaged_models.md
Created November 1, 2023 00:04 — forked from raprasad/test_unmanaged_models.md
Ignoring migrations during Django testing (unmanaged databases, legacy databases, etc)

Scenario

  • Django 1.9 application with two databases:
    • Legacy database with readonly access via unmanaged models. Both Django models (models.py) and related migrations have "managed" set to False
      • 'managed': False
    • Default database holding django specific tables (e.g. auth_user, django_content_type, etc)

Testing Woes

@orientalperil
orientalperil / multipartify.py
Created April 16, 2021 15:39 — forked from kazqvaizer/multipartify.py
Python dict to multipart/form-data converter to use it requests
"""
Here is a way to flatten python dictionaries for making multipart/form-data POST requests.
{"some": ["balls", "toys"], "field": "value", "nested": {"objects": "here"}}
->
{"some[0]": "balls", "some[1]": "toys", "field": "value", "nested[objects]": "here"}
@orientalperil
orientalperil / global-protect.sh
Last active April 11, 2021 05:43 — forked from kaleksandrov/global-protect.sh
Simple script that starts and stops GlobalProtect.app on Mac OSX.
#!/bin/bash
case $# in
0)
echo "Usage: $0 {start|stop}"
exit 1
;;
1)
case $1 in
start)
var convertStringToSeconds = function (s) {
var array = s.split(':');
array = array.map(function(x){return parseInt(x);});
var hours;
var minutes;
var seconds;
if (array.length === 2) {
hours = 0;
minutes = array[0];
seconds = array[1];
@orientalperil
orientalperil / gist:8c1abc94204053f23f849e63cef50fce
Created May 7, 2018 21:18
Convert ES6 string formatting to sprintf()
def find_string_formatting(text):
first = text.find('`')
second = text.find('`', first+1)
match = text[first:second+1]
match = match[1:len(match)-1]
vars = []
format_string = match
while '${' in format_string:
var = find_var(format_string)
vars.append(var)
@orientalperil
orientalperil / sssl.js
Last active September 20, 2015 03:27 — forked from aFarkas/sssl.js
simple, small script loader
/*!
* SSSL: smallest, simpelst script loader
* version: 1.0.1
*
* API:
* Normal usage
* sssl(source [,complete]);
*
* Example:
* sssl('jquery.js', function(){
@orientalperil
orientalperil / template_graph.py
Created December 10, 2014 18:15
Create Graphviz diagrams of Django templates
import os
import functools
import fnmatch
import re
import collections
import pydot
def Walk(root='.', recurse=True, *patterns):
"""
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite

TMUX - Single window group, multiple session.

So I have been using tmux for a while and have grown to like it and have since added many many customizations to it. Now once you start getting the hang of it, you'll naturally want to do more with the tool.

Now tmux has a concept of window-group and session and if you are like me you'll want multiple session that connects to the same window group instead of a new window group every time. Basically I just need different views into the same set of windows that I have already created, I don't want to create a new set of windows every time I fire up my terminal.

This is the default case if you simply use the tmux command as your login shell, effectively creating a new group of windows every time you start tmux.

This is less than ideal because, if you are like me, you fire up one-off terminals all the time and you don't want all those one-off jobs to stay running in the background. Plus sometimes you need information fro