Skip to content

Instantly share code, notes, and snippets.

@voidfiles
voidfiles / actionQueue.js
Created November 27, 2011 19:42
actionQueue
(function(A) {
var registered_ids = {},
id_to_module_map = {},
interim_actions = {},
cleanup_actions = {},
clicked_ids = {},
queueing = {};
function register_id(id, callbacks, required_module) {
id = id.replace('*', '.*');
@voidfiles
voidfiles / awesome.md
Created December 10, 2011 19:25
actionQueue part two: in practice

In part two of before your scripts load series we are going to figure out how to use the techniques that Flickr uses to handle this problem. To recap, if we use an async JS loader, or even if we just put our script tags at the bottom of our pages we have a problem. The is potential for a user to interact with the page before the code loads. This means there might not be any code around to handle what the user just did.

Flickr uses something they call an actionQueue, and there code to do that is in a very tight, isolated bunch of code. With very little modification I think we could use that exact same piece of code. We are going to build a simple webpage that exercises the code. To start we need to make a few changes to the original code so that we could have multiple modules loading instead of just one.

Note: I am using QUnit to run the tests

The code:

https://gist.github.com/1398040

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Z-Index Example</title>
<style>
@font-face {
font-family: 'Win95F';
src: url('data:application/font-woff2;base64,d09GMk9UVE8AAB7IAAoAAAAAfLQAAB54AAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAADYHcRQZgAIpcATYCJAOFAAQGP21ldGGCBAWHeQcgG/17FeyYl7gdUKg+MzYSIWwchCaAJ1GUTdZM2f+fEtQxhLpXsjlMOBl1rtM5kVqBMp1XeGh4M/bhm1fyGODBICrJYyX3cIpIfVYz8+zf7k/1poo76F5SyxV35u42RuK58Pyzv//2ufiSI5FINEWNWcddrlPZZr353F4vNRtmfpL6FyCmfDO+2gEHHHZoxKaa7jrsXaZOHea+XXQOfP8/9vs9cxcVqniikQnZQ7JE62SzSFJJlfXTq1/snkEVLh3bgX9wrpvZrHU6h4r8an+wJ/mf+G0eKltj8Y0CE6MTzFphsWCV6tY3xQxWaSyijN4a1jYsZYEPgty2j1NBvFO5ztS8L7nCE3R9JjsC1hSKoT3X3uY/v7/vz137WW3kOP6K38nIPwlujGIbNkGXOwLg//99U20JOQ0Yh4DD0LlU0bhPcFDIsBzy6t0Td7+5d9mjCFAJA0VwEQ4h4M07M9/hM0P5S4sBznkkVa5S5dxVIbUt2bl0SRWdWndyVbjrtXoXfWko9Ixf8mAlKsgL1qjQb5oCz6Y4siXFEeB8+MN2upYd8LuBdoR/31iLxhoVBZhAB3bnZRRIIKn3s59aH/bm9DqFEgRElDEz/m5qk9vHmEbteKX0j35isACCAoJ0hS2/QNAEEf
@uprime22
uprime22 / makeFilename.js
Last active May 5, 2024 17:16
適当な文字列から、半角英数日本語ピリオド以外を除きファイル名に使えそうな文字列を再構築する正規表現
function makeFilename(s){
var filename =
s.replace(/[^\.A-Za-z0-9\u30e0-\u9fcf\u3040-\u309f\u30a0-\u30ff]/gi, '');
return (filename);
};
@uprime22
uprime22 / Bookmarklet_Open_in_googleweblight_com.js
Last active May 5, 2024 17:16
Bookmarklet: Open in googleweblight.com
javascript:var%20h=location.href;var%20u='http://googleweblight.com/?lite_url='+h;location=u;
@voidfiles
voidfiles / gist:2289046
Created April 3, 2012 03:22
Simplenotes new iOS URL scheme
Hey Alex, there aren't any docs yet. Here's the info:
simplenote://new?content=encodedContent&tag=encodedTag
The parameters are optional. If omitted, Simplenote will open to a new, blank note.
@voidfiles
voidfiles / textrank.py
Created January 20, 2012 08:22
An implmentation of TextRank in python
"""
From this paper: http://acl.ldc.upenn.edu/acl2004/emnlp/pdf/Mihalcea.pdf
I used python with nltk, and pygraph to do an implmentation of of textrank.
for questions: http://twitter.com/voidfiles
"""
import nltk
import itertools
@voidfiles
voidfiles / js_hint_conf.js
Created December 17, 2011 08:21
JSHint conf options
{
// Settings
"passfail" : false, // Stop on first error.
"maxerr" : 10000, // Maximum error before stopping.
// Predefined globals whom JSHint will ignore.
"browser" : true, // Standard browser globals e.g. `window`, `document`.
"node" : false,
@voidfiles
voidfiles / jquery.ui.draggable.js
Created December 17, 2011 07:08
ussing css3 transitions to do jquery draggable
/*
* jQuery UI Draggable @VERSION
*
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* http://docs.jquery.com/UI/Draggables
*
* Depends:
@voidfiles
voidfiles / edits.md
Created December 14, 2011 22:10
Edits
layout title author categories
post
Flickr's Asynchronous Script Loading Part 2
Alex Kessinger
events
dom
code-review
flickr-async