Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jmcd
jmcd / ArrayChunker.cs
Created March 10, 2014 12:37
Split array into chunks
public static class ArrayChunker<T>
{
public static T[][] Chunk(T[] sourceArray, int chunkLength)
{
var numberOfFullBuffers = sourceArray.Length/chunkLength;
var lengthOfRemainderBuffer = sourceArray.Length%chunkLength;
var hasRemander = lengthOfRemainderBuffer > 0;
var numberOfBuffers = numberOfFullBuffers +( hasRemander ? 1 : 0);
@jmcd
jmcd / filtered.js
Created July 16, 2014 11:26
jQuery plugin to filter tables/whatever
(function ($) {
$.fn.filtered = function (options) {
var roots = this;
var displayProperty = $(roots).first().css('display');
var elementContentArrays = [];
@jmcd
jmcd / mkappicons.swift
Created October 27, 2014 17:11
Create all the different sized iOS App Icons from a single source image
#!/usr/bin/xcrun swift
import Cocoa
import AppKit
import CoreGraphics
class Spec {
let pointSize: Int;
let scales: [Int]
@jmcd
jmcd / Dirty.cs
Last active August 29, 2015 14:14
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
namespace DIrtyWars
{
[TestFixture]
public class TestFixture
{
@jmcd
jmcd / v1.cs
Last active August 29, 2015 14:22
public class Counter
{
private readonly string directoryPath;
private int count = 0;
private static readonly object lockable = new object();
public const string AggregatedCountFilename = "agg_count.txt";
public const string PendingFileExt = "pnd";
@jmcd
jmcd / BcdCoderTests.java
Last active August 29, 2015 14:26
Simple BCD coder
public class BcdCoderTests extends InstrumentationTestCase {
private int[][] decimalAndBcd = new int[][]{
{0, 0},
{1, 1},
{2, 2},
{3, 3},
{4, 4},
{5, 5},
{6, 6},
@jmcd
jmcd / L.java
Last active August 29, 2015 14:26
Android Log Wrapper to: [1] automatically (and probably expensively) add class/method tracing to debug messages and [2] ability to hack in loggint to other places (e.g. a dirty log to a TextView)
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
public final class L {
public static final String MAGICAL_EXPENSIVE_AUTO_TAG = "JPgpKvpxrnB1zrs8WnGqVNTeK0NgMyY8SXnMEaXPnTY=";
public final static List<Println> PRINTLNS = new ArrayList<>();
private final static String[] NAMES_OF_EXCLUDED_CLASSES = new String[]{L.class.getName()};
import android.os.Handler;
import android.widget.TextView;
import timber.log.Timber;
public class TextViewTimberDebugTree extends Timber.DebugTree {
private final static long UNINITIALIZED_DEBUG_START_TIME = -1;
@jmcd
jmcd / FixedCapacityMovingBuffer.cs
Created August 19, 2011 11:08
A fixed capacity buffer that allows adding of items beyond the capacity by discarding earlier items. Adding is O(1), rather than O(N) because the internal representation is overwritten rather than actually moved.
public class FixedCapacityMovingBuffer<T>
{
private readonly int _capacity;
private readonly T[] _buffer;
private int _addCount;
public FixedCapacityMovingBuffer(int capacity)
{
_capacity = capacity;
@jmcd
jmcd / StreamExtensions.cs
Created October 12, 2011 10:37
An extension method to read to the end of a stream
using System;
using System.IO;
namespace jmcd
{
public static class StreamExtensions
{
public static byte[] ReadToEnd(this Stream stream)
{
var result = new byte[0];