Skip to content

Instantly share code, notes, and snippets.

@lamchau
lamchau / ember-component-fadeout.js
Created August 17, 2015 19:53
`fadeIn` and `fadeOut` for Ember Component (ES6; ember-cli)
export default Ember.Component.extend({
fadeDurationInMilliseconds: 300,
didInsertElement() {
let duration = this.get("fadeDurationInMilliseconds"),
element = this.$();
element.fadeIn(duration);
},
@lamchau
lamchau / bypass-click-shield.js
Last active October 25, 2015 22:24
bookmarklet to bypass instagram's click shield
if (window.location.host === "instagram.com" && window.location.pathname.startsWith("/p/")) {
var images = document.querySelectorAll(".-cx-PRIVATE-Photo__image");
var length = images.length;
if (length) {
var element = images[length - 1];
if (element.src) {
window.location.href = element.src;
}
}
}
@lamchau
lamchau / Program.java
Created September 11, 2015 06:31
TimeUnit gcd
package com.lchau;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class Program {
public static void main(String[] args) {
@lamchau
lamchau / time-unit-oracle-test.js
Created September 13, 2015 03:49
test dependencies: lodash and qunit (not by choice)
/*
* This file is a ported version of
* http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/test/jtreg/util/concurrent/TimeUnit/Basic.java?view=co
* which contained the following header:
*/
/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
(function(Factory, Lorem, underscore) {
var SHA_CHARS = "0123456789abcdef";
var ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var CATEGORIES = ["Low", "Medium", "High"];
var ONE_YEAR_IN_MILLISECONDS = 31536000000;
var _ = underscore;
var methods;
// http://www.ssa.gov/oact/babynames/decades/century.html
var FIRST_NAME = ["James", "John", "Robert", "Michael", "William", "David", "Richard", "Joseph", "Charles", "Thomas", "Christopher", "Daniel", "Matthew", "Donald", "Anthony", "Mark", "Paul", "Steven", "George", "Kenneth", "Mary", "Patricia", "Jennifer", "Elizabeth", "Linda", "Barbara", "Susan", "Margaret", "Jessica", "Sarah", "Dorothy", "Karen", "Nancy", "Betty", "Lisa", "Sandra", "Ashley", "Kimberly", "Donna", "Helen"];
// https://en.wikipedia.org/wiki/List_of_most_common_surnames_in_North_America
function findBalancePoint(array) {
if (array.length === 0) {
return 0;
}
if (array.length === 1) {
return 1;
}
// initial sums
var left = 0;
var right = 0;
function getPath(object, path) {
if (typeof object === 'undefined' || typeof path !== 'string') {
return undefined;
}
var index = path.trim().indexOf('.');
if (index < 0) {
return object[path];
}
function Stats(data, precision) {
var PRECISION = precision || 2;
var length = data.length;
var mean = (function() {
var sum = data.reduce(function(a, b) {
return a + b;
}, 0);
return sum / length;
})();
// a1Foo => a1_foo
function getRange(start, end) {
return [start.charCodeAt(0), end.charCodeAt(0)];
}
function inRange(value, start, end) {
return value >= start && value <= end;
}
var checkOption = function(optionName) {
return process.argv.some(function(option) {
if (option.indexOf("--", 0) === 0 && optionName) {
return option.substr(2).toLowerCase() === optionName.toLowerCase();
}
return false;
});
};