Skip to content

Instantly share code, notes, and snippets.

View gist:7299747
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)
View gist:7292974
'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 Jul 28, 2013
githubのCSPを消すbackground.js
View 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 Jul 28, 2013
簡単extend(jQuery.extendと動作が違うので注意)
View extend.js
(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}
View 00_Deferred.js.md
@kyo-ago
kyo-ago / userFilter.js
Created Feb 17, 2013
kleptoのuserFilter例
View userFilter.js
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 Dec 13, 2015
Not properly indent in WebStorm.
View gist:4950296
// Before WebStorm AutoIndent
({
'method': function () {
}
}).method(function () {
// hoge
});
/* After WebStorm AutoIndent
({
'method': function () {
View background.js
var utils = {};
utils.ab2t = function (buffer) {
var arr = new Int8Array(buffer);
var str = "";
for(var i = 0, l = arr.length; i < l; i++) {
str += String.fromCharCode.call(this, arr[i]);
}
return str;
};
utils.t2ab = function (str) {
@kyo-ago
kyo-ago / appcache.js
Last active Oct 28, 2017
application cache loading js
View appcache.js
(function (app) {
var loading_class = 'loading';
var html = document.documentElement;
loading_class = ' ' + loading_class + ' ';
//未サポート
if (!app || app.UNCACHED === app.status) {
init();
return;
}
@kyo-ago
kyo-ago / gist:3853421
Created Oct 8, 2012
ChromeDriver経由でSeleniumIDEの内容を実行するJSサンプル
View gist:3853421
(function (d,s) {s=d.createElement('script');s.src = 'http://code.jquery.com/jquery-latest.js';d.body.appendChild(s);return s})(document).addEventListener('load', function () {var interval = setInterval(function () {
if (!jQuery) {
return;
}
clearInterval(interval);
load();
});
}, false);
function load () {
var sessionId, test_doc;