Skip to content

Instantly share code, notes, and snippets.

View giscafer's full-sized avatar
🎣
Work hard

Nicky Lao giscafer

🎣
Work hard
View GitHub Profile
@giscafer
giscafer / Cookie.ts
Created November 22, 2019 02:11
Cookie类封装
@giscafer
giscafer / socket-client-sdk.js
Created May 30, 2019 03:27
前端 对 websocket 封装,提供一个client-js-sdk.js , 使得client可以通过管道发送异步请求。管道只有一个,也就是只有 onMessage 和 emit 。遇到问题就是,socket中 listener 和 emit 是两个独立的块,伪代码说明如何实现封装。
/**
* 伪代码
*/
var socket = {};
socket.on('message', function() {
// listener 真正拿到结果
});
@giscafer
giscafer / compare-pk.js
Created April 26, 2019 09:22
CI配置,监听package.json 文件版本更新,然后脚本自动修改NODE_MODULES_VERSION版本号
'use strict';
const fs = require('fs');
const exec = require('child_process').exec;
const npmPackageName = process.env.npm_package_name;
const uri = './.gitlab-ci.yml';
const uuid = () => {
return `${Math.random()
@giscafer
giscafer / .eslintrc
Last active April 19, 2019 09:50
React Native ESLint Config
{
"parser": "babel-eslint",
"plugins": ["react", "react-native"],
"env": {
"browser": true,
"node": true
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true,
@giscafer
giscafer / bos-upload.js
Created January 26, 2019 08:51
微信小程序百度直传
/**
* 百度BOS直传
* @param {*} filePath
*/
export default function uploadPicture(filePath) {
let filename = uuid() + filePath.substring(filePath.lastIndexOf("/") + 1);
const tokenObj = Taro.getStorageSync('bosUploadToken');
let policy = `{"conditions":[{"bucket":"yztfile"},{"key":"${commonPath}${filename}"}]}`;
let base64 = Base64.encode(policy)
let signature = HmacSHA256(base64, secretAccessKey).toString(EncHex);
@giscafer
giscafer / ordercancel48.js
Created January 24, 2019 02:13
48小时订单倒计时
const orderCancelTime = 48 * 3600 * 1000;
const timeCountDown = orderCancelTime - (30 * 60 * 1000); // 半小时开始倒计时
const farawayTime = orderCancelTime - (60 * 60 * 1000); // 1小时以上不倒计时,避免定时器性能问题
export const formatByTimestamp = (timestamp, hasHour) => {
let second = Math.floor(timestamp / 1000);
if (second < 1) {
return '';
}
@giscafer
giscafer / BinarySearchTree.js
Last active August 15, 2018 13:55
二叉搜索树 数据结构实现
/* 二叉搜索树 数据结构实现 */
class TreeNode {
constructor(key) {
this.key = key;
this.left = null;
this.right = null;
}
}
@giscafer
giscafer / HashTable.js
Created August 9, 2018 02:38
散列表(散列算法的作用是尽可能快地在数据结构中找到一个值)
/* 散列表*/
// 缺点:键的冲突度较高
class HashTable {
constructor() {
this.table = [];
}
/* 散列函数 */
loseloseHashCode(key) {
@giscafer
giscafer / LinkedList.js
Created August 6, 2018 07:18
链表数据结构实现
/**
* 链表实现
*/
/* 用来创建链表中的每个项 */
class LinkNode {
constructor(element) {
this.element = element;
this.next = null;
}
@giscafer
giscafer / Queue.js
Last active August 26, 2019 10:02
JavaScript类模拟队列实现
/**
* @author: giscafer ,https://github.com/giscafer
* @date: 2018-07-25 15:59:02
* @description: 类实现队列模拟
*/
const Queue = (() => {
// 闭包实现私有变量
let item = new WeakMap();