Skip to content

Instantly share code, notes, and snippets.

@kyo-ago
kyo-ago / gist:9873380
Created March 30, 2014 14:17
休日だけhueの操作を変えるGAS(作りかけ)
var account = {
'email': '',
'password': ''
};
var bridgeid = '';
var initializeParameter = {
'devicetype' : 'GAS',
'username' : 'newdeveloper'
};
@kyo-ago
kyo-ago / gist:8280903
Last active January 2, 2016 09:09
JavaScriptでDCI的なものを実装してみた例
// 銀行口座
var BankAccount = function (balance) { this.balance = balance; };
BankAccount.prototype.increase = function (money) { this.balance += money; };
BankAccount.prototype.decrease = function (money) { this.balance -= money; };
// ロール: 送信側
var Sender = function () {};
Sender.prototype.send = function (money, to) {
this.decrease(money);
to.onReceived(money, this);
trait Node {
val number: Int
def max: Int = this.number
def min: Int = this.number
def sum: Int = this.number
def avg: List[Int] = List(this.number)
def find(e: Int): Option[Node] = if (this.number == e) Some(this) else None
}
case class Branch(left: Node, number: Int, right: Node) extends Node {
override def max: Int = List(left.max, this.number, right.max).max
import scala.util._
def binarySearch(number: Int, numbers: List[Int]): Try[Int] = {
def Y[A,B]( f:((A => B), A ) => B, x:A ):B = f( (y:A) => Y(f,y),x)
Success(Y( (f: ((Int, Int)) => (Int, Int), n: (Int, Int)) => {
if (n._1 == n._2) return Failure(new NoSuchElementException)
((mid: Int) => {
((numbers(mid), number) match {
case (l, r) if l > r => f(n._1, mid)
case (l, r) if l < r => f(mid + 1, n._2)
case _ => (mid, -1)
'use strict';
module.exports = function (grunt) {
var _ = grunt.util._;
var esprima = require('esprima');
var licenseRegExp = /BSD|MIT|License/i;
grunt.registerTask('save-license', 'Save the license', function () {
this.files.forEach(function (file) {
var valid = file.src.filter(grunt.file.exists.bind(grunt.file));
_.difference(file.src, valid).forEach(function (filepath) {
@kyo-ago
kyo-ago / background.js
Created July 28, 2013 13:18
githubのCSPを消すbackground.js
chrome.webRequest.onHeadersReceived.addListener(function (details) {
for (var i = 0, l = details.responseHeaders.length; i < l; i++) {
var res = details.responseHeaders[i];
if (res.name.toLowerCase() !== 'content-security-policy')
continue;
res.value = '';
}
return {
'responseHeaders': details.responseHeaders
};
@kyo-ago
kyo-ago / extend.js
Created July 28, 2013 04:49
簡単extend(jQuery.extendと動作が違うので注意)
(function () {
var result = {};
[].slice.apply(arguments).forEach(function (val) {
Object.keys(val).forEach(function (key) {
result[key] = val[key];
})
});
return result;
})({1: 2}, {3: 4});
// Object {1: 2, 3: 4}
@kyo-ago
kyo-ago / userFilter.js
Created February 17, 2013 18:32
kleptoのuserFilter例
head = [
'HTTP/1.1 200 OK',
'Connection: close',
'Content-Length: 1',
'Content-Type: text/plain',
'Cache-control: private'
].join('\r\n');
body='1';
@kyo-ago
kyo-ago / gist:4950296
Last active December 13, 2015 17:48
Not properly indent in WebStorm.
// Before WebStorm AutoIndent
({
'method': function () {
}
}).method(function () {
// hoge
});
/* After WebStorm AutoIndent
({
'method': function () {