Skip to content

Instantly share code, notes, and snippets.

@kyo-ago
kyo-ago / gist:6e9e46791ea61c592831
Created July 28, 2014 08:59
server sent event test
var SSE = require('sse')
, http = require('http');
var server = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<html><head><title></title></head><body>');
res.write('<script src="https://raw.githubusercontent.com/Yaffle/EventSource/master/eventsource.js"></script><script>');
res.write('var es = new EventSource("/sse");es.onmessage = function (event) {alert(event.data);};');
res.write('</script></body></html>');
res.end();
// applicationCacheの更新を妨害する
Object.defineProperty(this,'applicationCache',{get:function(){return{}}});
(function () {
// AppCache上でlocation.hrefを読み込むとAppCacheの内容を読み込むため、「ブラウザは別URLと認識するが、サーバは同じコンテンツを返すURL」を作る
contentLoad(location.href+'/');
// 本来であればsubmit等のイベントもキャッチする必要がある
window.addEventListener('click', function (evn) {
var elem = evn.target;
while (elem.tagName.toLocaleLowerCase() != 'a') elem = elem.parentNode;
@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}