Skip to content

Instantly share code, notes, and snippets.

@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.
*
@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 / 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 / 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 / __components_inline-edit.js
Last active August 29, 2015 14:25
{{inline-edit}} for Ember
/**
* Inline Edit Component
*
* @author lamchau
*/
import Ember from "ember";
import KeyCodes from "utils/key-codes";
const DOUBLE_CLICK_COUNT = 2;
const SINGLE_CLICK_COUNT = 1;
Object.prototype[Symbol.iterator] = function() {
let self = this;
let keys = null;
let length = 0;
let index = -1;
return {
next() {
if (keys === null) {
keys = Object.keys(self);
(function(I18n) {
if (!I18n) {
throw new Error('Missing dependency: I18n');
}
var translate = I18n.translate;
var slice = [].slice;
/**
* // en.js
function demethodize(fn) {
if (typeof fn === "function") {
return Function.bind.bind(Function.call)(fn);
}
return null;
}
_.mixin((function() {
return {
demethodize: function(fn) {
function humanizeBytes(bytes, si) {
unit = si ? 1e3 : 1024;
var byteSuffix = (si ? 'b' : 'B');
if (bytes < unit) {
return bytes + byteSuffix;
}
var modifier = Math.floor(Math.log(bytes) / Math.log(unit));
var prefix = (si ? 'kMGTPEZ' : 'KMGTPEZ')[modifier - 1];
if (!si) {
function orderByProperty(prop) {
var args = [].slice.call(arguments, 1);
return function (a, b) {
var propA = a[prop];
var propB = b[prop];
var result;
if (typeof propA == 'string' || typeof propB == 'string') {
result = String(propA).localeCompare(propB);
} else {