Skip to content

Instantly share code, notes, and snippets.

View lgh06's full-sized avatar

Daniel Liu lgh06

View GitHub Profile
@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 / img-onerror.js
Created August 3, 2016 12:13
img-onerror.js
var coverInitialed = false;
util.covererror = function (selector) {
if (coverInitialed) return;
if (document.addEventListener && document.removeEventListener){ //现代浏览器 根节点捕获
var errorhandler = function(e){
console.log(e)
var elem = e.target;
if($(elem).parent().is('.user_img')){ //出错的节点并不多
@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 / img2base64.html
Created September 21, 2016 12:09
drag an image,converted to base64
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>file encode to Base64URL</title>
<style>
body{
font-size:12px;
font-family:verdana;
@lgh06
lgh06 / mse-mp4.html
Last active October 18, 2016 09:29
渐进加载mp4文件 需要服务端支持 有bug 不支持拖拽
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<video controls></video>
<script>
var video = document.querySelector('video');
#
# Wide-open CORS config for nginx
# HEAD方法和OPTIONS方法一定要支持。HEAD显示文件信息,OPTIONS让浏览器确认有权限跨域。
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
#
# Om nom nom cookies
#
@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);