Skip to content

Instantly share code, notes, and snippets.

View lgh06's full-sized avatar

Daniel Liu lgh06

View GitHub Profile
@lgh06
lgh06 / meta.html
Created April 17, 2014 04:34 — forked from Jimco/meta.html
<!DOCTYPE html> <!-- HTML5 doctype 不区分大小写 -->
<html lang="zh-cmn-Hans-CN"> <!-- 更加标准的 lang 属性写法 http://zhi.hu/XyIa -->
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <!-- 优先使用IE最新版本和 Chrome -->
<meta name="renderer" content="webkit|ie-comp|ie-stand"> <!-- 360 浏览器内核控制 -->
<!--
content的取值为webkit,ie-comp,ie-stand之一,区分大小写,分别代表用webkit内核,IE兼容内核,IE标准内核。

@kangax's ES6 quiz, explained

@kangax created a new interesting quiz, this time devoted to ES6 (aka ES2015). I found this quiz very interesting and quite hard (made myself 3 mistakes on first pass).

Here we go with the explanations:

Question 1:
(function(x, f = () =&gt; x) {
@lgh06
lgh06 / handlebars-helper-x.js
Created July 14, 2016 09:04 — forked from akhoury/handlebars-helper-x.js
Handlebars random JavaScript expression execution, with an IF helper with whatever logical operands and whatever arguments, and few more goodies.
// for demo: http://jsbin.com/jeqesisa/7/edit
// for detailed comments, see my SO answer here http://stackoverflow.com/questions/8853396/logical-operator-in-a-handlebars-js-if-conditional/21915381#21915381
/* a helper to execute an IF statement with any expression
USAGE:
-- Yes you NEED to properly escape the string literals, or just alternate single and double quotes
-- to access any global function or property you should use window.functionName() instead of just functionName()
-- this example assumes you passed this context to your handlebars template( {name: 'Sam', age: '20' } ), notice age is a string, just for so I can demo parseInt later
<p>
{{#xif " this.name == 'Sam' && this.age === '12' " }}
@lgh06
lgh06 / supervisord.sh
Last active July 22, 2016 16:06 — forked from danmackinlay/supervisord.sh
an init.d script for supervisord
#! /bin/sh
### BEGIN INIT INFO
# Provides: supervisord
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
@lgh06
lgh06 / sohu_crawler.js
Created August 9, 2016 08:37 — forked from sillykelvin/sohu_crawler.js
A node.js script for sohu video downloading
#!/usr/bin/env node
var fs = require('fs');
var http = require('http');
var request = require('request');
var urlListFile = 'url.list';
if (!fs.existsSync(urlListFile)) {
@lgh06
lgh06 / video.php
Created August 11, 2016 04:41 — forked from HuangFJ/video.php
通过php直接输出的文件通常不被html5的<video>标签支持,尤其是ios设备。为了完美支持html5的视频播放,php必须支持byte-range请求。因为html5播放视频之前会发送一个只需文件少数字节的请求,确认服务端是否支持byte-range请求,支持才会继续发送请求剩余的文件数据。
<?php
$localfile = "test.mp4";
$size = filesize($localfile);
$start = 0;
$end = $size - 1;
$length = $size;
header("Accept-Ranges: 0-$size");
@lgh06
lgh06 / enc_file_stream.js
Last active October 28, 2016 02:44 — forked from csanz/encrypt_decrypt.js
Simple String Encryption & Decryption with Node.js
var fs = require('fs'),
crypto = require('crypto');
var key = '14189dc35ae35e75ff31d7502e245cd9bc7803838fbfd5c773cdcd79b8a28bbd',
cipher = crypto.createCipher('aes-256-cbc', key);
input = fs.createReadStream('test.txt'),
output = fs.createWriteStream('test.txt.enc');
input.pipe(cipher).pipe(output);
@lgh06
lgh06 / task.js
Created November 9, 2016 02:30 — forked from zmofei/task.js
cutwords
var fs = require('fs')
var trie = {}
var tempWords = {};
fs.readFile('./text.txt',function(err,callback){
var str = callback.toString();
str = str.replace(/[^\u4e00-\u9fa5]/g,'@');
str = str.replace(/@+/g,' ')
split(str);
@lgh06
lgh06 / better-nodejs-require-paths.md
Created January 12, 2017 08:34 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions