Skip to content

Instantly share code, notes, and snippets.

View sr105's full-sized avatar

Harvey Chapman sr105

View GitHub Profile
@sr105
sr105 / column.py
Created February 12, 2017 03:38
Re-implement `column -t filename` using python and centering the columns.
#!/usr/bin/env python3
import sys
import itertools
def three_passes_and_storage():
# Read file and split each line into fields (by whitespace)
with open(sys.argv[1]) as f:
lines = [line.split() for line in f.readlines()]
# Check that each line has the same number of fields
@sr105
sr105 / count_24_bits.py
Created February 6, 2017 19:03
count in bits manually
def test(counter=[0], bits=[], stop=24):
if len(bits) == stop:
print(*bits, ' ', counter[0])
counter[0] += 1
return
bits.append(0)
test(counter, bits)
bits[-1] = 1
test(counter, bits)
bits.pop()
@sr105
sr105 / gist:8c9873420c855f0bd0cf
Created December 11, 2015 22:33
gsc wd disabled by power off
###########################################################################
###########################################################################
###########################################################################
U-Boot SPL 2015.04-g85edf72 (Nov 30 2015 - 09:12:48)
Booting from NAND
PMIC: LTC3676
NAND : 256 MiB
*** Warning - bad CRC, using default environment
@sr105
sr105 / nth.py
Last active November 20, 2015 14:24
Answer for [Can I yield from an instance method](http://stackoverflow.com/q/33818422/47078)
from itertools import izip, islice
import random
def sumdiff(data):
return ((x + y, x - y) for x, y in data)
def combined_file_data(files):
for i,n in files:
# Generate some data.
x = range(n)
@sr105
sr105 / garmin_split.py
Last active November 20, 2015 15:23
Splits a GPX file with pauses in the track into multiple files.
#!/usr/bin/env python
# Copyright (C) 2015 Harvey Chapman <hchapman@3gfp.com>
# Public Domain
# Use at your own risk.
"""
Splits a gpx file with breaks in the track into separate files.
Based on: http://stackoverflow.com/q/33803614/47078
@sr105
sr105 / gist:d659bbf23a3582956e86
Created August 19, 2015 15:47
Example ffmpeg conversion
silver:2015 June hchapman$ ffmpeg -i BeerDemo_h264_aac.mp4 -c:v h264 -an OUTPUT.mp4
ffmpeg version 2.7.1 Copyright (c) 2000-2015 the FFmpeg developers
built with Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.7.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-libcaca --enable-vda
libavutil 54. 27.100 / 54. 27.100
libavcodec 56. 41.100 / 56. 41.100
libavformat 56. 36.100 / 56. 36.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libavresample 2. 1. 0 / 2. 1. 0
<6>[ 16.348681] sd 0:0:0:0: [sda] Unhandled sense code
<6>[ 16.353485] sd 0:0:0:0: [sda]
<4>[ 16.356629] Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
<6>[ 16.362206] sd 0:0:0:0: [sda]
<4>[ 16.365349] Sense Key : Medium Error [current]
<6>[ 16.369911] sd 0:0:0:0: [sda]
<4>[ 16.373057] Add. Sense: Unrecovered read error
<6>[ 16.377516] sd 0:0:0:0: [sda] CDB:
<4>[ 16.381006] Read(10): 28 00 00 05 57 09 00 00 f0 00
<3>[ 16.386050] end_request: critical target error, dev sda, sector 349961
@sr105
sr105 / gist:e9bbf4e4865902149f69
Created June 5, 2015 15:46
U-Boot read an I2C register into an environment variable
#### Demo Commands
mw.b ${loadaddr} 0 10
md.b ${loadaddr} 10
i2c bus 0
i2c read 0x51 0xDF.1 1 $loadaddr
md.b ${loadaddr} 10
setexpr.b recovery *$loadaddr
echo $recovery
mm ()
{
if [ -f build/core/envsetup.mk -a -f Makefile ]; then
make $@;
else
T=$(gettop);
local M=$(findmakefile);
local MODULES=;
local GET_INSTALL_PATH=;
local ARGS=;
@sr105
sr105 / UsbStorageDevice.java
Created March 6, 2015 15:42
Class that discovers USB mass storage devices on Android. See getAll() as a starting point.
package com.rdm.storagetests;
import com.rdm.storagetests.StorageHelper.StorageVolume;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;