Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
#
# Adam Sharp
# Aug 21, 2013
#
# Usage: Add it to your PATH and `git remove-submodule path/to/submodule`.
#
# Does the inverse of `git submodule add`:
# 1) `deinit` the submodule
# 2) Remove the submodule from the index and working directory
import ctypes as c
import string
import logging; log = logging.getLogger(__name__)
# ...
def dump(obj, logger=log.info):
# assert isinstance(obj, c.C_TYPE)
B = []
C = []
offset = 0
@jn0
jn0 / fs.py
Last active September 12, 2018 13:08
Handy wrapper to [sys/proc] filesystem
#!/usr/bin/python
import os
import errno
AUTO_EXPAND_USER = True
def RootFS(root='/'): return FS(root)
def SysFS(root='/sys'): return FS(root)
def ProcFS(root='/proc'): return FS(root)
@jn0
jn0 / bin2c.py
Last active October 25, 2018 12:51
My (failed) attempt to use Python driven C++ powered TensorRT application on Jetson
#!/usr/bin/python
import sys
CHUNK_SIZE = 1024
LINE_LENGTH = 16
if __name__ == '__main__':
if len(sys.argv) < 3:
print('Usage: ' + sys.argv[0] + ' ${input_name} ${output_name} < ${bin_file} > ${c_file}')
@jn0
jn0 / OrderedJson.py
Created November 26, 2018 12:15
Ordered JSON dictionary
'''
Supplemental thing for better handling of json.load() results.
I.e. keep it ordered.
'''
from collections import OrderedDict
import json
class OrderedJson(OrderedDict):
@jn0
jn0 / pelco_d.py
Created November 27, 2018 09:05
PELCO-D Protocol
# -*- coding: utf-8 -*-
'''The Pelco-D Protocol
Standard Number TF-0002
Version 2 Revision 1 Release Date August 15, 2003
Transmitters will format a single character and receivers will be able to
decipher a single character as: 1 start bit, 8 data bits, 1 stop bit,
and no parity.
@jn0
jn0 / setup.py
Created December 18, 2018 13:57
pypylon-1.3.1 setup script abruptly hacked for MacOS 10.14
#!/usr/bin/env python
from __future__ import print_function
from setuptools import setup, Extension
from distutils import spawn
from distutils.util import get_platform
from distutils.version import LooseVersion
from logging import info, warning, error
import argparse
import ctypes
@jn0
jn0 / macos_lsusb.py
Created December 20, 2018 09:30
sorta lsusb for MacOS
#!/usr/bin/env python3
'''
lsusb for MacOS after https://github.com/jlhonora/lsusb
MacBook-Pro-apple-2:~ jno$ system_profiler SPUSBDataType
2018-12-19 15:14:49.583 system_profiler[96589:1580584] SPUSBDevice: IOCreatePlugInInterfaceForService failed 0xe00002be
USB:
USB 3.0 Bus:
@jn0
jn0 / jnx.py
Last active September 17, 2021 11:46
Sample JNX parser
#!/usr/bin/env python3
'''
Garmin JNX as of http://whiter.brinkster.net/JNX.shtml
'''
import logging; log = logging.getLogger('JNX' if __name__ == '__main__' else __name__)
import sys
import os
import struct
import json
#!/usr/bin/env python3
'''
After https://gist.github.com/jn0/7739995c5b7da04183ffc7ebfe65ff35 script
we have a whole bunch of JPEG tiles and this JSON:
{
"header": {
"signature_offset": 0,
"coordinates": {
"sw_lon": 36.36583659628678,