Skip to content

Instantly share code, notes, and snippets.

View phillipalexander's full-sized avatar

Phillip Alexander phillipalexander

  • Galvanize
  • San Francisco
View GitHub Profile
@phillipalexander
phillipalexander / InspectorA.js
Created July 19, 2013 00:52
X-Ray Spectacles For Your JavaScript Objects
var xRay = function (obj, key, spaces) {
var i,
k,
keyTypeStr,
xrayResult,
indent;
key = key || "";
spaces = spaces || 1;
indent = "";
@phillipalexander
phillipalexander / defineProperty.js
Created July 22, 2013 01:19
Javascript Object.definePropery() method
var o = {}; // Creates a new object
// Example of an object property added with defineProperty with a data property descriptor
Object.defineProperty(o, "a", {value : 37,
writable : true,
enumerable : true,
configurable : true});
// 'a' property exists in the o object and its value is 37
// Example of an object property added with defineProperty with an accessor property descriptor
@phillipalexander
phillipalexander / d3.phylogram.js
Created July 26, 2013 18:55 — forked from kueda/d3.phylogram.js
Demonstration of two common tree visualizations using [d3](http://mbostock.github.com/d3) and [newick.js](https://github.com/jasondavies/newick.js). I hadn't found any examples of these kinds of right-angle trees so I figured I'd share. Input data is a Newick-formatted guide tree from a clustalw multiple sequence alignment on some cytochrome b s…
/*
d3.phylogram.js
Wrapper around a d3-based phylogram (tree where branch lengths are scaled)
Also includes a radial dendrogram visualization (branch lengths not scaled)
along with some helper methods for building angled-branch trees.
d3.phylogram.build(selector, nodes, options)
Creates a phylogram.
Arguments:
selector: selector of an element that will contain the SVG
{
"name": "flare",
"children": [
{
"name": "analytics",
"children": [
{
"name": "cluster",
"children": [
{"name": "AgglomerativeCluster", "size": 3938},
# These are my notes from the PragProg book on CoffeeScript of things that either
# aren't in the main CS language reference or I didn't pick them up there. I wrote
# them down before I forgot, and put it here for others but mainly as a reference for
# myself.
# assign arguments in constructor to properties of the same name:
class Thingie
constructor: (@name, @url) ->
# is the same as:
/*
Grep.js
Author : Nic da Costa ( @nic_daCosta )
Created : 2012/11/14
Version : 0.2
(c) Nic da Costa
License : MIT, GPL licenses
Overview:
Basic function that searches / filters any object or function and returns matched properties.
@phillipalexander
phillipalexander / InjectLib.coffee
Created August 8, 2013 19:39
inject a JS library into the current webpage
injectLib = do ->
scriptSrc = prompt('Source to inject')
head = document.getElementsByTagName('head')
body = document.getElementsByTagName('body')
target = if head? then head else body
scriptEl = document.createElement('script')
scriptEl.src = scriptSrc
target[0].appendChild(scriptEl)
console.log("injected: #{scriptSrc}")
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://npmjs.org/install.sh | sh
/**
* Annoying.js - How to be an asshole to your users
*
* DO NOT EVER, EVER USE THIS.
*
* Copyright (c) 2011 Kilian Valkhof (kilianvalkhof.com)
* Visit https://gist.github.com/767982 for more information and changelogs.
* Visit http://kilianvalkhof.com/2011/javascript/annoying-js-how-to-be-an-asshole/ for the introduction and weblog
* Check out https://gist.github.com/942745 if you want to annoy developer instead of visitors
*
#!/bin/bash
for FILE in `find . -name "*.js" -type f -o -path './node_modules' -prune -o -path './components' -prune`
do
if [ -e $FILE ] ; then
COFFEE=${FILE//.js/.coffee}
echo "converting ${FILE} to ${COFFEE}"
js2coffee "$FILE" > "$COFFEE"
else