This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def firstchar(str) | |
return str.split.map{|w|w[0]}.join | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 = {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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? | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
/** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
OlderNewer