Skip to content

Instantly share code, notes, and snippets.

### JSTN
jstn.vt220.19200:\
:cb:ce:ck:lc:fd#1000:hw:ht:np:sp#19200:tt=vt220:im=\r\n . .o8 oooo\r\n .o8 "888 `888\r\n.o888oo oooo oooo ooo. .oo. .oo. 888oooo. 888 oooo d8b\r\n 888 `888 `888 `888P"Y88bP"Y88b d88' `88b 888 `888""8P\r\n 888 888 888 888 888 888 888 888 888 888\r\n 888 . 888 888 888 888 888 888 888 888 888 .o.\r\n "888" `V88V"V8P' o888o o888o o888o `Y8bod8P' o888o d888b Y8P\r\n\r\n\r\n%s %r %m (%t)\r\n%h\r\n\r\n:
###
@jstn
jstn / RandomNumbers.swift
Last active May 5, 2023 03:26
generate random numbers for 64-bit types while mitigating modulo bias
/*
`arc4random_uniform` is very useful but limited to `UInt32`.
This defines a generic version of `arc4random` for any type
expressible by an integer literal, and extends some numeric
types with a `random` method that mitigates for modulo bias
in the same manner as `arc4random`.
`lower` is inclusive and `upper` is exclusive, thus:
// JSTN / 10 June 2014
// I really like Swift so far, but I can't help be a little sad that I still find
// myself doing the weakSelf/strongSelf dance to avoid retain cycles.
// For a contrived example, suppose we had a class like this with a queue:
import Foundation
class ParallelMessenger {
@jstn
jstn / gist:5451843
Last active December 16, 2015 14:49
frame rate of a QTMovie
- (NSTimeInterval)frameRateForMovie:(QTMovie *)movie
{
for (QTTrack *track in [movie tracks]) {
QTMedia *media = [track media];
if (![media hasCharacteristic:QTMediaCharacteristicHasVideoFrameRate])
continue;
QTTime duration = [(NSValue *)[media attributeForKey:QTMediaDurationAttribute] QTTimeValue];
long sampleCount = [(NSNumber *)[media attributeForKey:QTMediaSampleCountAttribute] longValue];
return sampleCount * ((NSTimeInterval)duration.timeScale / (NSTimeInterval)duration.timeValue);
}
@jstn
jstn / JXBezier.c
Last active December 13, 2015 17:19
iOS tweening, adapted from Webkit
#include "JXBezier.h"
#include <math.h>
JXUnitBezier JXUnitBezierMake(double p1x, double p1y, double p2x, double p2y) {
JXUnitBezier bezier;
bezier.cx = 3.0 * p1x;
bezier.bx = 3.0 * (p2x - p1x) - bezier.cx;
bezier.ax = 1.0 - bezier.cx - bezier.bx;
bezier.cy = 3.0 * p1y;
bezier.by = 3.0 * (p2y - p1y) - bezier.cy;
@jstn
jstn / JSTN.dvtcolortheme
Created February 2, 2013 17:19
xcode theme / variation on "Dusk"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>1 1 1 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>Monaco - 12.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>1 1 1 1</string>
@jstn
jstn / JSTN.css
Last active March 1, 2021 02:28
limechat theme
/*
JSTN THEME FOR LIMECHAT 1.0
put this and the other thing in ~/Library/Application Support/LimeChat/Themes/
bg 1a2230
hlight 273146
red e44347
purps 8b84d0
fuscia c2339a
@jstn
jstn / howisobamadoing.rb
Created September 29, 2012 21:07
howisobamadoing.com / howisromneydoing.com
# howisobamadoing.com / howisromneydoing.com
# (c) justinouellette.com MMXII
require 'rubygems'
require 'sinatra'
CACHE_TIME = 3600 # one hour
OBAMA_DATA_PATH = 'obama.txt'
ROMNEY_DATA_PATH = 'romney.txt'
@jstn
jstn / pixelbytes.m
Created July 19, 2012 02:33
Read an image off disk and iterate through its pixel data byte by byte using Core Graphics
NSString *imagePath = @"/tmp/test.jpg";
CGDataProviderRef imageDataProvider = CGDataProviderCreateWithFilename([imagePath UTF8String]);
CGImageRef image = CGImageCreateWithJPEGDataProvider(imageDataProvider, NULL, false, kCGRenderingIntentDefault);
CGDataProviderRelease(imageDataProvider);
size_t bytesPerPixel = 4;
size_t bitsPerComponent = 8;
size_t imageWidth = CGImageGetWidth(image);
size_t imageHeight = CGImageGetHeight(image);
<!--
scaling background, as seen on normative.com
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Scaling Background</title>
<meta name="warning" content="HC SVNT DRACONES" />
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.6.0/build/reset/reset-min.css" />