Skip to content

Instantly share code, notes, and snippets.

View mohiji's full-sized avatar

Jonathan Fischer mohiji

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / texture-generators.lisp
Created December 4, 2012 18:19
Using a cond in a let form makes me feel a little greasy
(defvar *grass-base-color* (list 64 137 44))
(defvar *grass-medium-color* (mapcar (lambda (x) (round (* x 0.9))) *grass-base-color*))
(defvar *grass-dark-color* (mapcar (lambda (x) (round (* x 0.8))) *grass-base-color*))
(defun generate-grass-texture2 (file width height)
(let* ((png (make-instance 'zpng:png
:color-type :truecolor-alpha
:width width
:height height))
(image (zpng:data-array png)))
@mohiji
mohiji / TextureAtlas.h
Created August 11, 2012 04:56
My texture atlas tool and sample code
//
// TextureAtlas.h
//
// Created by Jonathan Fischer on 8/10/12.
// Copyright (c) 2012 Jonathan Fischer. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface AtlasFrame : NSObject
@mohiji
mohiji / gist:3086990
Created July 10, 2012 23:45
Handy Common Lisp + cl-pdf Snippet
(pdf:with-document ()
(pdf:with-page (:bounds pdf:*letter-portrait-page-bounds*)
(let ((width (elt pdf:*letter-portrait-page-bounds* 2))
(height (elt pdf:*letter-portrait-page-bounds* 3))
(helvetica (make-instance 'pdf:font)))
(loop for y from 20 to height by 20 do
(pdf:move-to 0 y)
(pdf:line-to width y))
(loop for x from 20 to width by 20 do
@mohiji
mohiji / gist:2784905
Created May 24, 2012 23:42
Player character classes make things sound kind of silly.
_stationaryMaria = [[Maria alloc] init];
_stationaryMaria.x = 7.0f * 24.0f;
_stationaryMaria.y = 5.0f * 24.0f;
@mohiji
mohiji / CollisionMap.h
Created April 17, 2012 21:14
A* Implementation
//
// CollisionMap.h
// MazeGame
//
// Created by Jonathan Fischer on 2/25/12.
//
#import <Foundation/Foundation.h>
#include "MapCommon.h"
@class Path;