Skip to content

Instantly share code, notes, and snippets.

@ushiboy
ushiboy / DateToJSON.js
Created February 20, 2014 00:58
JSON.stringifyでタイムゾーン付けてDate送るとか。
Date.prototype.toUTCJSON = Date.prototype.toJSON;
Date.prototype.toJSON = function() {
var sep = this.toString().match(/\w{3}\s\w{3}\s(\d{2})\s(\d{4})\s(\d{2}:\d{2}:\d{2})\sGMT(\+\d{4})/);
return sep[2] + '-' + ('0' + this.getMonth()).slice(-2) + '-' + sep[1] + 'T' + sep[3] + sep[4];
};
@ushiboy
ushiboy / backbone.model.ext.js
Created May 27, 2014 13:32
BackboneのModelに付け足す
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define([
'underscore',
'backbone'
], function(_, Backbone) {
factory(root, _, Backbone);
});
} else if (typeof exports !== 'undefined') {
var _ = require('underscore'),
@ushiboy
ushiboy / index.html
Created June 9, 2014 22:38
blobとcontentTypeの関係
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Blob</title>
</head>
<body>
<input type="file" id="file-field">
<img id="preview" src="" alt="">
<script type="text/javascript">
function Hoge(name) {
this.name = name;
}
Hoge.prototype.greet = function() {
return 'Hello, ' + this.name;
};
Hoge.prototype.toJSON = function() {
var key, ret = { __meta__ : {} };
for (key in this) {
switch (typeof(this[key])) {
@ushiboy
ushiboy / app.js
Last active December 28, 2015 07:59
web+db pressに載ってたアイスクリームショップのサンプル
!function() {
'use strict';
// Model *****************************************************
var icecreamModel = {
list : [
{ id : 't1', name : 'バニラ' },
{ id : 't2', name : 'チョコレートチップ' },
{ id : 't3', name : 'オレンジシャーベット' },
@ushiboy
ushiboy / jobserve.js
Created November 16, 2013 13:34
ObjectのなんちゃってObservableみたいな。
function Observable(o) {
o._$eObj = $({});
var key,
fn;
for (key in o) {
fn = o[key];
if (typeof(fn) === 'function') {
o[key] = (function(_fn) {
return function() {
var ret = _fn.apply(o, arguments);
@ushiboy
ushiboy / index.js
Created November 17, 2013 13:46
workerのpostMessageの検証。Function混じらなければ文字列化の必要なかった。
var worker = new Worker('worker.js');
worker.addEventListener('message', function(evt) {
var meta = evt.data,
key;
for (key in meta) {
console.log(key + ':' + meta[key]);
}
}, false);
@ushiboy
ushiboy / class-spec.js
Last active December 28, 2015 17:49
車輪づくり。 ArrayやObjectの中までチェックするのどうしよう?
describe('class', function() {
var clazz = require('../src/class').clazz,
User = clazz('User', {
id : Number,
name : String,
birthday : Date,
owner : Boolean,
greet : function() {
return 'Hello ' + this.name();
}
// ==UserScript==
// @name ChatWork Image Extractor
// @description Image extractor for ChatWork.
// @include https://www.chatwork.com/*
// @version 0.0.1
// ==/UserScript==
(function() {
var forEach = Array.prototype.forEach,
ATTR_NAME_APPEND_IMG_DONE = 'data-append-img-done',
@ushiboy
ushiboy / index.php
Created February 26, 2016 13:48
Closure::bindTo warning
<?php
class Hoge
{
static function foo()
{
return function() {
echo "test";
};
}