Skip to content

Instantly share code, notes, and snippets.

@zhaocnus
zhaocnus / coordinateToPosition.js
Last active November 18, 2017 01:28
webgl-globe
export function coordinateToPosition(lat, lng, radius) {
const phi = (90 - lat) * DEGREE_TO_RADIAN;
const theta = (lng + 180) * DEGREE_TO_RADIAN;
return new THREE.Vector3(
- radius * Math.sin(phi) * Math.cos(theta),
radius * Math.cos(phi),
radius * Math.sin(phi) * Math.sin(theta)
);
}
@zhaocnus
zhaocnus / webgl-globe.js
Last active August 28, 2019 09:51
webgl-globe
import * as THREE from 'three';
import { geoInterpolate } from 'd3-geo';
const GLOBE_RADIUS = 200;
const CURVE_MIN_ALTITUDE = 20;
const CURVE_MAX_ALTITUDE = 200;
const DEGREE_TO_RADIAN = Math.PI / 180;
export function clamp(num, min, max) {
return num <= min ? min : (num >= max ? max : num);
@zhaocnus
zhaocnus / chrome.md
Last active March 6, 2017 20:12
Chrome

Check/update chrome flags

  • chrome://gpu
  • chrome://flags

Start Chrome with specific flags

  • Flags
    • --start-fullscreen
  • --kiosk
/**
* braces/brackets/parentheses validator
*/
function check(str) {
const closers = {
')' : '(',
'}' : '{',
']' : '['
};
const openers = {
@zhaocnus
zhaocnus / database.sh
Last active January 30, 2017 18:49
Database
# simple php server to serve adminer
php -S localhost:8000
// children propType
Foo.propTypes = {
children: PropTypes.oneOfType([
PropTypes.arrayOf(React.PropTypes.node),
PropTypes.node
])
}
// use react router in a component (if you have to)
import withRouter from 'react-router/lib/withRouter';
@zhaocnus
zhaocnus / git.sh
Last active January 24, 2018 07:56
# create local branch (shorthand)
git checkout -b <branch_name>
# create local branch
git branch <branch_name>
git checkout <branch_name>
# and then start hacking and commit
# push branch to remote
@zhaocnus
zhaocnus / nginx.conf
Last active March 10, 2017 03:40
Nginx config
# Serve static SPA
server {
listen 80;
root /home/young/src/www.example.com/;
index index.html;
server_name www.example.com;
location / {
@zhaocnus
zhaocnus / svn.sh
Created October 14, 2016 18:23
svn commands
# delete all locally missing files
svn st | grep ^! | awk '{print " --force "$2}' | xargs svn rm
# add all unversioned files to SVN
svn add --force * --auto-props --parents --depth infinity -q
# edit a ignore list on this folder
svn propedit svn:ignore .