Skip to content

Instantly share code, notes, and snippets.

@honbin
honbin / gist:1883443
Created February 22, 2012 08:39
クロージャのサンプル(ulのmemberクラスにli要素を生成して、クリックイベントをはる。jquery利用)
/**
* HTMLはこんな感じ
* <html>
* <head>
* <meta charset="UTF-8" />
* <title>クロージャの勉強</title>
* <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
* </head>
* <body>
* <ul class="member"></ul>
@honbin
honbin / gist:1937694
Created February 29, 2012 04:23
ファサードパターンお勉強1
//引用URL:http://addyosmani.com/resources/essentialjsdesignpatterns/book/
var module = (function() {
var _private = {
i:5,
get : function() {
console.log( 'current value:' + this.i );
},
set : function(val) {
this.i = val;
},
@honbin
honbin / gist:1937994
Created February 29, 2012 05:03
イベントハンドラの共通化
// htmlがこんな感じだとして
// <div id='hoge'>hoge</div>
//
var addEvent = function(elName, ev, fn) {
var el = document.getElementById(elName);
if(el.addEventListener) {
el.addEventListener(ev, fn, false);
} else if(el.attachEvent){
el.attachEvent('on' + ev, fn);
} else {
@honbin
honbin / gist:1938826
Created February 29, 2012 07:18
sigletonパターン勉強1
//引用http://addyosmani.com/resources/essentialjsdesignpatterns/book/
var Singleton = (function(){
var instantiated;
function init (){
// singleton here
return {
publicMethod: function(){
console.log( 'hello world' );
},
publicProperty: 'test'
@honbin
honbin / gist:1939071
Created February 29, 2012 08:09
カリー化のお勉強
//sum(10)(10) → 20
function sum(x, y) {
return x + y;
}
funtion c_sum(x) {
return function(y) { return sum(x,y); }
}
@honbin
honbin / gist:1992718
Created March 7, 2012 11:57
イベント管理(coffeeスクリプトのお勉強)
class EventManager
constructor: ()->
@list = {}
set: (elmName, event, fnc) ->
@list[elmName] = @list[elmName] || {}
@list[elmName] =
elO:document.getElementById elmName
ev:event
fn:fnc
//投稿
// @url /posts/:id
var posts = {
id: "", // 投稿のID (Mongo[ORMapper]の仕様に合わせる)
img: "http://example.com/iamges/foo.png", // 画像のURL
body: "", // 投稿文
tags: [ // Tagの情報
{ id: "1", name: "Ruby" },
{ id: "4", name: "JavaScript" },
{ id: "6", name: "Python" }
@honbin
honbin / gist:2927815
Created June 14, 2012 03:00
jquery.validate 使い方
//参考サイト:http://d.hatena.ne.jp/sugyan/20090312/1236815025
// http://d.hatena.ne.jp/kudakurage/20091211/1260521031
//独自バリデーション追加方法
jQuery.validator.addMethod("isKatakana", function(value, element) {
return this.optional(element) || /^([ァ-ヶーァ-ン゙゚]+)$/.test(value);
}, "カタカナで入力してください"
);
//バリデーション設定方法
@honbin
honbin / gist:2972021
Created June 22, 2012 10:45
ajaxzipの引数thisをディープコピーしてvalueの値を半角数値にして返す
(function($) {
convertHalfwidthNum = function(obj) {
var cObj = $.extend(true, {}, obj);
var str = '';
var v = cObj.value;
var len = v.length;
for (var i = 0; i < len; i++) {
var c = v.charCodeAt(i);
if ((c >= 65296 && c <= 65305))
str += String.fromCharCode(c - 65248);
@honbin
honbin / gist:3065535
Created July 7, 2012 08:49
担当エリアの担当者名を出力するサンプル
<?php
$area = "setagaya";
$area_list = array(
1 => "setagaya",
2 => "sinagawa"
);
$staff_list = array(