Skip to content

Instantly share code, notes, and snippets.

@kiyoto
kiyoto / google_adwords_to_td.js
Created April 1, 2016 23:29
Google Adwords Account Performance Daily Dump
CONSTANTS = {
tdAPIKey: 'YOUR_TD_API_KEY_HERE',
databaseName: 'adwords_reports',
tableName: 'sample_report',
timeColName: "Date",
timeLowerBound: Date.parse(new Date())/1000 - 7*86400,
timeUpperBound: Date.parse(new Date())/1000 + 3*86400
}
function validateDateColumn(o) {
@kiyoto
kiyoto / google_spreadsheet_to_td.js
Last active April 1, 2016 23:08
AppScript to copy Google Spreadsheet into Treasure Data
CONSTANTS = {
maxColumns: 1000,
rowsPerRead: 200,
maxRows: 100000,
tdAPIKey: 'YOUR_API_KEY',
databaseName: undefined,
tableName: undefined,
timeColName: "time",
timeLowerBound: Date.parse(new Date())/1000 - 7*86400,
timeUpperBound: Date.parse(new Date())/1000 + 3*86400
@kiyoto
kiyoto / gist:8131010
Created December 26, 2013 07:56
jls-grok error
2.0.0-p0 :006 > g = Grok.new
=> #<Grok:0x007f9b5aa85988>
2.0.0-p0 :007 > g.discover("hello")
NameError: uninitialized constant Grok::GrokDiscover
from /Users/owenestea/.rvm/gems/ruby-2.0.0-p0/gems/jls-grok-0.10.12/lib/grok.rb:127:in `init_discover'
from /Users/owenestea/.rvm/gems/ruby-2.0.0-p0/gems/jls-grok-0.10.12/lib/grok.rb:120:in `discover'
from (irb):7
from /Users/owenestea/.rvm/rubies/ruby-2.0.0-p0/bin/irb:16:in `<main>'
@kiyoto
kiyoto / fluentd-kibana-elasticsearch.conf
Last active December 29, 2015 09:59
An example config for Fluentd + Kibana 3 + ElasticSearch
<source>
type embedded_elasticsearch
</source>
<source>
type kibana_server
bind 0.0.0.0
port 24300
mount /kibana/
access_log_path var/log/kibana/access.log
C:/Ruby200-x64/bin/ruby.exe extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_thread_alone()... yes
checking for rb_str_set_len()... yes
checking for clock_gettime() in -lrt... no
checking for sys/select.h... no
checking for poll.h... no
checking for sys/epoll.h... no
checking for sys/event.h... no
checking for port.h... no
@kiyoto
kiyoto / fluentd-elasticsearch
Created August 2, 2013 21:06
fluentd configuration to gather data from Twitter and index them on Elastic Search
# Twitter input: See https://github.com/y-ken/fluent-plugin-twitter
<source>
type twitter
consumer_key YOU_CONSUTMER_KEY # Required
consumer_secret YOUR_CONSUMER_SECRET # Required
oauth_token YOUR_OAUTH_TOKEN # Required
oauth_token_secret YOUR_TOKEN_SECRET # Required
tag twitter.timeline # Required
timeline userstream # Required s(sampling or userstream)
#keyword SFGiants
@kiyoto
kiyoto / 140_bytes_not_chars
Created February 25, 2013 08:53
UTF-8 heavy languages like Japanese manage to pack in more meaning into 140 characters than English. Here is one farcical attempt to keep them honest: truncate the tweet after 140 bytes, not characters.
javascript:(function(d){
var tbox, text, len = 140, ii = 0;
tbox = d.getElementById('tweet-box-global');
if (!tbox) return;
if (!(tbox = tbox.firstChild)) return;
if (!(text = tbox.innerHTML)) return;
while (true) {
len -= encodeURI(text[ii]).replace(/%[A-F\d]{2}/g, 'U').length;
javascript:(function(d){
var cls, ii, cl, ct = 0;
cls = d.getElementsByClassName('discussion-bubble');
for (ii = 0; ii < cls.length; ii++) {
cl = cls[ii];
if (/IETF/i.test(cl.innerHTML)) {
cl.style.display = 'none';
ct++;
}
}
#!/bin/bash
repo=$1
project=$2
curl -sL https://api.github.com/repos/$1/$2/issues | perl -e '$nc=0; while(<>) { if(/"comments": (\d+)/ && ($nc < ($c=int($1)))) { $nc=$c; } } print "$nc\n";'
@kiyoto
kiyoto / grok.md
Last active October 21, 2015 05:19
Grok in Fluentd?

One of the common questions on Fluentd is "does Fluentd handle my log?" At the moment, the answer to this question comes down to one of the following three:

  1. Yes, with in_xxx plugin
  2. Yes, if you use in_tail with a custom regex
  3. Yes, if you extend an existing plugin or write a new one =p

While we can't expect to meet all needs with our core plugins (and that's why there are 3rd party plugins), we want to make things easier and simpler.

One idea that I've been thinking about is adding Grok-like parser. For those who don't know what Grok is, it's a regex macro library originally developed by Jordan Sissel (of Logstash). A big upshot here is that a lot of grok patterns have already been written, and we can immediately take advantage of them.