Skip to content

Instantly share code, notes, and snippets.

@nanto
nanto / plack-middleware-env.pl
Created February 18, 2014 07:31
Run legacy applications which depend on environment variables.
package Plack::Middleware::ENV;
use strict;
use warnings;
use parent qw(Plack::Middleware);
sub call {
my ($self, $env) = @_;
my @fields = grep { m/^(?:HTTP.*|REMOTE_ADDR)$/ } keys %$env;
local @ENV{@fields} = @$env{@fields};
return $self->app->($env);
@nanto
nanto / content.tt
Created November 12, 2014 03:07
Text::Xslate::TTerse の undocumented な動作
Out of WRAPPER
[%- WRAPPER 'wrapper.tt' WITH arg1 = var, arg2 = 'literal' -%]
arg2: [% arg2 %]
[%- END -%]
@nanto
nanto / es6-draft-memo.txt
Last active August 29, 2015 14:19
ECMAScript 6 草案を斜め読みしていくメモ
https://people.mozilla.org/~jorendorff/es6-draft.html を参照する。
4.3.25
Symbol value が ES 6 で登場。
5.1.5
パラメータ化がたくさん。
// ==UserScript==
// @name bit.ly referred
// @namespace http://nanto.asablo.jp/blog/
// @include http://*
// @require http://svn.coderepos.org/share/lang/javascript/jsdeferred/trunk/jsdeferred.userscript.js
// ==/UserScript==
D = D();
const XHTML_NS = 'http://www.w3.org/1999/xhtml';
/*
* HTMLParser for Greasemonkey by snaka(http://d.hatena.ne.jp/snaka72/)
*
* Original coode written by swdyh(http://d.hatena.ne.jp/swdyh/)
* This code includes part of AutoPagerize(http://userscripts.org/scripts/show/8551)
*
* Released under the GPL license
* http://www.gnu.org/copyleft/gpl.html
*/
@nanto
nanto / read-selection.uc.js
Created February 19, 2010 04:07
A userChrome.js script to read selected text with js-ctypes.
// ==UserScript==
// @name Read Selection
// @namespace http://nanto.asablo.jp/blog/
// @description Read selection text.
// @include chrome://browser/content/browser.xul
// @author nanto_vi
// ==/UserScript==
({
// http://www.a-quest.com/products/aquestalk2.html
#!/usr/bin/perl
$i=1;
start:
goto print_fizz if $i % 3 == 0;
goto print_buzz if $i % 5 == 0;
print $i;
goto print_newline;
print_fizz: print 'Fizz';
goto print_buzz if $i % 5 == 0;
goto print_newline;
@nanto
nanto / consumer.pl
Created December 21, 2010 09:52
はてなブックマークの OAuth 対応 API 利用サンプル。 Run | $ perl consumer.pl daemon | and access http://localhost:3000/.
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use Mojolicious::Lite;
use OAuth::Lite::Consumer;
use XML::Atom::Feed;
use XML::Atom::Entry;
use URI::Escape qw/uri_escape_utf8/;
@nanto
nanto / router.js
Created July 4, 2012 16:51
Router: a router that can be combined with jquery.pjax.js
// Router: a router that can be combined with jquery.pjax.js [1]
//
// [1] https://github.com/defunkt/jquery-pjax
//
// This file is in the public domain.
//
//
// var router = new Router();
// $(document).on('pjax:end', function () { router.dispatch(location); });
// $(function () { router.dispatch(location); });
@nanto
nanto / jquery-deferred-test-runner.js
Created January 23, 2013 15:50
jQuery のビルドはできないが SpiderMonkey JavaScript Shell が利用できる環境で jQuery Deferred のテストを実行するためのスクリプト。
var window = this;
if (typeof JSON === 'undefined') {
this.JSON = {};
}
load('src/core.js');
load('src/callbacks.js');
load('src/deferred.js');
function module() {}