Skip to content

Instantly share code, notes, and snippets.

@kiyoto
kiyoto / collatz.markdown
Created May 1, 2016 09:10
The Collatz Conjecture in PostgreSQL

##QUERY (PostgreSQL 9.4)

WITH RECURSIVE t(n) AS (
  VALUES(1337)
  UNION ALL
  SELECT CASE WHEN n%2=0 THEN n/2 ELSE 3*n+1 END FROM t WHERE n > 1)
SELECT * FROM t
require 'fluent-logger'
# specify the host and port to forward data to
logger = Fluent::Logger.new(nil, :host => "localhost", :port => 24224)
fn = ARGV[0]
fh = File.new(fn)
msgpack_unpacker = MessagePack::Unpacker.new(fh)
@kiyoto
kiyoto / fluentd-etymology.markdown
Last active November 18, 2020 01:50
The Etymology of Fluentd

#"Why is it called Fluentd?"

My day (and night) job is to answer questions about Fluentd, and enough people have asked me why it's called that. It is not the easiest to pronounce. It is not mono- or bysyllabic. It's not the end of the world that it is trisyllabic, but you need to inunciate reasonably well to be heard correctly ("Wait, what is it? Flu..what?").

Yes, your guess is as good as anyone else's. It is pronounced as fluent-dee. Like "fluent" with a "d" tacked onto it.

Fluentd is called Fluentd because it wasn't called Fluentd on day one. Its initial name was "Fluent" (hence our repo owner's name), with the intent that this software should make streaming data from sources to sinks more "fluent". Less hassle, more extensibility, more reliability.

However, the author realized (or rather did not realize at first) that if you search for "fluent", you would get bazillion links to Rosetta Stone apps and their siblings. Fluency

@kiyoto
kiyoto / book_crossing_action_query.sql
Created July 23, 2012 22:13
Book Crossing Dataset Action Queries
-- Query 1: Counting Harsh, Generous and Lazy
td query -w -d book_crossing_dataset "
SELECT rating_type, COUNT(*) As cnt
FROM
(
SELECT user_id, MIN(book_rating) AS stat, COUNT(book_rating) AS cnt, 'Generous' AS rating_type
FROM ratings
WHERE 0 < book_rating
GROUP BY user_id
HAVING 5 < COUNT(book_rating)
@kiyoto
kiyoto / google_analytics_to_td.js
Last active September 9, 2019 17:39
Google Analytics Report into Treasure Data (for the previous day)
// See https://developers.google.com/analytics/devguides/reporting/core/v3/reference for how Core Reporting API works
// TODO: Filter by user segment, etc.
INPUTS = {
groupBy: ['country'],
metrics:['visits'],
sortBy:['visits'],
profileId: 'YOUR_GA_PROFILE_ID',
databaseName: 'google_analytics',
tableName: 'sample_report',
tdAPIKey: 'YOUR_TD_API_KEY'
@kiyoto
kiyoto / repo_names.txt
Created June 8, 2014 02:59
docker repo names
0718c7bf/fbtrack
0718c7bf/tomcat6java8
0x42/base
0xahmed/netcat
0xfa1a/centos-ssh
0xfa1a/dockerfiles
0xffea/raring-server-cloudimg-amd64
0xffea/saucy-server-cloudimg-amd64
0xffea/saucy-server-existdb-amd64
1uptalent/docker-registry
@kiyoto
kiyoto / lato.less
Created August 19, 2017 22:32 — forked from Drunkar/lato.less
slack for windowsで日本語フォントをnoto sans cjk jpに変更する。path: C:\Users\<ユーザ名>\AppData\Local\slack\app-<バージョン>\resources\app.asar.unpacked\src\static\lato.less
/*
This is a smaller variant of the new Lato2, serving compressed woff2 files.
Currently: TS-Only
Clients needs to have Lato2 pref turned ON.
The payload is 50% smaller. However, woff2 is not yet well supported,
so we're still providing the woff as fallback.
@kiyoto
kiyoto / tidy.ps1
Last active July 22, 2017 22:05
tidy download directory on windows
# tidy up the ~/Downloads directory
cd C:\Users\me\Downloads
$week_ago = (Get-Date).AddDays(-7)
dir | Select-Object {
$last_access = $_.lastAccessTime
if ($last_access -lt $week_ago) {
$path = "{0:yyyyMM}" -f $last_access
if (! (Test-Path $path)) { mkdir $path }
if ($_.FullName -notmatch "^20\d\d\d\d") { mv $_.FullName $path }
@kiyoto
kiyoto / error.log
Created August 11, 2016 07:08
Tried Fluentd on Bash on Windows.
2016-08-11 00:07:24 -0700 [error]: unexpected error error_class=Errno::EINVAL error="Invalid argument - recvmsg(2)"
2016-08-11 00:07:24 -0700 [error]: /home/kiyoto/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/serverengine-1.6.4/lib/serverengine/socket_manager_unix.rb:30:in `recv_io'
2016-08-11 00:07:24 -0700 [error]: /home/kiyoto/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/serverengine-1.6.4/lib/serverengine/socket_manager_unix.rb:30:in `recv_tcp'
2016-08-11 00:07:24 -0700 [error]: /home/kiyoto/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/serverengine-1.6.4/lib/serverengine/socket_manager.rb:37:in `listen_tcp'
2016-08-11 00:07:24 -0700 [error]: /home/kiyoto/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-0.14.2/lib/fluent/plugin/in_forward.rb:100:in `listen'
2016-08-11 00:07:24 -0700 [error]: /home/kiyoto/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-0.14.2/lib/fluent/plugin/in_forward.rb:68:in `start'
2016-08-11 00:07:24 -0700 [error]: /home/kiyoto/.rbenv/versions/2.3.1/lib
// Intimate Merger
!function(a,b,c,d){if(!b[a]){b[a]=function(){b[a].instances.push(this),this.init&&this.init()},b[a].instances=[];for(var e=0,f=["td_send","td_send_imid"];e<f.length;e++)b[a].prototype[f[e]]=function(a){return function(){this["tmp_"+a]=this["tmp_"+a]||[],this["tmp_"+a].push(Array.prototype.slice.call(arguments))}}(f[e]);var g=c.getElementsByTagName(d)[0],h=c.createElement(d);h.async=!0,h.src="//cf.im-apps.net/sdk/tdim-1.1.0.min.js",g.parentNode.insertBefore(h,g)}}("TDIM",window,document,"script");
!function(t,e){if(void 0===e[t]){e[t]=function(){e[t].clients.push(this),this._init=[Array.prototype.slice.call(arguments)]},e[t].clients=[];for(var r=function(t){return function(){return this["_"+t]=this["_"+t]||[],this["_"+t].push(Array.prototype.slice.call(arguments)),this}},n=["addRecord","set","trackEvent","trackPageview","ready"],s=0;s<n.length;s++){var i=n[s];e[t].prototype[i]=r(i)}var a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src=("https:"===document.locatio