このGistは以下のリポジトリへ移動されました。
以後、ここは更新されません。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
head = [ | |
'HTTP/1.1 200 OK', | |
'Connection: close', | |
'Content-Length: 1', | |
'Content-Type: text/plain', | |
'Cache-control: private' | |
].join('\r\n'); | |
body='1'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Before WebStorm AutoIndent | |
({ | |
'method': function () { | |
} | |
}).method(function () { | |
// hoge | |
}); | |
/* After WebStorm AutoIndent | |
({ | |
'method': function () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static function OnBeforeResponse(oSession: Session) | |
{ | |
if (oSession.uriContains('/fiddler.pac')) (function () { | |
var e = new Enumerator(GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")); | |
var ip = ""; | |
for(; !e.atEnd(); e.moveNext()) { | |
ip = e.item().IPAddress(0); | |
break; | |
} | |
oSession.utilSetResponseBody("function FindProxyForURL(url, host) { return 'PROXY "+ip+":8888'; }"); |