Skip to content

Instantly share code, notes, and snippets.

@quidmonkey
quidmonkey / NotificationManager.js
Created July 5, 2011 15:28
NotificationManager for ImpactJS
/*
* Impact Plugin
* NotificationManager
* Written by Abraham Walters
* July 2011
* Jxyzzy Dev Company
* jxyzzy.com
*
* This plugin extends the Font class and allows you to pop-up a
* text Notification (spawnNote()), move it (this.pos) and have
@quidmonkey
quidmonkey / gist:5295797
Last active December 15, 2015 17:19
WebGL Shaders with Alpha
// vertex shader
attribute float a_alpha;
attribute vec2 a_position;
attribute vec2 a_texCoord;
uniform vec2 u_resolution;
varying vec2 v_texCoord;
void main () {
if (this.standing && ig.input.pressed('jump')) {
this.vel.y = -this.jumpVel;
} else if (this.vel.y < 0 && ig.input.state('jump')) {
this.vel.y -= this.smallJumpBoost;
}
@quidmonkey
quidmonkey / gist:5398041
Last active December 16, 2015 07:19
WebGL 2D Vertex Shader
<script id="2d-vertex-shader" type="x-shader/x-vertex">
precision lowp float;
attribute vec2 a_texCoord;
uniform vec2 u_resolution;
uniform float u_angle;
uniform vec2 u_pivot;
uniform vec2 u_scale;
@quidmonkey
quidmonkey / gist:5398063
Last active December 16, 2015 07:19
WebGL 2D Fragment (Texture) Shader
<script id="2d-fragment-shader" type="x-shader/x-fragment">
precision mediump float;
uniform sampler2D u_image;
uniform float u_alpha;
uniform vec4 u_frame; // x, y, width, height
varying vec2 v_texCoord;
@quidmonkey
quidmonkey / gist:5484715
Last active December 16, 2015 19:19
Fill Browser with a Small Canvas
var preserveAspectRatio = true;
function fillBrowser (canvas) {
if (preserveAspectRatio) {
var dWidth = window.innerWidth / canvas.width;
var dHeight = window.innerHeight / canvas.height;
var newWidth;
var newHeight;
if (dWidth < dHeight) {
@quidmonkey
quidmonkey / css
Last active December 17, 2015 15:18
Get Vendor Prefix for a CSS attribute
function css (css) {
var browser = window.navigator.userAgent.toLowerCase().match(/chrome|firefox|opera|msie|safari/)[0];
var attribute = browser === 'chrome' || browser === 'opera' || browser === 'safari' ? '-webkit-' + css :
browser === 'firefox' ? '-moz-' + css :
browser === 'msie' ? '-ms-' + css :
css;
var styles = document.documentElement.style;
if (typeof styles[attribute] !== 'undefined') {
return attribute;
@quidmonkey
quidmonkey / cpu.sh
Last active December 17, 2015 21:08
Bash Shell Script: Print CPU Usage for a Given Program to a Terminal
# !/bin/bash
while :; do
# grab process id for given arg
PID=$(ps aux | grep $1 | grep -v grep | grep -v cpu.sh | awk '{print $2}')
# grab cpu usage
USED=$(ps -p $PID -o %cpu)
# grab arg string length + 9
LEN=$(expr $(echo $1 | awk '{print length}') + 9)
# hack! print backspace mulitple times to erase previous input
for (( i=1 ; i<=$LEN ; i++ )); do
@quidmonkey
quidmonkey / gist:5711170
Last active December 18, 2015 02:29
A simple Javascript inheritance example
Function.prototype.extends = function (parent) {
var ctor = function () {},
proto = this.prototype;
ctor.prototype = parent.prototype;
this.prototype = new ctor;
this.prototype.constructor = this;
for (var key in proto) {
this.prototype[key] = proto[key];
@quidmonkey
quidmonkey / Default.sublime-command
Last active December 19, 2015 04:29
A Sublime Text 2 Plugin that will write a console.log of the selected Javascript on the line above or below. Suggested user key-binding is to use Ctrl+C+Up to create a console.log of the selected text above the current line, and Ctrl+C+Down to log to the line below. To install this plugin, create a jsLog/ directory in your Sublime Text 2 Package…
[{
"id": "jslog",
"caption": "Javascript Log",
"command": "js_log"
}]