Skip to content

Instantly share code, notes, and snippets.

View luojiyin1987's full-sized avatar
💭
I may be slow to respond.

luo jiyin luojiyin1987

💭
I may be slow to respond.
View GitHub Profile
@luojiyin1987
luojiyin1987 / create_link.sh
Created May 8, 2018 07:16
create link for all script
@luojiyin1987
luojiyin1987 / nodejs_mongoose.js
Last active July 3, 2018 10:31
[nodejs mongoose 想获得find的值] #异步
function couldSendSMS(mobile) {
SMSLog.model.find()
.where('mobile', mobile)
.sort({ expiredate: -1 })
.limit(1)
.exec( function (err, smsLogs) {
console.log("find ok");
return (smsLogs[0].expiredate < Date.now());
});
}
@luojiyin1987
luojiyin1987 / recurrence.js
Last active July 4, 2018 15:01
#recurrence #callback
let syncFn = x => {
console.log("x is " + x);
if (x < 10) {
syncFn(x + 1);
console.log("x is " + x);
}
}
console.log('=== start sync ===');
syncFn(2);
console.log('=== end sync ===');
@luojiyin1987
luojiyin1987 / anotherTickFn.js
Created July 4, 2018 15:06
#TickFn #callback
let anotherTickFn = x => {
console.log('async', x);
if (x < 10){
process.nextTick(() => {
anotherTickFn(x + 1);
});
}
}
console.log('=== start async ===');
@luojiyin1987
luojiyin1987 / Promise.js
Created July 5, 2018 04:24
#Promise #callback
let cleanRoom = function() {
return new Promise(function(resolve, reject){
resolve(' Cleaned The Room');
});
};
let removeGarbage = function(message) {
return new Promise(function(resolve, reject){
resolve(message + ' remove Garbage');
});
@luojiyin1987
luojiyin1987 / callback.js
Created July 6, 2018 11:45
要抽象的异步调用 #callback #moogoose
// 代码
const keystone = require('keystone');
const SMSLog = keystone.list('SMS_log');
const user = keystone.list('User');
const Wallet = keystone.list('Wallet');
exports = module.exports = function (req, res) {
console.log(req.query.id);
const id = req.query.id;
class Solution:
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
stack, lookup = [], {"(": ")", "{": "}", "[": "]"}
for par in s:
if par in lookup:
stack.append(par)
@luojiyin1987
luojiyin1987 / go_stack.go
Created July 19, 2018 14:57
#golang #stack
type stack []rune
func (s *stack) push(b rune) {
*s = append(*s, b)
}
func (s *stack) pop() (rune, bool) {
if len(*s) > 0 {
res := (*s)[len(*s)-1]
*s = (*s)[:len(*s)-1]
@luojiyin1987
luojiyin1987 / vaild_parar.go
Created July 19, 2018 14:59
#golang #leetcode
func isValid(s string) bool {
stack := []rune{}
for _, b := range s {
switch b {
case '(', '[', '{':
stack = append([]rune{b}, stack...)
default:
if len(stack) > 0 {
c := stack[0]; stack = stack[1:]
switch c {