Skip to content

Instantly share code, notes, and snippets.

@mohiji
mohiji / gist:4235524
Created December 7, 2012 18:57
Rebuilding a scene
/* This method gets called with the absolute root object for the whole scene. I then
add a few container objects to it.
_freeSceneRoot is a bog standard sprite that I just add child sprites to; I just move
it around in relation to where the current viewpoint is. Anything that's placed in the
game world is added to this (including the _sortedContainer below)
_sortedContainer is a customized sprite that sorts its children by their y-coordinate,
so things draw in the right order. (Things lower on the screen draw over things higher on
the screen)
@mohiji
mohiji / gist:4236599
Created December 7, 2012 21:16
Constructing a SPDisplayObject
/* My character class handles switching animation frames based on time, whether it's
walking, and what direction it's facing. When the time comes to render, it returns
an SPImage set up like this.
*/
@interface Character : NSObject
{
SPImage *_image; // Generic image sprite
NSMutableArray *_frames; // array of texture frames
int _facing; // North, south, east or west
@mohiji
mohiji / steinhart-test-results.txt
Last active December 13, 2015 23:29
Deriving Steinhart-Hart (http://en.wikipedia.org/wiki/Steinhart–Hart_equation) coefficients given a known thermistor response curve.
CL-USER> (test-steinhart-hart)
Steinhart-hart coefficients for the ACI/10K-CP curve are:
A: 0.0011212672
B: 2.3534849E-4
C: 8.3802405E-8
Resistance: 336450.0 Expected: -40.0 Calculated: -39.999985
Resistance: 242660.0 Expected: -35.0 Calculated: -35.009888
Resistance: 176960.0 Expected: -30.0 Calculated: -30.018707
Resistance: 130410.0 Expected: -25.0 Calculated: -25.02591
@mohiji
mohiji / iphone-template.lisp
Created July 6, 2013 01:46
Really basic demo of cl-pdf: in this case drawing boxes for doing 3.5" iPhone mockups.
;; iphone-template.lisp
;; Quicky code to generate an iPhone template for sketching out ideas.
;;
;; To use it, make sure you have cl-pdf available, e.g. (ql:quickload "cl-pdf"),
;; then just run (iphone-template:write-template "/path/to/output.pdf")
(require 'cl-pdf)
(defpackage :iphone-template
(:use :cl)
@mohiji
mohiji / dupe-detector.m
Created January 2, 2014 03:40
Got distracted while sorting photos and wrote a thing to help me find duplicate files.
//
// main.m
// dupe-detector
//
// Created by Jonathan Fischer on 1/1/14.
// Copyright (c) 2014 Jonathan Fischer. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CommonCrypto/CommonDigest.h>
@mohiji
mohiji / gist:11235244
Created April 23, 2014 22:50
Removes all non-important whitespace from a JSON file.
(require 'st-json)
(defun squish-json-file (filename)
(let ((parsed-json (with-open-file (stream filename)
(st-json:read-json stream))))
(with-open-file (stream (concatenate 'string filename ".squished")
:direction :output
:if-exists :supersede)
(st-json:write-json parsed-json stream))))
@mohiji
mohiji / gist:5d652540799ee9c74342
Created October 7, 2014 19:28
This confuses me. 127.0.0.1 works, localhost doesn't resolve?
solace:~ jfischer$ curl http://127.0.0.1:4000
Hi there.
solace:~ jfischer$ curl -v http://localhost:4000
* Rebuilt URL to: http://localhost:4000/
* Hostname was NOT found in DNS cache
* Trying ::1...
* connect to ::1 port 4000 failed: Connection refused
* Trying fe80::1...
* connect to fe80::1 port 4000 failed: Connection refused
@mohiji
mohiji / StateMachines.swift
Created July 30, 2015 16:22
GKStateMachine in Swift
//: Playground - noun: a place where people can play
import Cocoa
class State {
weak var stateMachine: StateMachine?
func isValidNextState(stateClass: AnyClass) -> Bool {
return true
}
@mohiji
mohiji / StateMachineTests.swift
Created March 4, 2016 21:10
GameplayKit style state machines in pure Swift
import XCTest
/********************************************
* The state graph used in these tests
*
* StateOne -----> StateTwo -----> State Three
* ^ | ^ |
* | | | |
* -------------| |----------------|
*
@mohiji
mohiji / Model.java
Created July 8, 2016 22:04
Really basic immutable models for Java/GWT.
import static com.google.common.base.Preconditions.checkNotNull;
public class ImmutableModel {
private final int id;
private final String label;
public ImmutableModel(int id, String label) {
this.id = id;
this.label = checkNotNull(label);
}