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 / JavaScript.sublime-build
Created August 28, 2013 03:53
Sublime Text 3 JavaScript Build System
{
"cmd": ["node", "$file"]
, "selector": "source.js"
, "path": "/usr/local/bin"
, "working_dir": "$project_path"
, "variants":
[
{
"name": "Run",
"cmd": ["js2coffee", "$file"],
#depends on underscore
_.isConstructor = (thing) ->
if thing.name && thing.name[0].toUpperCase() == thing.name[0]
true
else
false
class Instrumentor
constructor: (namespace) ->
@phillipalexander
phillipalexander / ObjectCreationN8Nstyle.js
Created August 15, 2013 04:43
ObjectCreationN8Nstyle.js
var Stack = function() {
return Object.create(Stack.prototype, {
_storage: { value: [], writable: false, configurable: false }
});
};
Stack.prototype = Object.create(null);
Stack.prototype.add = function(element) {
// ...
copy = function(str, mimetype) {
document.oncopy = function(event) {
event.clipboardData.setData(mimetype, str);
event.preventDefault();
};
document.execCommand("Copy", false, null);
}
#!/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
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
@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}")
/*
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.
# 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:
{
"name": "flare",
"children": [
{
"name": "analytics",
"children": [
{
"name": "cluster",
"children": [
{"name": "AgglomerativeCluster", "size": 3938},