This file contains 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
String::reverse = -> | |
size = @length + 1 | |
result = "" | |
while size -= 1 | |
result += @[size - 1] | |
result | |
String::reversable = -> | |
@reverse() == @toString() |
This file contains 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
# to memorize the collatz sequence length for a specific number | |
memory = [] | |
Number::collatz = -> | |
if @ % 2 == 0 | |
@ / 2 | |
else | |
3 * @ + 1 | |
Number::collatzSequenceLength = -> |
This file contains 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
#!/bin/env ruby | |
# -*- coding: utf-8 -*- | |
class MatrixCalc | |
def initialize(matrix) | |
@matrix = matrix | |
end | |
def input | |
@input ||= traverse |
This file contains 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
// 输入 m: 月, d: 天 | |
// 例如 getAstro(5, 1) 返回 `金牛` | |
function getAstro(m, d) { | |
return "魔羯水瓶双鱼牡羊金牛双子巨蟹狮子处女天秤天蝎射手魔羯".substr(m * 2 - (d < "102123444543".charAt(m - 1) - -19) * 2, 2); | |
} |
This file contains 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
var Q = require('q'); | |
var util = require('util'); | |
function randomDelayedCall(func) { | |
var delay = Math.floor(Math.random() * (1200 - 100) + 100); | |
setTimeout(func, delay); | |
} | |
function findUser(id, cb) { | |
var err = null; |
This file contains 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
module.exports = { | |
resourcePath: '/orgs', | |
apis: [{ | |
path: '/orgs', | |
operations: [{ | |
httpMethod: 'POST', | |
responseClass: 'void', | |
nickname: 'returnParams', | |
parameters: [{ | |
dataType: 'Org', |
This file contains 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
// To test with it, run with `curl` | |
// curl -F "photo=@/path/to/your/photo" localhost:3000/api/uploads | |
var express = require('express'); | |
var swagger = require('swagger-jack'); | |
var app = express(); | |
app.use(express.logger('dev')) | |
.use(express.bodyParser()) | |
.use(express.methodOverride()) | |
.use(swagger.generator(app, { |
This file contains 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
var _ = require('underscore'); | |
var ObjectID = require('mongodb').ObjectID; | |
var duplicatedIds = []; | |
var lengthOfDuplicatedIds = 10; | |
for (var i = 0; i < lengthOfDuplicatedIds; i++) { | |
duplicatedIds.push(new ObjectID()); | |
} | |
var ArrToTest = []; |
This file contains 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
11:29:35.387693 IP (tos 0x0, ttl 63, id 50801, offset 0, flags [DF], proto TCP (6), length 64) | |
116.2xx.x.x.53587 > 115.239.211.110.80: Flags [S], cksum 0x5f8f (correct), seq 895062881, win 65535, options [mss 1452,nop,wscale 4,nop,nop,TS val 783494939 ecr 0,sackOK,eol], length 0 | |
0x0000: 4500 0040 c671 4000 3f06 95fc 74ea 2302 [email protected]@.?...t.#. | |
0x0010: 73ef d36e d153 0050 3559 9361 0000 0000 s..n.S.P5Y.a.... | |
0x0020: b002 ffff 5f8f 0000 0204 05ac 0103 0304 ...._........... | |
0x0030: 0101 080a 2eb3 2f1b 0000 0000 0402 0000 ....../......... | |
11:29:35.394412 IP (tos 0x0, ttl 55, id 50801, offset 0, flags [DF], proto TCP (6), length 64) | |
115.239.211.110.80 > 116.2xx.x.x.53587: Flags [S.], cksum 0x2bbb (correct), seq 117149092, ack 895062882, win 65535, options [mss 1440,nop,wscale 7,nop,nop,nop,nop,nop,nop,nop,nop,nop,nop,nop,nop,sackOK,eol], length 0 | |
0x0000: 4500 0040 c671 4000 3706 9dfc 73ef d36e [email protected]@.7...s..n |
This file contains 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
PS1='\[\e[1;34m\]\u@\h \W \[\e[0;32m\]\$\[\e[0;39m\] ' | |
if [ -f `brew --prefix`/etc/bash_completion ]; then | |
. `brew --prefix`/etc/bash_completion | |
PS1='\[\e[1;34m\]\u@\h \W\[\e[0;36m\]$(__git_ps1 "(%s)") \[\e[0;32m\]\$\[\e[0;39m\] ' | |
# PS1='\u@\h \W$(__git_ps1 " (%s)")\$ ' | |
GIT_PS1_SHOWDIRTYSTATE=true | |
fi | |
# bash setting |
OlderNewer