Skip to content

Instantly share code, notes, and snippets.

View bossjones's full-sized avatar
💭
Learning every damn thing I can

Malcolm Jones (bossjones/Tony Dark) bossjones

💭
Learning every damn thing I can
View GitHub Profile
@bossjones
bossjones / async.py
Created May 15, 2024 14:28 — forked from iedmrc/async.py
Python turn sync functions to async (and async to sync)
import functools
import asyncio
from concurrent.futures import ThreadPoolExecutor
def to_async(func):
"""Turns a sync function to async function using event loop"""
@functools.wraps(func)
async def run(*args, loop=None, executor=None, **kwargs):
if loop is None:
@bossjones
bossjones / .direnvrc
Created December 13, 2021 14:18 — forked from ZhangChen199102/.direnvrc
Setup direnv + pyenv + pyenv-virtualenv
# use a certain pyenv version
use_python() {
if [ -n "$(which pyenv)" ]; then
local pyversion=$1
pyenv local ${pyversion}
fi
}
layout_virtualenv() {
local pyversion=$1
// Open all links on a page in new tab -- for MBW
// Requires ECMAScript 6's `Set()` for getting unique urls
// I'm too lazy to write a `uniq` function nor do I want to pull in a 3rd party lib
// Works in Firefox 25+, Chrome 38+, Opera 25+, Safari 7.1+, Internet Explorer 11+
Set(
Array.prototype.filter.call(document.querySelectorAll('[href]'), function(el) {
return el.tagName.toLowerCase() !== 'link' && el.href[0] !== '#'
}).map(function(el) {
return el.href
})
@bossjones
bossjones / tmux-all-panes.sh
Created August 6, 2021 17:09 — forked from acdvorak/tmux-all-panes.sh
tmux: run a command in all panes
#!/bin/bash
# Runs the specified command (provided by the first argument) in all tmux panes
# in every window. If an application is currently running in a given pane
# (e.g., vim), it is suspended and then resumed so the command can be run.
all-panes()
{
all-panes-bg_ "$1" &
}
#!/usr/bin/python
# Credit to frogor for the objc
from Foundation import NSBundle
import json
import objc
import os
import plistlib
import subprocess
@bossjones
bossjones / to_filename.py
Created March 22, 2021 16:42 — forked from wassname/to_filename.py
python convert string to safe filename
"""
Url: https://gist.github.com/wassname/1393c4a57cfcbf03641dbc31886123b8
"""
import unicodedata
import string
valid_filename_chars = "-_.() %s%s" % (string.ascii_letters, string.digits)
char_limit = 255
def clean_filename(filename, whitelist=valid_filename_chars, replace=' '):
@bossjones
bossjones / conftest.py
Created January 21, 2020 22:39 — forked from rcoup/conftest.py
Click CliRunner with PDB working better under pytest
import contextlib
import io
import warnings
import pytest
from click.testing import CliRunner
"""
In your tests:
@bossjones
bossjones / Twitter.plist
Created November 21, 2019 00:44 — forked from MattieTK/Twitter.plist
Twitter video handbrake settings
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist>
<array>
<dict>
<key>AudioList</key>
<array>
<dict>
<key>AudioBitrate</key>
<string>128</string>
@bossjones
bossjones / git-track
Created July 14, 2019 01:01 — forked from graysky/git-track
Auto-track a git branch
#!/bin/sh
# Sets up auto-tracking of a remote branch with same base name.
# Can set up "git track" so it feels built-in:
# git config --global --add alias.track '!git-track'
#
branch=$(git branch 2>/dev/null | grep ^\*)
[ x$1 != x ] && tracking=$1 || tracking=${branch/* /}
git config branch.$tracking.remote origin
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import boto3
SCRIPT_RUNNER_JAR = 's3://us-east-1.elasticmapreduce/libs/script-runner/script-runner.jar'
BASE_ARGS_HIVE_STEP = [
'/usr/share/aws/emr/scripts/hive-script',
'--run-hive-script',
'--args',