Skip to content

Instantly share code, notes, and snippets.

@phiggins42
phiggins42 / ast-test.js
Created September 1, 2021 12:39
AST Goodtimes?
// Trying to use AST do determine _possible_ all calls to
// `Foo.prototype.emit`.
// I think I want to walk CallExpressions and look for
// property.name === 'emit', which seems accurate enough
// if not maybe giving false positives in mixed code with
// actual EventEmitters and otherwise?
class Foo {
@phiggins42
phiggins42 / .zshrc
Created November 27, 2013 15:01 — forked from SlexAxton/.zshrc
gifify() {
if [[ -n "$1" ]]; then
if [[ $2 == '--good' ]]; then
ffmpeg -i $1 -r 10 -vcodec png out-static-%05d.png
time convert -verbose +dither -layers Optimize -resize 600x600\> out-static*.png GIF:- | gifsicle --colors 128 --delay=5 --loop --optimize=3 --multifile - > $1.gif
rm out-static*.png
else
ffmpeg -i $1 -s 600x400 -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > $1.gif
fi
else
function each(ar, cb){
for(var i = 0, l = ar.length; i < l; i++){
cb.call(ar[i], i, ar);
}
}
function jerkify(obj, methods, thres){
each(methods, function(meth){
var orig = obj.prototype[meth];
orig && obj.prototype[meth] = function(){
@phiggins42
phiggins42 / attachpoint.js
Created June 3, 2013 16:15
mixin for widget
function attachpoint(selector){
return function(){
return this.$(selector);
}
}
// eg:
declare(WidgetBase, {
$: function(selector){
return query(selector, this.domNode);
define([
"dojo",
"dijit",
"dijit/_Templated"
], function(dojo,dijit,_Templated){
/*
mustache.js — Logic-less templates in JavaScript
See http://mustache.github.com/ for more info.
<!DOCTYPE html>
<html>
<head>
<script>
var list = [0, -1, 1, -1, 0, null, 1];
var sorter = function(direction){
// returns a sort function which treats `null` as a special case, either 'always higher' (1)
// or 'always lower' (-1)
@phiggins42
phiggins42 / checkwriting.js
Created April 3, 2012 14:07
A handy way to convert your dollar values to an unreadable base 16 variant.
function zero(n){
n = n.length == 1 ? n + "0" : n;
return +n;
}
function dollarsToHex(total){
var parts = total.toString(10).split(".");
return parts.map(function(part){
return zero(part).toString(16);
define(["dojo"], function(dojo){
return function(node, command, args){
// summary: a magic function
// example:
// magic("foo", "byId");
// example:
// magic(widget, "connect", "onClick", function(e){ })
// example:
// magic("bar", "style", { color: "red" });
String.prototype.repr = function(n){
return Array(n + 1).join(this);
}
String.prototype.lpad = function(/* Int */ length, /* String */ pad){
// summary: left pad this string to become `length` using an optional `pad` character
return (pad || " ").repr(length - this.length) + this;
}
String.prototype.rpad = function(length, pad){
Making output directory...
source/dojox/html/metrics.rst:5: ERROR: The API Could not be fetched for dojox.html.metrics
[]
source/dojox/html/styles.rst:5: ERROR: The API Could not be fetched for dojox.html.styles
[]
source/dojox/rpc/JsonRPC.rst:5: ERROR: The API Could not be fetched for dojox.rpc.JsonRPC
[]