Skip to content

Instantly share code, notes, and snippets.

@subtleGradient
subtleGradient / loadAsyncScript.js
Created August 23, 2011 01:55
Safe loadAsyncScript implementation
function loadAsyncScript(URL) {
var script = document.createElement('script'),
firstScript = document.getElementsByTagName('script')[0];
script.async = 1;
script.src = URL;
firstScript.parentNode.insertBefore(script, firstScript);
}
loadAsyncScript('ext.js');
@subtleGradient
subtleGradient / prim.js
Created September 29, 2011 20:38
Minimal Object Pattern
exports.constructor = function(){}
exports.constructor.prototype = exports
exports.create = function(){
return this.constructor.apply(Object.create(this), arguments)
}
exports.property = 'foo'
@subtleGradient
subtleGradient / git-cherry-punch-ext4.sh
Created January 24, 2012 22:42
Convert a Git repo into a new Subversion repo using brute force commit copying
#!/usr/bin/env bash -l
die () {
echo "[ERROR] $@" 1>&2
exit 1
}
GIT_SRC="$HOME/Projects/Sencha/SDK"
GIT_ROOT="$GIT_SRC-copy"
SVN_REPO="$HOME/Projects/Sencha/sdk-svn-repo"
if [[ ! -d "$SVN_REPO" ]]; then
var regexp = LSD.RegExp({
'fn_tail': '\\.',
'fn_arguments': '\\g<inside_round>',
'fn_name': '\\g<unicode>',
'fn': '\\g<fn_tail>?\\g<fn_name>\\(\\g<fn_arguments>\\)',
'block_arguments': '\\g<inside_curly>',
'block_body': '\\g<inside_curly>',
'block': '\\{\\g<block_arguments>?\\g<block_body>\\}',
@subtleGradient
subtleGradient / README.md
Created July 19, 2012 13:01
How to create a double-click-to-start web server

How to create a double-click-to-start web server

  1. Download the "Start HTTP Server Here.command" file
    • In Safari you can do that by ⌥ (option) clicking the "raw" link next to that script.
  2. Add the executable flag
    so that it will run when you double-click it
    • type chmod +x "$HOME/Downloads/Start HTTP Server Here.command"
  3. Move the command file into the root folder of your website
  4. Double-click it to start your webserver.
    Your browser will load it up automatically
<element name="comment-form" constructor="CommentForm">
<template>
<form class="commentForm" onSubmit={this.handleSubmit}>
<input type="text" placeholder="Your name" ref="author" />
<input
type="text"
placeholder="Say something..."
ref="text"
/>
@subtleGradient
subtleGradient / index.js
Created June 5, 2013 19:25
MeeMoo.org DataFlow Graph from Quartz Composer QTZ file
var bplistParser = require('bplist-parser')
var bplistCreator = require('node-bplist-creator')
var fs = require('fs')
var DFGraph = {}
DFGraph.edgeFromQCConnection = function(qcConnection, connectionKey){
return {
source:{node: qcConnection.sourceNode, port:qcConnection.sourcePort},
target:{node: qcConnection.destinationNode, port:qcConnection.destinationPort}
@subtleGradient
subtleGradient / delete twitter DMs.js
Created July 8, 2013 02:07
Delete Twitter Direct Messages. Go here: https://twitter.com/messages?since_id=0 Then paste this stuff into your Chrome inspector console
// delete console.log
querySelectorAttempt._timerIDs = []
function querySelectorAttempt(selectors, callback, _attempts){
if (!Array.isArray(selectors)) selectors = selectors.toString().split(/\s*,\s*/)
console.log('querySelectorAttempt', selectors, _attempts)
if (_attempts == null) _attempts = 20;
var elements
selectors.forEach(function(selector){
if (elements && elements.length > 0) return;
elements = document.querySelectorAll(selector);
@subtleGradient
subtleGradient / watch.node.js
Created July 23, 2013 02:33
Usage: watch.node.js SomeFile.whatever "clear; time test.sh"
#!/usr/bin/env node
/*jshint asi:true*/
fs = require('fs')
child_process = require('child_process')
if (module.id == '.') watchForChangesAndThenExec(process.argv[2] || process.env.PWD, process.argv[3] || "echo")
module.exports = exports = watchForChangesAndThenExec
@subtleGradient
subtleGradient / Behavior.framer.js
Last active July 28, 2017 17:27
Simple Behavior sheet system for FramerJS. Allows you to apply pre-defined behaviors to your layers by changing the layer name. by Thomas Aylott (http://subtlegradient.com) Copyright 2013 Facebook. All rights reserved. MIT License.
function Behavior(PSD){
var _BehaviorNames = Object.keys(Behavior.behaviors)
.filter(function(BehaviorName){ return !!Behavior.behaviors[BehaviorName].namingPattern });
Object.keys(PSD).forEach(function(layerName){
var layer = PSD[layerName];
_BehaviorNames.forEach(function(BehaviorName){
var match = layerName.match(Behavior.behaviors[BehaviorName].namingPattern);
try {