Skip to content

Instantly share code, notes, and snippets.

View struCoder's full-sized avatar
☀️
Working and Working

david zh struCoder

☀️
Working and Working
  • Shanghai China
View GitHub Profile
@struCoder
struCoder / dabblet.css
Created November 21, 2014 03:52
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
.demo {
width: 200px;
height: 200px;
-webkit-box-shadow: 0px 0px 10px #333;
box-shadow: 0px 0px 10px #333;
color: transparent;
/**
* @author Dongxu Huang, Shu Ke, Wang Lei
* @date 2013-07-08
*/
document.addEventListener("mousemove", update_mouse_pos, true);
document.addEventListener("mouseup", on_mouse_up, true);
document.addEventListener("mousedown", on_mouse_down, true);
document.addEventListener("dblclick", on_mouse_dbclick, true);
var clientX, clientY;
@struCoder
struCoder / editDistence.js
Created June 8, 2015 07:14
editDistence
var getStrDistance = function(str1, str2) {
var lenStr1 = str1.length;
var lenStr2 = str2.length;
if (lenStr1 === 0 || lenStr2 === 0) {
return lenStr1 === 0 ? lenStr2 : lenStr1;
}
var dArr = new Array(lenStr1 + 1);
for (var i = 0; i <= lenStr1; i++) {
dArr[i] = new Array(lenStr2 + 1);
dArr[i][0] = i;
local redis_c = require "resty.redis"
local ok, new_tab = pcall(require, "table.new")
if not ok or type(new_tab) ~= "function" then
new_tab = function (narr, nrec) return {} end
end
local _M = new_tab(0, 155)
@struCoder
struCoder / express-plugin.js
Created July 6, 2016 09:25
exress管理路由插件
function customRouter(originRouter, prefix) {
let urlArr = [];
let slice = [].slice;
let methods = ['get', 'post', 'delete', 'put'];
function array2ArrayLike(array) {
let arrayLike = {
length: 0
}
for(let i = 0; i < array.length; i++) {
@struCoder
struCoder / ffmpeg_compress_mp4.md
Created September 7, 2016 06:20
use fmpeg to compress mp4 video

use fmpeg to compress mp4 video

ffmpeg -i "input.MP4" -vb xxxk -vcodec libx264 -ab 64k -ar 44100 -y "output_.MP4"

xxxk: You should adjust its size according to your needs.

For example i use 2000k to compress Gopro mp4 videos.

// from here: http://marcio.io/2015/07/handling-1-million-requests-per-minute-with-golang/
// great example !!
func payloadHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
// Read the body into a string for json decoding
@struCoder
struCoder / multi_hash.go
Created December 16, 2016 09:01
figure file multi hash with go
package main
import (
"bufio"
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"encoding/hex"
"fmt"
@struCoder
struCoder / convert_gbk_utf8.js
Created December 25, 2016 13:28
遍历文件夹将gbk编码的文件专为utf8
'use strict';
const fs = require('fs');
const iconv = require('iconv-lite');
const path = require('path');
const p = console.log;
function readText(path) {
let buf = fs.readFileSync(path);
return iconv.decode(buf, 'gbk');
@struCoder
struCoder / csv.js
Created March 2, 2017 10:17
nodejs csv乱码解决方案
// https://cnodejs.org/topic/516e0ab46d382773067a5473
var http = require('http');
var url = require('url');
var Iconv = require('iconv').Iconv;
var crypto = require('crypto');
var server = http.createServer(function(req, res){
var path = url.parse(req.url).pathname;
if(path == '/favicon.ico'){
res.end('');