Skip to content

Instantly share code, notes, and snippets.

@jspahrsummers
jspahrsummers / GHRunLoopWatchdog.h
Created January 28, 2015 20:50
A class for logging excessive blocking on the main thread
/// Observes a run loop to detect any stalling or blocking that occurs.
///
/// This class is thread-safe.
@interface GHRunLoopWatchdog : NSObject
/// Initializes the receiver to watch the specified run loop, using a default
/// stalling threshold.
- (id)initWithRunLoop:(CFRunLoopRef)runLoop;
/// Initializes the receiver to detect when the specified run loop blocks for
@zenparsing
zenparsing / dedent-template.js
Last active April 25, 2023 22:16
Dedenting Template Strings
function dedent(callSite, ...args) {
function format(str) {
let size = -1;
return str.replace(/\n(\s+)/g, (m, m1) => {
if (size < 0)
size = m1.replace(/\t/g, " ").length;
@slmcmahon
slmcmahon / UpdateManager.m
Last active January 22, 2019 02:28
Implementation file for UpdateManager - a tool for automating updates for AdHoc iOS apps.
//
// UpdateManager.m
// ReactiveLearning
//
// Created by Stephen L. McMahon on 8/4/13.
//
// interface: https://gist.github.com/slmcmahon/6152156
static NSString *const kPreferenceAskUpdate = @"pref_ask_update";
@slmcmahon
slmcmahon / UpdateManager.h
Last active January 22, 2019 02:28
Header file for UpdateManager - a tool for automating updates for AdHoc iOS apps.
//
// UpdateManager.h
// ReactiveLearning
//
// Created by Stephen L. McMahon on 8/4/13.
//
// implmementation: https://gist.github.com/slmcmahon/6152160
#import <Foundation/Foundation.h>
@abhinav-upadhyay
abhinav-upadhyay / DateTimeDecoder.py
Last active July 4, 2023 13:12
A JSON decoder/encoder implementation for parsing dates as datetime objects in Python
#!/usr/bin/env python
# An example of decoding/encoding datetime values in JSON data in Python.
# Code adapted from: http://broadcast.oreilly.com/2009/05/pymotw-json.html
# Copyright (c) 2023, Abhinav Upadhyay
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@olvado
olvado / getAverageColourAsRGB.js
Created June 27, 2011 10:19
Get the average colour of an image in javascript using getImageData in CANVAS
function getAverageColourAsRGB (img) {
var canvas = document.createElement('canvas'),
context = canvas.getContext && canvas.getContext('2d'),
rgb = {r:102,g:102,b:102}, // Set a base colour as a fallback for non-compliant browsers
pixelInterval = 5, // Rather than inspect every single pixel in the image inspect every 5th pixel
count = 0,
i = -4,
data, length;
// return the base colour for non-compliant browsers