Skip to content

Instantly share code, notes, and snippets.

@groves
groves / copy_layer.py
Last active January 11, 2022 15:49
Scripts to tweak Keyboardio Chrysalis exported JSON keymaps
import json
import sys
def usage():
print("python copy_layer.py <source layout JSON file> <destination layout JSON file> <copy from layer index> <copy to layer index>")
sys.exit(1)
if len(sys.argv) != 5:
usage()
@groves
groves / GraphiteReporter.java
Created January 25, 2016 00:17
GraphiteReporter with configurable reported values
import com.codahale.metrics.Clock;
import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Histogram;
import com.codahale.metrics.Meter;
import com.codahale.metrics.Metered;
import com.codahale.metrics.MetricFilter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.ScheduledReporter;
import com.codahale.metrics.Snapshot;
public void testSkip() throws Exception {
File test = File.createTempFile("blah", "blah");
FileOutputStream out = new FileOutputStream(test);
out.getChannel().position(1024);
out.write(new byte[]{1, 2, 3, 4, 5, 6});
out.getChannel().position(512);
out.write(new byte[]{6, 5, 4, 3, 2, 1});
out.close();
FileInputStream in = new FileInputStream(test);
System.err.println("Initial " + TestUtil.toHex(StreamUtil.readBytes(in, 6)));
@groves
groves / gist:1368318
Created November 15, 2011 20:56
SPPoint pooling vs arc
#import <mach/mach_time.h>
void logMachTime_withIdentifier_(uint64_t machTime, NSString *identifier) {
static double timeScaleSeconds = 0.0;
if (timeScaleSeconds == 0.0) {
mach_timebase_info_data_t timebaseInfo;
if (mach_timebase_info(&timebaseInfo) == KERN_SUCCESS) { // returns scale factor for ns
double timeScaleMicroSeconds = ((double) timebaseInfo.numer / (double) timebaseInfo.denom) / 1000;
timeScaleSeconds = timeScaleMicroSeconds / 1000000;
}
}
@groves
groves / add_to_itunes.py
Created November 20, 2010 23:41
Transcodes shows downloaded with sickbeard into a format usable on iOS and AppleTV with HandBrakeCLI and fills in their metadata with AtomicParsley
#!/usr/bin/env python
import os, re, subprocess, sys
from xml.etree import ElementTree
retag = sys.argv[1] == "retag"
if retag:
del sys.argv[1]
source = os.path.abspath(sys.argv[1])
extensionless = '.'.join(source.split('.')[:-1])
@groves
groves / install_homebrew.rb
Created April 11, 2010 21:01 — forked from mxcl/install_homebrew.markdown
Recursively chowns and chgrps
#!/usr/bin/ruby
#
# I deliberately didn't DRY /usr/local references into a variable as this
# script will not "just work" if you change the destination directory. However
# please feel free to fork it and make that possible.
#
# If you do fork, please ensure you add a comment here that explains what the
# changes are intended to do and how well you tested them.
#
# 11th April 2010:
var data = [{
"color": "#92BA34",
"data": [[1251331200000, 15.0]]
},
{
"color": "#92BA34",
"data": [[1251417600000, 20.0]]
},
{
"color": "#3492BA",
@groves
groves / gist:177698
Created August 29, 2009 22:10
JUnit happily runs a clamp class from ant
from junit.framework import TestCase
from clamp import Clamp, java, jvoid
class TestJUnit(Clamp, TestCase):
@java(jvoid)
def testAddition(self):
self.assertEquals(4, 1 + 3)