Skip to content

Instantly share code, notes, and snippets.

View ykhs's full-sized avatar

Yukihisa Yamada ykhs

  • Autify, Inc.
  • Tokyo, Japan
View GitHub Profile
(function ($) {
$(function () {
// jQuery の要素集合をキャッシュ
var $slider_root = $('#slider'),
$slider_ul = $slider_root.find('ul'),
$slider_li = $slider_ul.find('li'),
sliderWidth = $slider_li.outerWidth(true) * $slider_li.size(),
viewWidth = 800;
@ykhs
ykhs / gist:1048792
Created June 27, 2011 12:49
オレオレ addEvent
function addEvent(element, type, handler, data, context) {
if (!element) { return false; }
if (!handler) { return false; }
context = context || element;
var fn = function (e) {
e = e || win.event;
var collection = Backbone.Collection.extend({
originalSync: Backbone.sync,
sync: function(method, model, options) {
var originalSuccess, cache;
if (method !== 'read') {
this.originalSync(method, model, options);
@ykhs
ykhs / flattenHeights.js
Created May 23, 2012 02:54
要素の高さ揃えたい
function flattenHeight(elements) {
var maxHeight, i, l, defaultView;
maxHeight = 0;
i = 0;
l = elements.length;
defaultView = document.defaultView || {};
if (defaultView.getComputedStyle) {
@ykhs
ykhs / gist:2949050
Created June 18, 2012 15:53
100数える
Array.apply(null, Array(100)).forEach(function(x, i) {
console.log(i + 1);
});
@ykhs
ykhs / gist:3027432
Created July 1, 2012 07:53
Shadow DOM Sample
<!DOCTYPE HTML>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title></title>
<!-- このスタイルは文書ツリー側に定義したものなので Shadow DOM 内部には適用されない。 -->
<style>
section.articleBox h1 {
color: black;
}
@ykhs
ykhs / genPassword.js
Created August 9, 2012 04:21
generate password like string
var password = [].reduce.call('AaBbCcDdEeFfGgHhiJjKkLMmNnPpQqRrSsTtWwXxYyz3456789', function(p, c, i, a) {
return p += a.replace(new RegExp(p.split('').join('|'), 'g'), '')[Math.floor(Math.random() * (a.length - p.length))];
}, '').substr(0, 16);
console.log(password);
@ykhs
ykhs / backcall-with-do-statement.ls
Created August 31, 2012 07:22
backcalls のスコープは `do` で制御できる
do
<-! $
initializeApp!
data <-! $.get 'ajaxtest'
$ \.result .html data
processed <-! $.get 'ajaxprocess', data
$ \.result .append processed
@ykhs
ykhs / colour_lovers_sass_palette.rb
Created April 7, 2013 09:57
www.colourlovers.com の palette を取得して Sass の変数定義の形へ整形
require 'net/http'
require 'rexml/document'
class Palette
attr_accessor :name, :url, :colors
def initialize(id)
@name = String.new
@url = String.new
@colors = Array.new
@ykhs
ykhs / domParse.js
Last active December 17, 2015 12:39
domParse = function(htmlString) {
var doc;
doc = document.implementation.createHTMLDocument('');
doc.body.innerHTML = htmlString;
return doc.body.firstChild;
};