Skip to content

Instantly share code, notes, and snippets.

View liftoff's full-sized avatar

Dan McDougall liftoff

View GitHub Profile
@liftoff
liftoff / json_cleaner.py
Created October 19, 2016 13:42
Allow comments and trailing commas in JSON files using two simple Python functions to clean them up before parsing
#!/usr/bin/env python
"""
An example of how to remove comments and trailing commas from JSON before
parsing. You only need the two functions below, `remove_comments()` and
`remove_trailing_commas()` to accomplish this. This script serves as an
example of how to use them but feel free to just copy & paste them into your
own code/projects. Usage::
json_cleaner.py some_file.json
@liftoff
liftoff / cleanup_json.py
Last active January 29, 2016 19:59
Clean up JSON-like data before decoding as JSON
import os, re, sys
comments_re = re.compile(
r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"',
re.DOTALL | re.MULTILINE
)
trailing_commas_re = re.compile(
r'(,)\s*}(?=([^"\\]*(\\.|"([^"\\]*\\.)*[^"\\]*"))*[^"]*$)')
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
* Copyright (C) 2011 Stephen Caudle <scaudle@doceme.com>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
@liftoff
liftoff / concurrent_futures_example.py
Created August 28, 2015 13:28
Example use of concurrent.futures
#!/usr/bin/env python
"""
Example of how to use futures with ProcessPoolExecutor or ThreadPoolExecutor.
"""
from concurrent import futures
def long_running_function():
"""
#!/usr/bin/python
# -*- coding: utf-8 -*-
from random import Random
=len
ج=int
=sum
ܠ=str
ܓ=range
ش=object
import sys
@liftoff
liftoff / shiftreg.py
Created November 21, 2014 02:07
Raspberry Pi Shift Register control module - It's super fast and can automatically invert the bits for you
#!/usr/bin/env python
"""
shiftreg.py
Shift register control module. Provides the :class:`Shiftter` class which
makes it easy to control shift registers.
.. note::
@liftoff
liftoff / mbi5026.ino
Last active April 23, 2024 07:08
Arduino with MBI5026 IC
// I pasted this without even looking at it. It the code running in the video here: http://youtu.be/OZ_9Yg0PG3M
// The video is of an Arduino controlling a single 8x8 LED matrix via an MBI5026 chip + a single 74HC595 shift register.
// Link to the MBI5026: http://www.rayslogic.com/propeller/programming/AdafruitRGB/MBI5026.pdf
#define SDI 10
#define CLK 9
#define LE 8
#define LED 17
// 74HC595
#define SHSDI 3 // DS (pin 14 on shift register)
@liftoff
liftoff / split_ca_cert.py
Created May 14, 2014 14:29
Split up and/or remove duplicate certificates from a PEM-formatted CA bundle (e.g. ca-bundle.crt)
#!/usr/bin/env python
"""
Split up and remove duplicate CA certificates from a bundle (e.g.
ca-bundle.crt).
.. note::
This script will preserve comments and certificate metadata at
the expense of possibly missing duplicates (that don't have the
@liftoff
liftoff / PeriodicTimerCallback
Created May 10, 2014 17:56
A simple periodic callback mechanism that uses the stdlib's threading.Timer
#!/usr/bin/env python3
"""
A periodic callback mechanism that uses `threading.Timer`.
"""
class PeriodicTimerCallback(object):
"""
A wrapper that uses either `threading.Timer` to call functions at a
@liftoff
liftoff / oclHashcat Benchmarks
Created April 14, 2014 13:26
Benchmarks of oclHashcat on my HTPC (single Radeon R7 265 w/1280 stream processors)
oclHashcat Benchmarks
System Info:
CPU: Intel(R) Core(TM) i5-4570S CPU @ 2.90GHz (quad core)
GPU: XFX Core Edition R7-265A-CNF4 Radeon R7 265 2GB (1280 stream processors)
NetNTLMv2 Benchmark first (since I consider it the most important)
------------------------------------------------------------------
$ ./oclHashcat64.bin -b --force -m5600