Skip to content

Instantly share code, notes, and snippets.

View cold-coder's full-sized avatar
🎯
Focusing

Yao Cheng cold-coder

🎯
Focusing
View GitHub Profile
@cold-coder
cold-coder / refreshRem.js
Created March 16, 2017 09:48
Page Rem Calculation
;
(function(win) {
var doc = win.document;
var docEl = doc.documentElement;
var tid;
function refreshRem() {
var width = docEl.getBoundingClientRect().width;
if (width > 540) { // 最大宽度
width = 540;
@cold-coder
cold-coder / promise.js
Created January 2, 2017 12:10
Promise the right way
let step1 = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('in step1');
resolve(1);
// reject(new Error('error from step1'));
}, 1000)
})
}
@cold-coder
cold-coder / lucky_draw.js
Last active January 2, 2023 13:46
#PhotoOf2016摄影评比参与奖抽奖程序
// var url = 'https://gist.github.com/cold-coder/4e60e31d254e921255d37874c302bd48';
const guys2017 = ['*晓悦', '*亚玲', '*佳', '*芽琦', '*范贤', '*奕', '*俊余', '*国迁',
'*晓炜', '*bing', '*乐琦', '*晓婷', '*达嵩', '*明明', '*伟中', '*志强', '*建华',
'*慧', '*伟锋', '*传萍', '*霞琴', '*晶晶', '*利华', '*华', '*苗', '*玉娇','*亚松',
'*亮萍'];
const guys2018 = ['*晴怡','Allen','*永成','Rain','*志强','Mira','Jonathan','Rachel',
'*霞琴', '*国迁', '*帆', '*才标', '*俊杰', 'Angela', '*浩宁', '*艳敏','*佳宝',
'chen洁', '*婧', '*承其', '*赛', '*成庆', '*杰', '*奇', '*小静','*成', 'chu洁',
@cold-coder
cold-coder / index.js
Created June 3, 2016 03:09
ES6 argument destructuring demo
let o = {a:'123',b:'456'}
let f = ({ a }) => {
console.log(a)
return 0
}
f(o) //123
@cold-coder
cold-coder / .gitignore
Last active January 7, 2016 14:09
WeChat UI Preview
jquery*.js
@cold-coder
cold-coder / Connectivity.js
Last active November 30, 2015 02:55
Check Internet access available in node.js, use book.douban.com to test in this case.
// require('dns').resolve('book.douban.com', function(err) {
// if (err){
// console.log('Oops! Cannot access Douban');
// }
// else{
// console.log('Have Internet Access');
// }
// });
require('http').get("book.douban.com", function(res) {
@cold-coder
cold-coder / server.js
Last active October 21, 2016 23:26
Use ajax approach to submit form, including multipart element.
var multer = require('multer');
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, 'public/img/');
},
filename: function (req, file, cb) {
cb(null, file.originalname + Date.now().toString().slice(0,10));
}
})
Select all and delete (actually move to buffer)
:%d
Select all and copy to buffer
:%y
Use p to paste the buffer.
@cold-coder
cold-coder / Weibo_Style.css
Created August 27, 2014 07:03
新浪微博V5 还我漂漂版
*{font-family: Georgia, "Times New Roman", "Microsoft YaHei", "微软雅黑", STXihei, "华文细黑", serif;}
.WB_feed a.notes {margin: 20px 20px 5px !important;padding: 10px 1px;}
.WB_feed a.notes:hover {background-color:#F7F3C6 !important;text-decoration:none !important;}
@cold-coder
cold-coder / dragAnywhere.html
Created May 7, 2014 10:05
drag and drop element on the page
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
<style>
html{
height: 100%;
}
body{