Skip to content

Instantly share code, notes, and snippets.

View DaveAtDog's full-sized avatar

Dave Lochhead DaveAtDog

View GitHub Profile
@DaveAtDog
DaveAtDog / positionObjectsOnSphereSurface.js
Last active June 9, 2016 14:26
My preferred way of positioning 3D objects on the surface of a sphere.
// Based on example C# code from http://forum.unity3d.com/threads/evenly-distributed-points-on-a-surface-of-a-sphere.26138/#post-2031195
// objects is an array of THREE.js 3D Objects
function positionObjectsOnSphereSurface(objects) {
var radius = 900;
var n = objects.length;
var inc = Math.PI * (3 - Math.sqrt(5));
var off = 2 / n;
var x = 0;
var y = 0;
var z = 0;
@DaveAtDog
DaveAtDog / map.js
Last active August 29, 2015 14:00
Match method to replicated the functionality of AS3’s Dictionary Class.
// Define our relationships
var map = {};
map[THING] = RELATED_THING;
// match method — searches for key and reurns value if not searches for value and returns key otherwise returns undefined.
var match = function(value)
{
if (map.hasOwnProperty(value))
{
return map[value];
@DaveAtDog
DaveAtDog / gulpfile.js
Last active August 29, 2015 14:00
Basic package.json and gulpfile.js for SASS compilation and live reload.
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
livereload = require('gulp-livereload'),
rename = require('gulp-rename'),
autoprefixer = require('gulp-autoprefixer');
var paths = {
styles: './css/demo.scss',
html: 'index.html'
};
@DaveAtDog
DaveAtDog / findKey.js
Last active September 21, 2018 08:49
JavaScript — Find key for value in an object
var findKey = function(obj, value)
{
var key = null;
for (var prop in obj)
{
if (obj.hasOwnProperty(prop))
{
if (obj[prop] === value)
{
@DaveAtDog
DaveAtDog / Xcode 5 - Build Number Increment
Created November 5, 2013 16:38
Auto-increments Build numbers. App (Top left) > Edit Scheme > Build > Pre-actions + Run New Script Action Provide build settings from *APP* Paste in script below. GOTCHA: Insure that your starting build number is set to a whole integer and not a float (e.g. 1, not 1.0)
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"
@DaveAtDog
DaveAtDog / DLog
Last active December 27, 2015 11:49
DLog - NSLog replacement - Stick in *-Prefix.pch file. Storing here for my own sanity.
#ifdef DEBUG
#define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define DLog(...)
#endif