Skip to content

Instantly share code, notes, and snippets.

View dai-shi's full-sized avatar

Daishi Kato dai-shi

View GitHub Profile
@dai-shi
dai-shi / benchmark-startswith.js
Created February 14, 2013 03:51
benchmark of String.startsWith equivalents in Node.js
var Benchmark = require('benchmark');
Benchmark.prototype.setup = function() {
a = ["test"];
for (var i = 0; i < 10000; i++) {
a.push("some other stuff");
}
s = a.join();
re1 = new RegExp("^test");
re2 = new RegExp("^not there");
};
@dai-shi
dai-shi / benchmark-lastindexof.js
Created March 11, 2013 10:57
benchmark of String.lastIndexOf in Node.js
var Benchmark = require('benchmark');
Benchmark.prototype.setup = function() {
a = ["test"];
for (var i = 0; i < 10000; i++) {
a.push("some other stuff");
}
s = a.join();
};
var suite = new Benchmark.Suite();
@dai-shi
dai-shi / benchmark-simpleregex.js
Last active December 14, 2015 23:59
benchmark regex.test, string.match, and string.search
var Benchmark = require('benchmark');
Benchmark.prototype.setup = function() {
s = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxtestyyyyyyyyyyyyyyyyyyyyy';
re = new RegExp('te[xs]t');
};
var suite = new Benchmark.Suite();
// add tests
suite.add('regex test', function() {
var r1 = re.test(s);
@dai-shi
dai-shi / rss-pipes-first10.js
Last active December 15, 2015 14:29
初めの10件に絞り込むフィルター #rsspipes
function rssPipesFilterFunction(articles) {
return articles.slice(0, 10);
}
/*
* Copyright (c) 2013 Daishi Kato
* Licensed under the MIT License
* http://www.opensource.org/licenses/mit-license.php
*/
@dai-shi
dai-shi / rss-pipes-keywords.js
Last active December 15, 2015 14:39
タイトルのキーワードで絞込みするフィルター #rsspipes
function rssPipesFilterFunction(articles) {
var keywords = ["ABC", "DEF", "GHI"];
var i, len = keywords.length;
var newArticles = [];
articles.forEach(function(article) {
if (article.title) {
for (i = 0; i < len; i++) {
if (article.title.indexOf(keywords[i]) >= 0) {
newArticles.push(article);
break;
@dai-shi
dai-shi / rss-pipes-no-ads.js
Last active December 15, 2015 14:48
AD,PRエントリを除去するフィルター #rsspipes
function rssPipesFilterFunction(articles) {
var newArticles = [];
articles.forEach(function(article) {
if (article.title && article.title.lastIndexOf('AD:', 0) != 0 && article.title.lastIndexOf('PR:', 0) != 0) {
newArticles.push(article);
}
});
return newArticles;
}
@dai-shi
dai-shi / rss-pipes-extract-link.js
Last active December 15, 2015 14:48
タイトルからURLを抜き出すフィルター #rsspipes
@dai-shi
dai-shi / rss-pipes-pickup-title.js
Last active December 15, 2015 19:18
タイトルのキーワードマッチでタイトルを目立たせる #rsspipes
function rssPipesFilterFunction(articles) {
var keywords = ["keyword01", "keyword02", "keyword03"];
var i, len = keywords.length;
articles.forEach(function(article) {
if (article.title) {
for (i = 0; i < len; i++) {
if (article.title.indexOf(keywords[i]) >= 0) {
article.title = "*** " + article.title;
break;
}
@dai-shi
dai-shi / kineticjs-test20130417.html
Created April 17, 2013 14:01
KineticJSでHelloWorld
<!doctype html>
<html>
<head>
<title>canvas test</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<style>
html, body {
@dai-shi
dai-shi / facebook-node-sdk-sample.js
Created April 22, 2013 13:33
A sample code to get an application access token using Thuzi / facebook-node-sdk.
var FB = require('fb');
FB.api('oauth/access_token', {
client_id: process.env.FACEBOOK_APP_ID,
client_secret: process.env.FACEBOOK_SECRET,
grant_type: 'client_credentials'
}, function(res) {
if (!res || res.error) {
console.log('error occurred when getting access token:', res && res.error);
return;