Skip to content

Instantly share code, notes, and snippets.

View patrickheng's full-sized avatar

Patrick HENG patrickheng

View GitHub Profile
@isaacs
isaacs / node-and-npm-in-30-seconds.sh
Last active March 8, 2024 02:11
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
@aslakhellesoy
aslakhellesoy / rounding.java
Created August 9, 2011 16:18
Rounding up and down to nearest multiple
/** round n down to nearest multiple of m */
long roundDown(long n, long m) {
return n >= 0 ? (n / m) * m : ((n - m + 1) / m) * m;
}
/** round n up to nearest multiple of m */
long roundUp(long n, long m) {
return n >= 0 ? ((n + m - 1) / m) * m : (n / m) * m;
}
@gre
gre / easing.js
Last active April 30, 2024 04:58
Simple Easing Functions in Javascript - see https://github.com/gre/bezier-easing
/*
* This work is free. You can redistribute it and/or modify it under the
* terms of the Do What The Fuck You Want To Public License, Version 2,
* as published by Sam Hocevar. See the COPYING file for more details.
*/
/*
* Easing Functions - inspired from http://gizma.com/easing/
* only considering the t value for the range [0, 1] => [0, 1]
*/
EasingFunctions = {
@conorbuck
conorbuck / angle-between-points.js
Created May 5, 2012 22:51
JavaScript: Find the angle between two points
var p1 = {
x: 20,
y: 20
};
var p2 = {
x: 40,
y: 40
};
@clavis-magna
clavis-magna / objectRotation.js
Created November 24, 2012 04:36
local and global rotation functions for THREE.js objects updated for recent revisions of THREE.js
//following two rotation functions are updated versions of code from: https://github.com/mrdoob/three.js/issues/1219
//updated to work in latest versions (r52 tested) of THREE.js
// Rotate an object around an axis in object space
var rotationMatrix
function rotateAroundObjectAxis( object, axis, radians ) {
rotationMatrix = new THREE.Matrix4();
rotationMatrix.makeRotationAxis( axis.normalize(), radians );
object.matrix.multiplySelf( rotationMatrix ); // post-multiply
object.rotation.setEulerFromRotationMatrix(object.matrix, object.order);
@dergachev
dergachev / GIF-Screencast-OSX.md
Last active May 2, 2024 05:55
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@finlaybob
finlaybob / normalmap.frag
Created March 10, 2013 00:37
Normal Map Fragment Shader
#version 400
layout( location = 0 ) out vec4 frag_main;
struct PointLight{
vec3 position;
vec3 ambient;
vec3 diffuse;
vec3 specular;
float shininess;
float intensity;
};
@adamcbrewer
adamcbrewer / webkit-css-mask.css
Created June 25, 2013 16:04
CSS: overflow/border-radius mask bug-thingy
/*
* There's a bug in Chrome/Safari using overflow:hidden with border-radius. This mask fixes it.
* Solution: http://stackoverflow.com/questions/5736503/how-to-make-css3-rounded-corners-hide-overflow-in-chrome-opera/10296258#10296258
*/
.masked {
position: absolute;
border-radius: 10px;
overflow: hidden;
/* this fixes the overflow:hidden in Chrome */
-webkit-mask-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAA5JREFUeNpiYGBgAAgwAAAEAAGbA+oJAAAAAElFTkSuQmCC);
@mbostock
mbostock / .block
Last active February 25, 2024 17:46
Closest Point on Path
license: gpl-3.0
@DanHerbert
DanHerbert / fix-homebrew-npm.md
Last active February 12, 2024 17:18
Instructions on how to fix npm if you've installed Node through Homebrew on Mac OS X or Linuxbrew

OBSOLETE

This entire guide is based on an old version of Homebrew/Node and no longer applies. It was only ever intended to fix a specific error message which has since been fixed. I've kept it here for historical purposes, but it should no longer be used. Homebrew maintainers have fixed things and the options mentioned don't exist and won't work.

I still believe it is better to manually install npm separately since having a generic package manager maintain another package manager is a bad idea, but the instructions below don't explain how to do that.

Fixing npm On Mac OS X for Homebrew Users

Installing node through Homebrew can cause problems with npm for globally installed packages. To fix it quickly, use the solution below. An explanation is also included at the end of this document.