Skip to content

Instantly share code, notes, and snippets.

@quidmonkey
quidmonkey / foo.js
Created February 5, 2016 18:20
How Do I Mock the DOM with Ava?
import jQuery from 'jquery';
export const attachEvents = someStr => {
jQuery(document).ready(e => {
// do something cool with someStr
});
};
@quidmonkey
quidmonkey / anonymous-es5.js
Last active January 12, 2016 21:54
JavaScript Anonymous Function Call Stack Test in ES5 & ES6
// anonymous function call stack test
// tested and works in chrome, ff, safari, node 4.2.2
// does not work in ie9 or ie11
var f = function f() { g(); };
var g = function g() { h(); };
var h = function h() { console.log(x) };
try {
f();
} catch (e) {
@quidmonkey
quidmonkey / uninstall_node.sh
Created January 7, 2016 16:55
Uninstall Node
# First:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
# To recap, the best way (I've found) to completely uninstall node + npm is to do the following:
#go to /usr/local/lib and delete any node and node_modules
cd /usr/local/lib
sudo rm -rf node*
@quidmonkey
quidmonkey / bower-components.js
Last active August 29, 2015 14:16
Get All Bower Components in Node
'use strict';
var fs = require('fs');
var globule = require('globule');
var path = require('path');
var bowerComponents = globule
.find('bower_components/**/bower.json')
.map(function (fileName) {
var bowerJson = fs.readFileSync(fileName);
@quidmonkey
quidmonkey / index.html
Last active March 22, 2024 19:05
Three.js Mandelbrot Demo
<!DOCTYPE html>
<html>
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/three.js/r67/three.min.js"></script>
</head>
<body>
<script id="mandelbrot-vertex" type="x-shader/x-vertex">
precision highp float;
uniform float zoom;
varying vec2 pos;
@quidmonkey
quidmonkey / JavaScriptExecuter.java
Last active August 29, 2015 14:02
Rhino Example to Execute a Javascript File - Run the following command: "java JavaScriptExecuter test.js"
import java.io.FileReader;
import java.io.Reader;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class JavaScriptExecuter {
public static void main(String[] args) throws FileNotFoundException, ScriptException, NoSuchMethodException {
@quidmonkey
quidmonkey / Gruntfile.js
Last active August 29, 2015 13:59
Changelogs for Grunt
grunt.registerTask('changelog', 'Create git changelog', function () {
var exec = require('child_process').exec;
var path = require('path');
var cmd;
var d = new Date();
var data = grunt.file.readJSON('build.json');
var now = d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate(); // yyyy-mm-dd
var since = grunt.option('since') || data.lastSince || now;
var targetFile = path.normalize(__dirname + '/changelogs/changelog_since_' + since + '.txt');
@quidmonkey
quidmonkey / decorator.js
Created March 1, 2014 15:17
Try/Catch Decorator Wrapper for Controller and Adapter/Interface
// controller proxy
for (var key in this.controller) {
if (this.controller.hasOwnProperty(key) && typeof this.controller[key] === 'function') {
this.proxyController(model.controller[key], key);
}
}
MvcAdapter.prototype.proxyController = function (method, key) {
this.controller[key] = function () {
try {
@quidmonkey
quidmonkey / proxy.js
Last active August 29, 2015 13:56
Node Proxy
// need to npm install http-proxy
require('http-proxy').createProxyServer({
port: 80, // if necessary
secure: false, // disable for self-signed certs
target: 'https://www.targetwebsite.com/'
}).listen(9000);
// boom baby, bye-bye development CORS issues!
@quidmonkey
quidmonkey / gist:8886439
Created February 8, 2014 16:42
Position Arrows on Either Side of Carousel
<footer>
<div class="jcarousel">
<ul>
<li><img src="1_designs_tab_images/designs_1.png"></li>
<li><img src="1_designs_tab_images/designs_2.png"></li>
<li><img src="1_designs_tab_images/designs_3.png"></li>
<li><img src="1_designs_tab_images/designs_4.png"></li>
<li><img src="1_designs_tab_images/designs_5.png"></li>
</ul>
</div>