Skip to content

Instantly share code, notes, and snippets.

View koshuang's full-sized avatar

Kos Huang koshuang

  • OnrampLab
  • Taipei / Taiwan
View GitHub Profile
public
@koshuang
koshuang / a.html
Created July 1, 2013 02:30
Fist Example
< style >
# elem - container {
position: absolute;
left: 100px;
top: 200px;
height: 100px;
} < /style>
<div id="elem-container">dummy</div > < div id = "output" > < /div>
@koshuang
koshuang / functional_programing.js
Last active November 19, 2016 20:49
javascript functional programing example
/** functional.js **/
function flip (func) {
// preserve f
// construct g
return function() {
var args = Array.prototype.slice.call(arguments);
// flip arguments when called
return func.apply(null, args.reverse());
};
@koshuang
koshuang / fibonacci.js
Created July 15, 2013 01:53
recursion with functional programing
function memoizer (memo, formula) {
var recur = function(n) {
var result = memo[n];
if (typeof result !== 'number') {
result = formula(recur, n);
memo[n] = result;
}
return result;
}
@koshuang
koshuang / textoverflow.css
Created July 17, 2013 03:36
Text overflow
div {
overflow : hidden;
text-overflow : ellipsis;
white-space : nowrap;
width : 240px;
}
@koshuang
koshuang / boolean_example.js
Created July 17, 2013 04:09
邏輯判斷範例
var isMale = false;
var age = 16;
if (isMale && age <= 14) {
console.log("Hi Boy!");
}
else if (isMale && age > 14) {
console.log("Hi Man!");
}
else if (!isMale && age <= 14) {
@koshuang
koshuang / refactoringExample.js
Created July 26, 2013 06:06
Javascript version of Refactoring example
var countTotal = function(array, func) {
var total = 0;
array.forEach(function(each) {
total += func(each);
});
return total;
}
var Movie = function(title, priceCode) {
@koshuang
koshuang / functional_basis.js
Created July 27, 2013 14:42
functional basis
function addf (x) {
return function(y) {
return x + y;
}
}
function add (x, y) {
return x + y;
}
@koshuang
koshuang / rebuilding_facebook_chat_snippet.js
Created August 15, 2013 05:34
Code snippet for rebuilding facebook chat
//Code snippet for https://www.youtube.com/watch?v=unEuPvA2wnM
//OOP style
ChatTabView = function(thread, rootDOM) {
this.el = Template.appendTo(rootDOM);
var participants = thread.getParticipants();
this.el.find('.title')
.setText(generateTitle(participants.map('getName'));
};
_complete_ssh_hosts ()
{
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
comp_ssh_hosts=`cat ~/.ssh/known_hosts | \
cut -f 1 -d ' ' | \
sed -e s/,.*//g | \
grep -v ^# | \
uniq | \
grep -v "\[" ;