Skip to content

Instantly share code, notes, and snippets.

View chinghanho's full-sized avatar
💁‍♂️
What's up?

Ching-Han Ho chinghanho

💁‍♂️
What's up?
View GitHub Profile
@chinghanho
chinghanho / bytesToSize.js
Created November 2, 2017 06:50 — forked from lanqy/bytesToSize.js
JavaScript To Convert Bytes To MB, KB, Etc
// from http://scratch99.com/web-development/javascript/convert-bytes-to-mb-kb/
function bytesToSize(bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return 'n/a';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
if (i == 0) return bytes + ' ' + sizes[i];
return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i];
};
@chinghanho
chinghanho / velocity.js
Created September 6, 2017 16:20 — forked from yuheiy/velocity.js
add `easeOutBounce` to velocity.js
'use strict';
import Velocity from 'velocity-animate';
let baseEasings = {};
baseEasings.Bounce = p => {
let pow2;
let bounce = 4;
while (p < ((pow2 = Math.pow(2, --bounce)) - 1) / 11) {}
// CommonJS 給你兩個工具:
//
// 1. require 函式
// 2. module 物件
//
// 可以用 module.exports 把物件模組化,用 reuqire 把物件載入。
function Animation() {
//
}
@chinghanho
chinghanho / index.js
Last active July 29, 2016 11:10
模糊圈越大景深越深
var cocs = [0.014, 0.019, 0.029]
var dofs = []
var distance = 1000
var focal = 50
var f_number = 2.8
for (let i = 0; i <= cocs.length - 1; i++) {
let coc = cocs[i]
let farPoint = (distance * Math.pow(focal, 2)) / (Math.pow(focal, 2) - (f_number * coc * distance))
@chinghanho
chinghanho / main.rb
Created July 12, 2016 11:16
計算鏡頭焦距及標準全級光圈光闌面積
focals = [20, 50, 85]
f_numbers = [1.4, 2, 2.8, 4, 5.6]
focals.each do |focal|
puts "鏡頭焦距:#{focal}mm"
puts ""
f_numbers.each do |f|
@chinghanho
chinghanho / README.md
Created June 23, 2016 03:18
wget 1.18 更新

Wget漏洞(CVE-2016-4971)利用方式解析

sudo apt-get update
curl -O https://launchpad.net/wget/main/1.18/+download/wget-1.18.tar.gz
tar -zxvf wget-1.18.tar.gz
cd wget-1.18
./configure --with-ssl=openssl

The pkg-config script could not be found or is too old

@chinghanho
chinghanho / app.go
Last active October 10, 2015 09:03
Simple benchmark of plain text in Go, Ruby, PHP and Node.js
package main
import (
"fmt"
"log"
"net/http"
)
func rootHandler(w http.ResponseWriter, r *http.Request) {
<?php
$url = 'http://vimeo.com/71673549';
preg_match('/\/\/(www\.)?vimeo.com\/(\d+)($|\/)/', $url, $matches);
?>
<iframe src="http://player.vimeo.com/video/<?php echo $matches[2] ?>?title=0&amp;byline=0&amp;portrait=0&amp;badge=0&amp;color=ffffff" width="640" height="360" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
//
//
//
// .__ __. ______ _______ _______ __ _______.
// | \ | | / __ \ | \ | ____| | | / |
// | \| | | | | | | .--. || |__ | | | (----`
// | . ` | | | | | | | | || __| .--. | | \ \
// oooooooooooo | |\ | | `--' | | '--' || |____ __| `--' | .----) |
// `888' `8 |__| \__| \______/ |_______/ |_______(__)\______/ |_______/
// 888 oooo ooo oo.ooooo. oooo d8b .ooooo. .oooo.o .oooo.o
@chinghanho
chinghanho / index.html
Last active August 29, 2015 14:02
CSS 練習
<div class="jumbotron">
<div class="jumbotron-header">
<h1>這是標題</h1>
</div>
<div class="jumbotron-body">
<p>這裡是內文,上面要有一條線</p>
</div>
<div class="jumbotron-footer">
<p>這裡是 footer,上面不能有線</p>
</div>