Skip to content

Instantly share code, notes, and snippets.

def firstchar(str)
return str.split.map{|w|w[0]}.join
end
/**
* Question:
* Suppose you are given an array stock_prices_yesterday of the prices of a stock
* over time. Write an efficient algorithm for computing the best profit you can
* make from first buying 1 share of the stock, and then selling that 1 share
* later. Note that you must buy before you sell (no "shorting").
*/
function copy(obj) {
var ret = {};
function colemanLiau(L, S) {
return 0.0588 * L - 0.296 * S - 15.8;
}
////////////////////////////////////////////////////////////////////////////////
// Parser //////////////////////////////////////////////////////////////////////
function TextParser(text) {
if (!(this instanceof TextParser)) {
return new TextParser(text);
/**
* Coin Change Problem
* ===================
* Find the number of ways of making changes for a particular amount of cents, N,
* using a given set of denominations S = {S1,S2,S3,...S[m]}.
*
* Let's look into a similiar but simplier case:
* | 0 1 2 3 4 5 ... N
* ---+--------------------------
* 1 | 1 1 1 1 1 1
@tcw165
tcw165 / ConcurrencyModelOfJavaScript.js
Last active August 30, 2015 13:54
Experiment for testing the "Concurrency Model and Event Loop" of JavaScript.
/**
* This is an experiment for testing the "Concurrency Model and Event Loop" of
* JavaScript.
*
* It's designed that an asynchronous function with a given callback is called;
* And subsequently a synchronous function which is designated to take far more
* time than the asynchronous one will take is called.
*
* Question: what is the response order of async-fun/sync-fun/callback?
*
/**
* How to declare a real private members in a JavaScript class?
*
* Prerequisities
* --------------
* 1. This is a node module, as it's wrapped in a closure (Module Pattern).
* e.g. var XXX = (function() { ... })();
* 2. Need ES6 support.
*
* Solution
package com.cardinalblue.android.piccollage.math;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.RectF;
import java.util.ArrayList;
import java.util.List;
/**
// Copyright (c) 2015 boyw165
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
@tcw165
tcw165 / ImageUtil.java
Last active May 26, 2018 11:40
The Android's image helper class
// Copyright (c) 2016 boyw165
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
@tcw165
tcw165 / BoilerplateActivity.java
Last active March 5, 2016 04:53
A boilerplate for Android Activity
// Copyright (c) 2016 boyw165
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in