Skip to content

Instantly share code, notes, and snippets.

View haohcraft's full-sized avatar

Hao haohcraft

View GitHub Profile
@haohcraft
haohcraft / easing.js
Created March 23, 2014 04:00 — forked from gre/easing.js
/*
* Easing Functions - inspired from http://gizma.com/easing/
* only considering the t value for the range [0, 1] => [0, 1]
*/
EasingFunctions = {
// no easing, no acceleration
linear: function (t) { return t },
// accelerating from zero velocity
easeInQuad: function (t) { return t*t },
// decelerating to zero velocity
var urlRegEx = /(http|https|ftp):\/\/[-a-zA-Z0-9@:%_\+.~#?&\/\/=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?$&\/\/=]*)?/gi;
//If entered data doesn't match the URL regex, then return error data, and don't actually make the AJAX request.
if (!urlRegEx.test(link)) {
var badURL = {warning: "Snap! That link came back with nothing. How about pasting it in?", tags: []};
$scope.suggestedData = badURL;
return;
}
@haohcraft
haohcraft / markify
Last active October 5, 2015 10:37
This is a wrapper for the API at http://fuckyeahmarkdown.com/
/**
* This is a wrapper for the API at http://fuckyeahmarkdown.com/
* where the article in the web will transform to a readable markdown text
* @author haohcraft@gmail.com
*/
/**
* Module dependencies
*/
'usr strict';
@haohcraft
haohcraft / gist:dfa7a4c8cc470a0282d1
Created June 11, 2014 03:26
Give permission to npm

This looks like a permissions issue in your home directory. To reclaim ownership of the .npm directory execute

sudo chown -R whoami ~/.npm

@haohcraft
haohcraft / gist:3bcff42a1d4e2d16dc55
Last active August 29, 2015 14:02
How to install opencv in mac os 10.9
http://stackoverflow.com/questions/19707468/installing-opencv-2-4-2-on-mac-os-x-10-9-mavericks
----------------Approach 1---------------
I tried your problems and I think steps are as follow:
open terminal in mac
in the terminal, check you have cmake and ccmake. If not, please type "brew install cmake"
go to your downloaded opencv folder, make a new folder by typing "mkdir build", then "cd build"
in this build folder, check you have gcc and g++ installed.
@haohcraft
haohcraft / gist:5fb2d8cf6528e9e3cd0c
Last active August 29, 2015 14:03
Check if the email is valid
function validateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
@haohcraft
haohcraft / gist:7927578b4fa72828eda0
Created July 18, 2014 14:28
Find port, and kill it
Find:
lsof -i :<Port Num>
Kill:
kill -9 <PID>
@haohcraft
haohcraft / messaging.js
Created August 7, 2014 04:42
A script to show chat on the page
(function(document){
"use strict";
var chatToggle;
var chatBox;
var chatPopup;
var dynamics;
var chatBoxHidden = true;
var contacts;
var currentContactID = -1;
@haohcraft
haohcraft / isFirefox
Created December 19, 2014 13:41
isFirefox/isWebkit/isSafari
'use strict';
function isFirefox() {
return /firefox/i.test(navigator.userAgent);
}
function isWebkit() {
return 'WebkitAppearance' in document.documentElement.style;
}
@haohcraft
haohcraft / gist:b82080092a5057cb7182
Last active August 29, 2015 14:13
How to parse your inbound email