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 / 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 / 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 / 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 / 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);
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Component.extend({
isFabricsProd: false,
actions: {
toggleFabricsValue(i, j) {
console.log(i, j);
console.log('value now: ', this.get('isFabricsProd'));
this.toggleProperty('isFabricsProd');