Skip to content

Instantly share code, notes, and snippets.

@zackthehuman
zackthehuman / gist:1677420
Created January 25, 2012 17:21
Locale-based short date formatting
var getShortDateFormat = (function() {
var pattern = undefined,
defaultPattern = "M/d/yyyy",
localeFormatMappings = {
"en-us": "M/d/yyyy",
"ja-jp": "yyyy\u5E74 M\u6708 d\u65E5"
};
return function(date, locale) {
var m, d, y;
@zackthehuman
zackthehuman / gist:1702978
Created January 30, 2012 06:59
SharePoint 2010 "Personal Actions"-like menu markup
<div class="ms-MenuUIPopupBody ms-MenuUIPopupScreen" style="position:absolute;">
<div class="ms-MenuUIPopupInner" style="overflow-x: visible; overflow-y: visible; ">
<div class="ms-MenuUILarge">
<ul class="ms-MenuUIUL">
<li class="ms-MenuUIULItem">
<div class="ms-MenuUIULItem">
<a class="ms-MenuUIULLink">
<span class="ms-MenuUIIconLarge" style="white-space: nowrap;">
<img class="ms-MenuUIULImg" width="32" height="32" src="/_layouts/images/blank.gif" alt="" title="" />
@zackthehuman
zackthehuman / hexagons.js
Created February 20, 2012 03:46
Drawing a hexagonal grid with HTML canvas
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Canvas Hexagonal Map</title>
<style type="text/css">
canvas {
border:0;
display:block;
margin:0 auto;
@zackthehuman
zackthehuman / fibs.js
Created March 29, 2012 06:03
Fibonacci using recursion and iteration
// These functions assume that fib(0) = 0, fib(1) = 1
// In other words, 0 and 1 are the seeds of the sequence.
function recursiveFib(n) {
if(n < 0) {
throw "Negative numbers are not allowed.";
}
if(n < 2) {
return n;
@zackthehuman
zackthehuman / cycle.frag
Created November 11, 2012 10:02
Color/palette cycling using GLSL (example in SFML)
uniform sampler2D texture;
uniform sampler2D colorTable;
uniform float paletteIndex;
void main()
{
vec2 pos = gl_TexCoord[0].xy;
vec4 color = texture2D(texture, pos);
vec2 index = vec2(color.r + paletteIndex, 0);
vec4 indexedColor = texture2D(colorTable, index);
@zackthehuman
zackthehuman / gist:5762171
Created June 12, 2013 00:59
JavaScript object difference using Underscore
var objectA = { a: '1a', b: '1b', c: '1c' };
var objectB = { a: '2a', b: '2b', d: '2d' };
function objectDifference(minuend, subtrahend) {
var firstIntersection = _.omit(minuend, _.keys(subtrahend)),
secondIntersection = _.omit(subtrahend, _.keys(minuend));
return _.extend(firstIntersection, secondIntersection);
}
@zackthehuman
zackthehuman / QuadTree.scala
Created June 9, 2014 13:32
Working generic quadtree written in Scala
case class Identifier(id: Long)
case class Rectangle(x: Int, y: Int, width: Int, height: Int)
object QuadTree {
private val MAX_OBJECTS = 2
private val MAX_LEVELS = 5
private val PARENT_NODE = -1
private val TOP_RIGHT = 0
private val TOP_LEFT = 1
@zackthehuman
zackthehuman / bit.cpp
Created December 17, 2015 23:47
bit function constexpr
#include <iostream>
constexpr auto bit(std::size_t index) {
return 1ULL << index;
}
int main() {
std::cout << bit(0) << "\n" << bit(1) << "\n" << bit(5) << std::endl;
return 0;
}
@zackthehuman
zackthehuman / application.controller.js
Last active March 21, 2016 18:18
limiting properties
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
queryParams: {
'number': '_number'
},
_number: 1,
totalPages: 5,
number: Ember.computed('_number', {
@zackthehuman
zackthehuman / rot.js
Created April 4, 2016 16:50
JavaScript 2D array rotations
var arr1 = [
['1', '2', '3', '4'],
['5', '6', '7', '8'],
['9', 'a', 'b', 'c'],
['d', 'e', 'f', 'g'],
];
function rotCCW(arr) {
var n = arr.length;
var ret = new Array(n);