Skip to content

Instantly share code, notes, and snippets.

@wolframkriesing
wolframkriesing / browser-js-stacktrace.js
Created July 29, 2011 22:13
Mini embeddable JavaScript stacktrace function (for the most relevant browsers)
// Create an error (normally you don't do that, but a try-catch :))
var e = new Error();
// Add a lineNumber and fileName property to the error in case there is none.
if (e.stack){ // Chrome has the "stack" property, but it's a rough string, parse out the lineNo and fileName.
var match = e.stack.split("\n")[1].match(/.*(http(s)?:\/\/.*):(\d+):(\d+)/);
if (match.length==5){ e.lineNumber = match[3]; e.fileName = match[1]; }
} else if (e.line && e.sourceURL){ // Safari has those
e.lineNumber = e.line; e.fileName = e.sourceURL;
}
@wolframkriesing
wolframkriesing / macro-JSON.stringify-selection
Created September 9, 2011 08:45
Komodo macro: replace a selected string 's' with 'JSON.stringify("s")'
// This is a macro for the IDE Komodo http://www.activestate.com/komodo-edit
var s = ko.views.manager.currentView.scimoz;
// If nothing was selected use {} ... dont know if useful, but we will see.
s.replaceSel("JSON.stringify("+ (s.selText || "{}") +")");
@wolframkriesing
wolframkriesing / gist:1544236
Created December 31, 2011 15:03
find vs. exec(find)
me@localhost:~> find /Applications/ -iname *.plist | wc -l
6660
me@localhost:~> node -e "require('child_process').exec('find /Applications/ -iname *.plist', function(_, stdout){ console.log(stdout.split('\n').length) })"
1806
// Why does the same find ran on the cmdline return a different number than when used via exec in node?
// Found the bug
// This works:
var dict = new Dictionary;
dict[runTests] = true;
var isFirstRun = true;
for (var key in dict) {
trace('key = ' + key);
if (isFirstRun) {
dict[this] = true;
isFirstRun = false;
}
delete dict[key];
var dict = new Dictionary;
dict[flash.display.ActionScriptVersion] = true;
var isFirstRun = true;
for (var key in dict) {
trace('key = ' + key);
if (isFirstRun) {
dict[flash.display.AVM1Movie] = true;
isFirstRun = false;
}
delete dict[key];
@wolframkriesing
wolframkriesing / gist:4354174
Created December 21, 2012 17:16
imho this shows that dictionary keys are sorted (even in the case of a namespace, as here flash.display there is an order, alphabetcially it seems) and the keys are walked, and if a key that is at the very first position (of that internal order) is added while iterating, it gets NOT visited in the looping. This is bad, i guess that is a bug in t…
/*
imho this shows that dictionary keys are sorted (even in the case of a namespace, as here flash.display
there is an order, alphabetcially it seems) and the keys are walked,
and if a key that is at the very first position (of that internal order) is added while iterating,
it gets NOT visited in the looping.
This is bad, i guess that is a bug in the ActionScript runtime.
It seems there is some comparison that breaks when it's index is 0 ...
let me know if I am wrong
var async = require('async');
async.parallel([
function(callback){
callback(null, 'one');
},
function(callback){
setTimeout(function() {callback(new Error('ONE'));}, 0);
},
function(callback){
var movieConfig = {
width: 550,
height: 400,
plugins: [
'//cdn.pixelplant.com/as3shim-latest.min.js',
'//cdn.pixelplant.com/as3vm-latest.min.js',
'//cdn.pixelplant.com/transwf-runtime-latest.min.js'
],
pluginDebug: false,
urls: ['movie.js'],
// inside app.js
export class App {}
// inside domUtil.js
import jQuery from 'jquery' // comes from the node_modules directory
export var domUtil = {}
// inside another file
import {App} from './app'
import {domUtil as domStuff} from './domUtil'
module.exports = {
entry: './src/main',
module: {
loaders: [
// Transpile any JavaScript file:
{ test: /\.js$/, loader: 'webpack-traceur?runtime&sourceMaps&experimental' }
]
},
resolve: {
// you can now require('file') instead of require('file.js')