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 / 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 / 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))
// CommonJS 給你兩個工具:
//
// 1. require 函式
// 2. module 物件
//
// 可以用 module.exports 把物件模組化,用 reuqire 把物件載入。
function Animation() {
//
}
@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) {}
@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 / what-forces-layout.md
Created January 13, 2018 02:13 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@chinghanho
chinghanho / fuzzy_string_match.js
Created May 13, 2018 15:34 — forked from dtjm/fuzzy_string_match.js
Fuzzy string matching function for JavaScript
// Fuzzy matching algorithm
var fuzzyMatch = function(needle, haystack) {
if(needle === "" || haystack === "") return true;
needle = needle.toLowerCase().replace(/ /g, "");
haystack = haystack.toLowerCase();
// All characters in needle must be present in haystack
var j = 0; // haystack position
for(var i = 0; i < needle.length; i++) {
uniform sampler2D tex; // matched from gst-plugin-gl uniform
const vec4 kappa = vec4(1.0,1.7,0.7,15.0);
// These can be made uniform if they are added to:
// gst/gl/gstglfiltershader.c:363
// gst_gl_shader_set_uniform_1f (filtershader->shader0, "screen_width", width);
// gst_gl_shader_set_uniform_1f (filtershader->shader0, "screen_height", height);
const float screen_width = 1920.0;
const canvasSketch = require('canvas-sketch'); // not yet released tool
const Random = require('./util/random');
const { lerp } = require('./util/math');
// We can force a random seed or a specific string/number
Random.setSeed(Random.getRandomSeed());
const settings = {
pixelsPerInch: 300,
// When exporting, use the seed as the suffix
@chinghanho
chinghanho / encoding-video.md
Created June 17, 2019 15:23 — forked from glen-cheney/encoding-video.md
Encoding video for the web

Encoding Video

Installing

Install FFmpeg with homebrew. You'll need to install it with a couple flags for webm and the AAC audio codec.

brew install ffmpeg --with-libvpx --with-libvorbis --with-fdk-aac --with-opus