Skip to content

Instantly share code, notes, and snippets.

View madprops's full-sized avatar

madprops madprops

View GitHub Profile
I have this in views.py
def connection_factory(auth_class, pubsub):
class GeneratedConnection(websocket_connection_factory(auth_class, pubsub)):
def open_connection(self):
log(self.authenticator)
return super(GeneratedConnection, self).open_connection()
def close_connection(self):
I have this in settings.py:
OMNIBUS_CONNECTION_FACTORY = 'server.views.connection_factory'
OMNIBUS_AUTHENTICATOR_FACTORY = 'omnibus.factories.userauthenticator_factory'
I have this in views.py
def connection_factory(auth_class, pubsub):
class GeneratedConnection(websocket_connection_factory(auth_class, pubsub)):
@madprops
madprops / matchmeta.py
Created October 24, 2017 13:01
Find files that match something in the metadata information and move them to another directory. Useful if you want to move a bunch of files from some artist without descriptive filenames but correct metadata
import os
import shutil
import subprocess
path = "/some/path"
destpath = "/some/other/path"
to_match = "Maybe an Artist name"
filenames = next(os.walk(path))[2]
@madprops
madprops / load_all.sh
Last active January 2, 2018 23:40
I use this script to make a smooth transition when new music has been added to my icecast radio. What it does is it first updates the database, crops the playlist, then add the new playlist, I have an audio file saying "the music database has been updated" , but I don't want it in the playlist, neither I want the current track appearing twice, s…
mpc --no-status --wait update &&
mpc --no-status crop &&
mpc --no-status add ''
mpc --no-status random on &&
mpc --no-status crossfade 10 &&
mpc --no-status consume on &&
mpc play &&
killall mpc
@madprops
madprops / gitcheck.sh
Last active December 3, 2018 19:01
Bash script to check if any of the git locations in a list have uncommitted changes and show output in a GUI alert box using gxmessage
#!/bin/bash
# Depends on the gxmessage package
# This is a script that will check all git repos in the location array
# Then it will check the output length of git diff
# If there's output in any of them it will show a red warning with their location
# If not it will show an "All good" message in green
# This is useful to keep various git repos in check with a simple command (or keypress if you map it)
@madprops
madprops / safeparse
Last active October 29, 2018 04:19
This function can be used to use html characters for tags (< and >) inside tags that you specify.
// For instance:
// If s = <code><code>This is a nested code that should be replaced</code> <div>Any tag here is replaced</div></code>
// safeparse(s, "code", "code") returns:
// <code>&lt;code&gt;This is a nested code that should be replaced&lt;/code&gt; &lt;div&gt;Any tag here is replaced&lt;/div&gt;</code>
// It should work for any number of correctly written nests.
// This will be applied to all specified top level tags.
// chars is the text to be parsed
// s1 is the starting tag
// s2 is the closing tag
@madprops
madprops / generate_favicon.js
Last active November 29, 2018 11:25
Function to generate colored squared favicons. A color is provided and it will make a square with that color with a black border of 2px. Then it will insert the favicon into the document.
generate_favicon = function(color)
{
let canvas = document.createElement("canvas")
canvas.height = 256
canvas.width = 256
let context = canvas.getContext("2d")
let center = canvas.height / 2
let side = 192
@madprops
madprops / remove-empty-lines.js
Created February 13, 2019 04:27
Extension that is "work in progress" because of a vscode bug
const vscode = require('vscode')
const cl_regex = new RegExp(/^\s*$/, "g")
function count_empty_lines()
{
let editor = vscode.window.activeTextEditor
if(!editor)
{
return false
@madprops
madprops / get_random_int.js
Created April 12, 2019 20:48
Random int with min, max, exclude, and seed options
get_random_int = function(args={})
{
let def_args =
{
min: 0,
max: 1,
exclude: false,
seed: Math.random
}
@madprops
madprops / wordz.js
Created April 14, 2019 16:50
Word list with helper functions
const Wordz = function()
{
const wordz = {}
wordz.words =
[
"aardvark", "abacus", "abbey", "abdomen", "ability", "abolishment", "abroad", "abuse",
"accelerant", "accelerator", "access", "accident", "accommodation", "accompanist", "accordion", "account",
"accountant", "achiever", "acid", "acknowledgment", "acoustic", "acoustics", "acrylic", "act",
"action", "activity", "actor", "actress", "acupuncture", "ad", "adapter", "addiction",