Skip to content

Instantly share code, notes, and snippets.

@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)
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 / 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)
@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 / 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