Skip to content

Instantly share code, notes, and snippets.

//
// OGKeyPath.h
//
// Created by Jim on 3/11/10.
//
// Copyright (c) 2010 Jim Kang/Phalange Software.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
//
// OGColorTools.h
//
// Created by Jim on 1/25/10.
// Copyright (c) 2010 Jim Kang/Phalange Software.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
@jimkang
jimkang / UIVariableCellSizeGrid.cs
Created December 7, 2012 01:53
Subclass of NGUI's UIGrid that adds support for variable size cells. Update: Turns out it's mostly unnecessary; UITable does much of the same - DOH
using UnityEngine;
using System.Collections.Generic;
// This is a subclass of NGUI's UIGrid that supports cells of varying sizes,
// in addition to fixed sizes.
// http://ghostcrabworkshop.com
public class UIVariableCellSizeGrid : UIGrid
{
// If neither of these is set to true, spacing will be exactly as it
@jimkang
jimkang / ArrangeWidgetDepths.cs
Created December 15, 2012 19:02
Unity wizard script for projects using NGUI that lists all of the depths of all of the UIWidgets, arranged by UIPanel and atlas. You can then edit depths from it, but the idea is that it gives you a global sense of your widget/panel/atlas arrangement. Looks like this: http://cl.ly/image/3k3J2G0q1m1F
// ArrangeWidgetDepths.cs
// Ghost Crab Workshop
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
public class ArrangeWidgetDepths : ScriptableWizard
@jimkang
jimkang / tp_to_html.pl
Created January 3, 2013 03:45
TaskPaper to html conversion script. http://death-mountain.com/2010/05/taskpaper-to-html-conversion-script/ (Now handles emdashes.)
# Copyright (c) 2010 Jim Kang
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
@jimkang
jimkang / copyBoard.js
Created February 25, 2013 21:07
copyBoard method for Meteor with problems.
// The callback should take a error object and a boardId.
copyBoard: function(options) {
options = options || {};
if (!(typeof options.boardId === "string" && options.boardId.length)) {
throw new Meteor.Error(400, "Required parameter missing");
}
if (!options.callback) {
throw new Meteor.Error(400, "Required parameter missing");
}
if (! this.userId)
@jimkang
jimkang / todos.js
Last active December 16, 2015 03:19
Possible way of dealing with Meteor collections' insert() not calling the callback when offline. This is code modified from the todos example (http://meteor.com/examples/todos).
Template.todos.events(okCancelEvents(
'#new-todo',
{
ok: function (text, evt) {
function doAfterInsert(error, _id) {
console.log("I was counting on this _id:", _id);
}
var connected = Meteor.status().connected;
@jimkang
jimkang / README.md
Last active December 16, 2015 11:19 — forked from mbostock/.block

Click to add new points. Hit the DELETE key to remove the selected point. Use the dropdown menu to change the interpolation mode.

Updated from mbostock's original gist to allow editing the coordinates in text fields.

@jimkang
jimkang / prepareOptions.js
Last active December 16, 2015 16:09
A function that makes sure an options object has a certain set of expected properties. If properties are missing or of the wrong type, they are set to the default values defined in propInfoDict.
// propInfoDict should have prop names as the keys, then arrays
// as values that contain the expected type and the default value.
// options should be the options dictionary.
// Example:
// options = prepareOptions(options, {
// someDictionary: ['object', null],
// aFunction: ['function', function(datum) {
// return datum;
// }],
@jimkang
jimkang / treegetting.js
Created August 6, 2013 03:53
Given a database that you want to retrieve from with async calls, and records in it that represent nodes of a tree (each of which has a 'children' array with containing ids of other node records), here's a way to walk that tree with callbacks. Saving this in case I later decide I need this, after all.
var levelup = require('level');
var _ = require('underscore');
var TreeGetter = function TreeGetter(db, rootNodeId, childDepth, done) {
this.treeGetState = {
db: db,
nodesToGet: 0,
nodesGot: 0,
errors: [],
depthLimit: childDepth,