Skip to content

Instantly share code, notes, and snippets.

@shanelau
shanelau / codevember-21-music-streaming-app-landing-page.markdown
Created March 5, 2024 06:14
#Codevember 21: Music Streaming App landing page
@shanelau
shanelau / index.js
Created August 28, 2017 08:24
http redirect to https
if (app.config.env === 'prod') {
// SLB 的 https 会添加 请求头部 x-forwarded-proto
const isHttps = this.ctx.request.headers['x-forwarded-proto'] && (this.ctx.request.headers['x-forwarded-proto'] === 'https');
if (!isHttps) {
return this.ctx.redirect(this.ctx.href.replace('http://', 'https://'));
}
}
@shanelau
shanelau / cache.js
Created August 10, 2017 07:06
egg middle for url cache
const DEFAULT_TTL = 60 * 1000;
const MIN_10 = 1 * 60 * 1000;
const cacheConfig = {
'/api/page/index': DEFAULT_TTL,
'/api/page/miner': DEFAULT_TTL,
'/api/page/luck': DEFAULT_TTL,
'/api/page/': DEFAULT_TTL,
'/api/blocks': DEFAULT_TTL,
'/api/miner/top10': MIN_10,
'/api/block/history': MIN_10,
@shanelau
shanelau / docker-install.sh
Last active April 14, 2017 03:17
install docker on linux
dir=`dirname $0`
DOCKER_VERSION=1.13.1
COMPOSE_VERSION=1.10.0
function get_docker {
ensuredir $1
DOCKER_COMPOSE_VERSION="DOCKER:$DOCKER_VERSION COMPOSE:$COMPOSE_VERSION"
if [ -e $1/version ] && [ "`cat $1/version`" = "$DOCKER_COMPOSE_VERSION" ]; then
echo docker has already fetched
@shanelau
shanelau / https-demo.html
Last active December 8, 2016 06:59 — forked from anonymous/index.html
DOMAIN: HTTPS 改造, 替换所有的非 https 域名。新增代码直接使用 https 域名// source http://jsbin.com/citocaz
<!DOCTYPE html>
<html lang="zh-Hans">
<head>
<meta charset="UTFa-8" />
<title>demo: HTTPS 改造</title>
<meta content="魅玩帮是一个提供智能硬件免费申请试玩的导购平台,我们筛选市面上最为前沿、时尚、实用和专业的硬件产品免费提供给用户进行试用,为其他用户在购买前提供有价值的决策参考。" name="description" />
<meta content="魅玩帮,可穿戴, 可穿戴设备, 智能设备, 智能可穿戴设备, 便携设备, 便携智能设备, 奇酷网, 奇酷,360 奇酷, 小米酷玩, 点名时间,牛玩,魅族智能硬件, 智能硬件,硬件, 智能移动设备, 免费试用, 苹果,评测,测评, 智能手环, 智能家居, 智能手表, 智能电视 " name="keywords" />
<meta content="True" name="HandheldFriendly" />
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible" />
<meta content="width=device-width,initial-scale=1,maximum-scale=1" name="viewport" />
@shanelau
shanelau / mqs-service.js
Created July 6, 2016 06:48
aliyun message queue service
var AliMNS = require("ali-mns");
var ENV = process.env;
var account = new AliMNS.Account(ENV.MQS_ACCOUNTID, ENV.MQS_KEY, ENV.MQS_SECURITY);
module.exports = {
MQActivity: new AliMNS.MQ(sails.config.mqs.queues.activity, account, ENV.MQS_REGION), // message queue client
MQElastic: new AliMNS.MQ(sails.config.mqs.queues.elastic, account, ENV.MQS_REGION) // message queue client
};
@shanelau
shanelau / .babelrc
Created June 28, 2016 02:32
node babel
{
"presets": [
"es2015",
"stage-0",
"react"
],
"plugins": [
"syntax-export-extensions",
"transform-export-extensions",
"add-module-exports"
@shanelau
shanelau / upyun-cache-refresh.js
Last active June 23, 2016 08:42
refresh cache for upyun by nodejs
/**
* Created by liuxing on 16/6/23.
*/
var request = require('request');
var crypto = require('crypto');
var UPYUN_CACHE = 'http://purge.upyun.com/purge/';
function md5sum(data) {
var md5 = crypto.createHash('md5');
md5.update(data, 'utf8');
@shanelau
shanelau / full_screen_iframe.html
Created May 8, 2016 08:27
full screen iframe
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>Asyncing</title>
<style>
body{
margin:0;
padding:0;
@shanelau
shanelau / nginx.sh
Last active May 12, 2016 10:33
nginx install for centos
#设置安装路径 chmod +x install_nginx.sh
save_path="/usr/local/"
#各安装包的版本
pcre="8.38"
path_pcre="pcre-${pcre}"
zlib="zlib-1.2.8"
openssl="openssl-1.0.1j"
nginx="nginx-1.8.0"
node="v0.12.2"