Skip to content

Instantly share code, notes, and snippets.

View xyfeng's full-sized avatar

XY Feng xyfeng

View GitHub Profile
@xyfeng
xyfeng / z installation note
Last active April 17, 2019 13:46
z install
#The power of z, copied from https://gist.github.com/mischah/8149239
Do you spend lots of time doing things like this?
cd this/is/the/path/that/i/want/so/i/type/it/all/out/to/get/whereiwant
With z, you could just do this:
z whereiwant
See README of z for all available options.
@xyfeng
xyfeng / bash alias
Last active April 12, 2019 19:30
bash alias
alias scs='source ~/.bashrc'
alias seebs='open -a TextEdit ~/.bashrc'
alias ls='ls -FGOp'
alias la='ls -FGOla'
alias lsg='ls -a | grep -ie '
alias lsl='ls | less'
alias h='history'
# git ##############
# taken from http://www.piware.de/2011/01/creating-an-https-server-in-python/
# generate server.xml with the following command:
# openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
# run as follows:
# python simple-https-server.py
# then in your browser, visit:
# https://localhost:4443
import BaseHTTPServer, SimpleHTTPServer
import ssl
@xyfeng
xyfeng / regex-js-comment
Created September 1, 2017 14:41
regex/js/comment
/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm
// JavaScript:
// source_string.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '$1');
// PHP:
// preg_replace("/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/m", "$1", $source_string);
@xyfeng
xyfeng / regex-js-comment
Created September 1, 2017 14:41
regex/js/comment
/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm
// JavaScript:
// source_string.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '$1');
// PHP:
// preg_replace("/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/m", "$1", $source_string);
@xyfeng
xyfeng / Highcharts Cheat Sheet
Created May 16, 2017 19:06 — forked from mulhoon/Highcharts Cheat Sheet
Highcharts Cheat Sheet
$('#container').highcharts({
chart: {
alignTicks: true, // When using multiple axis, the ticks of two or more opposite axes will automatically be aligned by adding ticks to the axis or axes with the least ticks.
animation: true, // Set the overall animation for all chart updating. Animation can be disabled throughout the chart by setting it to false here.
backgroundColor: '#FFF', // The background color or gradient for the outer chart area.
borderColor: '#4572A7', // The color of the outer chart border.
borderRadius: 5, // The corner radius of the outer chart border. In export, the radius defaults to 0. Defaults to 5.
borderWidth: 0, // The pixel width of the outer chart border.
className: null, // A CSS class name to apply to the charts container div, allowing unique CSS styling for each chart.
defaultSeriesType: 'line', // Alias of type.
@xyfeng
xyfeng / gist:2247e6367e7843ed6593823b2bb3c820
Created February 23, 2017 22:39
calculate barycentric coordinates in Processing
// calcuate barycentric coordinates (u,v,w) for point p with respect to triangle (a,b,c)
// use 3d PVector to store u,v,w
// https://en.wikipedia.org/wiki/Barycentric_coordinate_system
PVector getBaryCentric(PVector p, PVector a, PVector b, PVector c) {
PVector v0 = PVector.sub(b, a);
PVector v1 = PVector.sub(c, a);
PVector v2 = PVector.sub(p, a);
float den = v0.x * v1.y - v1.x * v0.y;
float v = (v2.x * v1.y - v1.x * v2.y) / den;
// calcuate center point from given three points
// http://paulbourke.net/geometry/circlesphere/
PVector calculateCenter(PVector p1, PVector p2, PVector p3) {
float ma = (p2.y - p1.y) / (p2.x - p1.x);
float mb = (p3.y - p2.y) / (p3.x - p2.x);
float x = (ma * mb * (p1.y - p3.y) + mb * (p1.x + p2.x) - ma * (p2.x + p3.x)) / ( 2 * (mb - ma));
float y = (p1.x - p3.x + ma * (p1.y + p2.y) - mb * (p2.y + p3.y)) / (2 * (ma - mb));
return new PVector(x, y);
}
@xyfeng
xyfeng / gif.py
Last active January 19, 2022 15:55
python script turn images into gif
# From https://github.com/wnyc/PIL/blob/master/Scripts/gifmaker.py
#
# The Python Imaging Library
# $Id$
#
# convert sequence format to GIF animation
#
# history:
# 97-01-03 fl created
#
@xyfeng
xyfeng / grid.scss
Created June 4, 2015 18:25
Flexbox grid scss with custom gutter
/**
* Grid Setup
* Modified from http://matthewsimo.github.io/scss-flex-grid/
*/
$ps-columns: 12 !default;
$ps-gutter: 0.5rem !default;
/**
* Break point namespace object
*