Skip to content

Instantly share code, notes, and snippets.

View sunmockyang's full-sized avatar

Sunmock Yang sunmockyang

View GitHub Profile
@sunmockyang
sunmockyang / IntersectionPoint.js
Created January 2, 2013 00:17
This set of functions has been developed as a thought of detecting intersection between bounding boxes based on whether a line segment between two corners has been intersected by another line segment. It will take two line segments, and return the point of intersection or return null if the line segments do not intersect. This code has not been …
// Two lines defined by entering 2 points
var line1 = new line([1, 1], [5, 5]); // Positive slope
var line2 = new line([1, 5], [5, 1]); // Negative slope
var line3 = new line([2, 6], [6, 2]); // Parallel to line 2 but line3 != line2
var line4 = new line([3.5, 0], [3.5, 5]); // Vertical line
console.log(line1);
console.log(line2);
console.log("Calculate: ")
console.log(calcIntersection(line1, line2)); // returns (3,3)
@sunmockyang
sunmockyang / Math.js
Last active January 2, 2017 00:55
For math vector objects.
// Math.js by Sunmock Yang
function Vector(x, y){
this.x = (typeof x !== "undefined") ? x : 0;
this.y = (typeof y !== "undefined") ? y : 0;
}
Vector.prototype.set = function(x,y) {
this.x = x; this.y = y;
};
@sunmockyang
sunmockyang / CanvasAppTemplate.html
Last active August 29, 2015 14:00
Canvas app project template
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<style type="text/css">
#canvas{
border: gray solid 2px;
}
</style>
</head>
@sunmockyang
sunmockyang / Puush File
Last active August 29, 2015 14:01
Right click and Puush for Linux Nautilus. Pair and use with the screenshot tool, and you've got a ghetto puush for linux!
#!/bin/bash
# Nautilus script -> Puush File for Ubuntu/linux
# Owner : Sunmock Yang
# www.sunmock.com
# May 2014
#
# Dependencies: - puush-linux (https://github.com/blha303/puush-linux)
# - xclip
# - notify-send
# - Nautilus
@sunmockyang
sunmockyang / mkv2mp4.sh
Last active August 29, 2015 14:01
Script to convert MKV files to MP4 with burned in subtitles with correct fonts. Primarily made to convert anime in mkv files to view on mobile devices.
#!/bin/bash
MAX_WIDTH=1280
MAX_HEIGHT=720
OUTPUT_DIR=${HOME}"/Videos"
IPHONE_PRESET="-e x264 -q 20.0 -r 30\
--pfr -a 1 -E ffaac -B 160 -6 dpl2 -R Auto\
-D 0.0 --audio-copy-mask aac,ac3,dtshd,dts,mp3\
@sunmockyang
sunmockyang / ClassTemplate.js
Created June 23, 2014 15:27
Javascript Class Template
var Class = (function(){
var Class,
staticVars = "";
function exports(args){
return new Class(args);
};
Class = function(args){
// Constructor
@sunmockyang
sunmockyang / project.html
Last active August 29, 2015 14:04
Simple project presentation HTML template
<!DOCTYPE html>
<meta charset="utf-8" />
<html>
<head>
<title>Project Template - Sunmock Yang</title>
<link rel="stylesheet" type="text/css" href="theme.css">
</head>
<body>
@sunmockyang
sunmockyang / project.html
Last active August 29, 2015 14:05
Canvas App Project Template. Combining the project template and the canvas app template
<!DOCTYPE html>
<meta charset="utf-8" />
<html>
<head>
<title>Project Template - Sunmock Yang</title>
<link rel="stylesheet" type="text/css" href="theme.css">
</head>
<body>
@sunmockyang
sunmockyang / Bounds.js
Last active September 29, 2015 02:08
Simple rectangular bounds
function Bounds(top, left, width, height){
this.top = (top) ? top : 0;
this.left = (left) ? left : 0;
this.width = (width) ? width : 0;
this.height = (height) ? height : 0;
this.right = this.left + this.width;
this.bottom = this.top + this.height;
};
@sunmockyang
sunmockyang / ColorAnimator.js
Created December 16, 2014 04:27
Animates colors of an element style attribute.
// Example: new ColorAnimator(document.getElementById("elem"), "backgroundColor", ["#FF0063", "#63FF00"], "slow");
function ColorAnimator(element, styleAttribute, colors, speed){
this.element = element;
this.styleAttribute = styleAttribute;
this.colors = [];
for (var i = 0; i < colors.length; i++) {
this.colors.push(new ColorAnimator.Color(colors[i]));