Skip to content

Instantly share code, notes, and snippets.

Shinichiro Aska s-aska

Block or report user

Report or block s-aska

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View localizer.js
// before html
// <html lang="ja">
// <span data-text-ja="タイムライン">Timeline</span>
//
// var localizer = new Localizer();
// localizer.localize();
//
// after html
// <span data-text-ja="タイムライン">タイムライン</span>
View sample_ajax_with_csft.js
// https://github.com/tokuhirom/Amon/blob/master/lib/Amon2/Plugin/Web/CSRFDefender.pm
function ajax(option) {
this.token_name = 'csrf_token'; // 実際は別のところでsetupしておく
if ("data" in option && "type" in option && option.type.toLowerCase() == 'post') {
if (!this.token) {
this.token = $('input[name=' + this.token_name + ']:first').val();
}
option.data[this.token_name] = this.token;
}
return $.ajax(option);
View sort.js
var lis = [];
this.parts.tasks.find('> li').each(function(i, ele) {
lis.push($(ele));
});
lis = lis.sort(function(a, b) {
return b.data('updated') - a.data('updated');
});
for (var i = 0; i < lis.length; i++) {
lis[i].appendTo(this.parts.tasks);
}
View MIME-Parser-Delux.pm
package MIME::Parser::Delux;
use strict;
use Encode;
use Encode::Alias;
use Encode::Guess qw/euc-jp shiftjis 7bit-jis/;
use File::Temp qw/ :seekable /;
use MIME::Parser;
use MIME::WordDecoder;
use MIME::Words qw(:all);
@s-aska
s-aska / delayHover.js
Created Jul 19, 2011
jQuery hover delay
View delayHover.js
function delayHover(element, over, out, delay) {
var timer;
$(element).hover(function(){
if (timer) {
clearTimeout(timer);
timer = null;
} else {
over.apply(this, arguments);
}
}, function(){
@s-aska
s-aska / gist:1094456
Created Jul 20, 2011
How to Build One Page Apps
View gist:1094456
How to Build One Page Apps
実サービス(9月下旬完成予定)を例にOne Page Appsの作り方を紹介します。
One Page Apps(Single Page Application)とは1枚のHTMLで構成されたWebアプリケーションでTweetDech等が有名です。
一日中開いたままでもバックグラウンドで同期が走り、必要に応じて通知やDOMの再構成が行われ、オフライン中の操作はスタックされ、通信回復後に再同期が行われる様なクライアントアプリケーションに非常に近い実装が必要になります。
実用的なアプリケーションにする為には標準のUIだけでは力不足ですし、開発効率を保つ為には肥大化しがちなJsコードをうまく整頓するコツも必要です。
View gist:1095068
function initElements(context) {
$('*[data-init]', context).each(function(){
var ele = $(this);
var methods = ele.data('init').split(',');
for (var i = 0, max_i = methods.length; i < max_i; i++) {
app.exec(['initElement', methods[i]], [this]);
}
});
}
function initElementClick(element) {
View test_psgi_error.t
# 500
test_psgi
app => builder {
enable "StackTrace", no_print_errors => 1; # no warning in make test.
MyApp->handler
},
client => sub {
my $cb = shift;
my $req = HTTP::Request->new( GET => 'http://localhost/foo/error' );
$req->header('Accept' => 'text/html'); # get stack trace message
View update_zip.pl
my $zip;
open my $fh, "<:encoding(cp932)", $ken;
while (my $row = $csv->getline($fh)) {
next if $zip->{$row->[2]};
$zip->{$row->[2]}++;
$model->insert( 'minotaur_zip', {
zip => $row->[2],
pref => substr($row->[0], 0, 2),
address1 => $row->[7],
address2 => $row->[8]
View blowfish.pl
#!/usr/bin/env perl
use strict;
use warnings;
use Crypt::CBC;
use Crypt::Blowfish;
my $key = shift;
my $val = shift;
You can’t perform that action at this time.