Skip to content

Instantly share code, notes, and snippets.

@jaydg
jaydg / logging.py
Created July 27, 2018 20:21
django-jinja logging helpers
from django_jinja import library
import logging as log
@library.filter
def debug(msg, *args):
"""
Usage: {{ 'Hello %s' | debug('world') }}
"""
log.debug(msg, *args)
@jaydg
jaydg / spec_32.d
Created May 28, 2018 15:41
Port of the ZeroMQ Z85 binary-to-text encoding reference implementation to D. See https://rfc.zeromq.org/spec:32/Z85
// --------------------------------------------------------------------------
// Reference implementation for rfc.zeromq.org/spec:32/Z85
//
// This implementation provides a Z85 codec as an easy-to-reuse C class
// designed to be easy to port into other languages.
// --------------------------------------------------------------------------
// Copyright (c) 2010-2013 iMatix Corporation and Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a
@jaydg
jaydg / astar.d
Last active March 18, 2018 02:01
Translation of https://rosettacode.org/wiki/A*_search_algorithm (C++ variant) to D
import std.algorithm.searching : find;
import std.container : DList;
import std.format : format;
import std.range :take;
import std.stdio;
class Point {
public:
int x, y;
@jaydg
jaydg / struct_member_map.d
Created March 4, 2018 12:41
Using std.algorithm.iteration.map to retrieve an attribute from each member struct of an array
import std.algorithm.iteration : map;
struct Foo {
int id;
string text;
private static Foo[] foos = [
{ 0, "Blah" },
{ 1, "Text" },
{ 2, "Moar Text" },
@jaydg
jaydg / hex2rgb.d
Last active June 10, 2018 20:00
Hex <-> RGB color conversion
module hex2rgb;
struct RGB {
ubyte r;
ubyte g;
ubyte b;
public this(ubyte r, ubyte g, ubyte b) {
this.r = r;
this.g = g;
@jaydg
jaydg / fr.ksh
Last active March 5, 2018 23:01
Rename multiple files at once (ksh88 and newer)
#!/bin/ksh
#
# Copyright (c) 2010,2011,2012 Joachim de Groot <jdegroot@web.de>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@jaydg
jaydg / convert.py
Last active March 26, 2024 19:06
Convert Google Contacts CSV export to Grandstream's dubious XML file format
#!/usr/bin/env python3
import csv
import re
import sys
from xml.dom.minidom import getDOMImplementation
contacts = []
# strip unwanted characters from strings