javascript hashtable
i needed an object that behaves similar to a AS3 Dictionary:
https://gist.github.com/pixelf3hler/8207913
DEAR READER

Love Begins
Stranger Things

roma★
Monterey Bay Aquarium
TVSTRANGERTHINGS

pixel skylines

ellievsbear
Three Goblin Art

★
art blog(derogatory)
Cosmic Funnies
d e v o n
let's talk about Bridgerton tea, my ask is open
trying on a metaphor
hello vonnie
One Nice Bug Per Day

tannertan36
Game of Thrones Daily
seen from United States

seen from France

seen from Türkiye
seen from Malaysia
seen from Nigeria

seen from United Kingdom
seen from Belgium

seen from United States
seen from Japan
seen from France
seen from Singapore
seen from United States

seen from United States

seen from Australia
seen from Netherlands
seen from United States
seen from United States

seen from Netherlands
seen from Türkiye

seen from Germany
@pixelf3hler
javascript hashtable
i needed an object that behaves similar to a AS3 Dictionary:
https://gist.github.com/pixelf3hler/8207913

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
passing functions to another thread in javascript
One thing that sucks about javascript workers is that the data you give them is copied rather than shared. Browsers use the structured clone algorithm defined in the HTML5 specs to accomplish that.
As you probably know, that algorithm isn't capable of cloning Function objects, so it's pretty useless in some cases. But there's a simple workaround if you need to pass a function to a worker thread:
// the worker code: function parseFunction(fnstr) { Â Â Â try{ Â Â Â Â Â Â var fn = Function(fnstr) Â Â Â }catch(err) { Â Â Â Â Â Â console.log("failed to build function from %s", fnstr) Â Â Â } Â Â Â return fn } self.onmessage = function(e) { Â Â Â var fn = parseFunction(e.data) Â Â Â fn() }
// the main thread: function serializeFunction(fn) { Â Â Â var fnstr = fn.toString().replace(/^function[^\)]*\)[^\{]*\{|\}$/g, "") Â Â Â return fnstr } function testFn() { Â Â Â console.log("called testFn in another thread!") } worker.postMessage(serializeFunction(testFn))
This example is really simple, but i guess you get the point. Passing strings to a worker thread works just fine, so you can call toString() on the function you want to pass to obtain its source code. After that you just need to remove everything from that string that doesn't belong to the function body. The worker thread on the other hand can use that string to recreate a similar function in its inner scope using the Function constructor. Functions created that way aren't clones since you can't assign a name to them..so testFn from the example is always anonymous in the worker, but that shouldn't matter in most cases. Note that this simplified example doesn't support functions with arguments, but the code can be easily adapted to do so.
If you're looking for a css extension that runs on the client-side without installing any additional software on the machine that runs your webserver, jss might be a solution.
jss allows you to mix css and javscript in a single file or style node
a simple way to clone your objects
javascript objects are always passed by reference, right? If you need a simple way to create a structured clone you can abuse a WebWorker to do your bidding:
(function(window, document, undefined) { window.URL = window.URL || window.webkitURL
var _worker, _codeBlob, _blobUrl, _workerCode = 'self.onmessage = function(e) { self.postMessage(e.data); }' function _createWorker() { Â Â if(!_worker) { Â Â Â _codeBlob = new Blob([_workerCode], { type: 'text/javascript' }) Â Â Â _blobUrl = window.URL.createObjectURL(_codeBlob) Â Â Â _worker = new Worker(_blobUrl) Â Â } } function copyAsync(obj, callback) { Â Â _createWorker() Â Â _worker.onmessage = function(e) { Â Â Â this.terminate() Â Â Â callback(e.data) Â Â } Â Â _worker.postMessage(obj) } window.copyAsync = copyAsync })(window, window.document)
the usage is more or less self-explanatory..just call it and pass the object you want to clone and a callback function like:
copyAsync(obj, function(clone) {
// do something...
})
the only drawback is that it only works asynchronously...but it's fast since it uses the browsers native structured cloning algorithm