Skip to content

Instantly share code, notes, and snippets.

@ishiduca
ishiduca / gist:2533833
Last active October 3, 2015 22:27
Ginger::Cookies
package Ginger::Cookies;
use strict;
use Carp;
use List::Util qw(reduce);
use Data::Clone qw(clone);
require Exporter;
our $VERSION = '0.01';
our @ISA = qw(Exporter);
@ishiduca
ishiduca / gist:2593889
Created May 4, 2012 10:25
テスト用のwebsocketserver
// server.js * this file
// /public/
// index.html
// /js/
// fuga.js
// hoge.js
// /css/
// /img/
// /etc/
var WSS = require('ws').Server
@ishiduca
ishiduca / AnyEvent::WebService::ComicZin.pm
Created May 15, 2012 01:45
Meta::Doujin::Search - WebSocket(Web::Hippie) + Dancer + Twiggy
package AnyEvent::WebService::ComicZin;
use strict;
use utf8;
use Encode;
use Carp;
use parent qw(AnyEvent::WebService::ToranoAna);
use URI::Escape;
use Web::Scraper;
our $VERSION = '0.01';
@ishiduca
ishiduca / Command.js
Created May 22, 2012 09:05
ライン文字列をパースし、その結果ごとに何かをさせる
function Command () { this.map = []; }
(function (cp) {
cp.set = function (pattern, cb) {
if (typeof cb !== 'function')
throw new Error('2nd argument must be "function"');
if (typeof pattern !== 'string' && ! pattern instanceof RegExp)
throw new Error('1st argument must be "string" of "regexp"');
this.map.push([ pattern, cb ]);
return this;
};
@ishiduca
ishiduca / Dancer_Response_Object.pl
Created May 26, 2012 12:38
streaming on Dancer...
use strict;
use warnings;
use Dancer;
get '/' => sub {
my $resp = Dancer::Response->new(
content_type => 'text/plain',
content => "1234567890",
);
$resp->streamed(sub {
#!/usr/bin/env perl
use strict;
use warnings;
package Nodedoc;
use Carp;
use Path::Class qw(file dir);
our $VERSION = "0.04";
@ishiduca
ishiduca / mongoose-users.js
Created July 10, 2012 03:12
mongooseやり直し #mongoose #MongoDB #Node.js
"use strict"
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, mongodb = 'mongodb://localhost'
, db_name = 'Test'
, db = [ mongodb, db_name ].join('/')
, collection = 'users'
, crypto = require('crypto')
, hash_key = 'bd3dcffe8e4523ca98e80f51f5ec85c18d57ea87'
@ishiduca
ishiduca / mix.js
Created July 24, 2012 02:10
平坦なハッシュの合成とか、上書きとか、コピーとか
var a = { hoge: 'HOGE'
, fuga: 'FUGA'
};
var b = { foo : 'FOO'
, bar : 'BAR'
};
var new_mixed_hash = monkey.wrench(a, monkey.wrench(b));
// "new_mixed_hash" is
@ishiduca
ishiduca / render.js
Created September 4, 2012 00:44
EJS apply 'include'
'use strict';
var ejs = require('ejs');
var usersEjs = './views/users.ejs';
var users = require('fs').readFileSync( usersEjs, 'utf-8' );
console.log( ejs.render( users, {
filename: usersEjs // required
, title : 'TITLE'
, users : [ 'hoge', 'huga', 'foo' ]
@ishiduca
ishiduca / config.js
Created September 14, 2012 06:06
Searching embedded documents in MongoDB (mongoose)
'use strict';
module.exports = function (mongoose) {
mongoose = mongoose || require('mongoose');
var note = {
type: String
, required: true
};
var created = {
type: Date