Skip to content

Instantly share code, notes, and snippets.

View kozo002's full-sized avatar

kozo yamagata kozo002

View GitHub Profile
@kozo002
kozo002 / jquery.expsub.js
Created January 21, 2012 16:58
jQuery Expression substitution method
$.expsub = function(str, data) {
if (typeof str === 'string' && typeof data !== 'undefined' && typeof data === 'object') {
$.each(str.match(/(#{(?:.*?)})/g), function(i, match) {
replace = data[match.replace(/^#{|}$/g, '')];
if (typeof replace === 'function') replace = replace();
str = str.replace(RegExp(match), replace);
});
return str;
}
}
@kozo002
kozo002 / gist:1675584
Created January 25, 2012 09:19
JavaScript勉強会 2012/1/25
<script type="text/javascript">
function kansu(kansu) {
console.log('Hello');
}
function kansu2(kansu) {
kansu();
}
//kansu2(kansu);
@kozo002
kozo002 / wp-content_plugins_sample_sample.php
Created January 25, 2012 14:42
WordPress Pluginでテンプレートを操作
<?php
add_action('template_redirect', 'sample_action');
function sample_action() {
global $wp;
echo '<pre>';
var_dump($wp->query_vars);
echo '</pre>';
$template = _parse_request_uri($wp->query_vars);
@kozo002
kozo002 / array.js
Created February 3, 2012 09:55
JavaScript勉強会 2012/2/3
<script type="text/javascript">
var fruits = ['apple', 'banana'];
var index = 1;
console.log(fruits[index]);
var fruits2 = [['apple', 5], 'banana'];
console.log(fruits2[0][0]);
</script>
@kozo002
kozo002 / jasmine.css
Created February 18, 2012 16:56
Jasmine Custom Stylesheet
body {
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}
.jasmine_reporter a:visited, .jasmine_reporter a {
color: #303;
}
.jasmine_reporter a:hover, .jasmine_reporter a:active {
@kozo002
kozo002 / jquery.imageload.js
Created March 15, 2012 03:32
画像のonloadイベントを扱う際のjQuery拡張
(function($) {
var imageLoad = function(callback) {
var src, timestamp;
src = this.attr('src');
timestamp = new Date().getTime();
this.attr({src: src + '?' + timestamp});
return this.load(callback);
};
var createImageAndLoad = function(image_path, callback) {
window.Zenra = (function() {
function Zenra(user_config) {
var default_config = {
subjects: '私 僕 俺 君 わたし ぼく おれ きみ 貴方 あなた'.split(/\s/),
conjunctions: 'は が'.split(/\s/)
};
if (typeof user_config === 'undefined') {
user_config = {subjects:[], conjunctions:[]};
}
@kozo002
kozo002 / Post.php
Created June 26, 2012 16:04
Three table association on Cakephp
<?php
class Post extends AppModel {
var $hasOne = 'PostUser';
}
class QueryParameterConstraint
def initialize(*keys)
@keys = keys
end
def matches?(request)
result = false
@keys.each do |key|
result = request.query_parameters.has_key?(key)
break unless result
@kozo002
kozo002 / routes.rb
Created August 1, 2012 07:48
confirmationを使う場合にRESTfulっぽくなるようにしてみた
resources :products, only: [:index, :show]
namespace :products do
resources :registrations, only: [:new, :create, :edit, :update]
resources :confirmations, only: [:show, :update] do
get :completion, on: :collection
end
end
namespace :admin do