Skip to content

Instantly share code, notes, and snippets.

@Altech
Altech / query_set_v2.rb
Last active December 12, 2015 05:28
experimental API of gem to create many queries for TreasureData.
## Add Queries
queries = MMQueries.new do # the receiver is MMQueries.
# add query
# case0-0: one
add :count_users_inflow_source do |from, to|
%w[customers creators].each do |users|
td.query "SELECT * FROM #{users} WHERE #{specific_time(from,to)}", to: 'td://@/db/result'
end
@Altech
Altech / mmqueries.rb
Last active December 14, 2015 06:58
many-many-queries-API.rb
# queries.rb
queries = MMQueries.new do |config|
# Scope: Receiver is <MMQueries> here.
# add simple query and store the result
add :top_n_keyword_of_day do |date|
# Scope: Receiver is <MMQueries::Query> here.
td.query('SELECT * FROM search WHERE ...'){|result|
mongo.collection('search.keyword').insert(result.merge(date: date.to_time))
} # This block is a callback called at completion of the job
@Altech
Altech / programming_haskell.hs
Last active December 14, 2015 21:19
exercises of `programming haskell`
-- 1.7.3
product' [] = 1
product' (x:xs) = x * product xs
-- 1.7.4
qsort [] = []
qsort (p:xs) = qsort smaller ++ [p] ++ qsort larger
where
smaller = [x | x <- xs, x < p]
larger = [x | x <- xs, x >= p]
@Altech
Altech / note_generator.rb
Last active December 15, 2015 11:09
This class converts text notes to good-looking html in a particulr directory. It is possible to add format of source file.
require 'pathname'
require 'fileutils'
require 'tempfile'
require 'tmpdir'
require 'nokogiri'
require 'fssm'
require 'pry'
require 'colorize'
class Pathname
@Altech
Altech / access.sql
Created April 7, 2013 06:30
valid HiveQLs on TreasureData.
-- Schema: (
-- path:string
-- method:string
-- ip:string
-- agent:string
-- referer:string
-- )
-- count access per day
SELECT to_date(from_unixtime(time)) AS day, COUNT(*) AS cnt FROM access GROUP BY to_date(from_unixtime(time)) ORDER BY day ASC
@Altech
Altech / create_link.rb
Created April 9, 2013 13:11
a substitution of Chrome Extension `create link`.
@Altech
Altech / call_create_link.el
Last active December 16, 2015 00:09
use create_link.rb from Emacs.
@Altech
Altech / emacs-with-ghci.el
Created April 22, 2013 11:34
commands for interactive programming with GHCi in emacs.
(defun altech-define-haskell-hook ()
(defun code-to-list (str)
(split-string
(replace-regexp-in-string "^\n+" ""
(replace-regexp-in-string "\n+$" "" str)) "\n"))
(defun send-line-to-ghci (line)
(insert line)
(eshell-send-input)
@Altech
Altech / random_set_generator.rb
Last active January 12, 2016 04:54
ドミニオンのランダムセットジェネレーター(暗黒時代対応)。
# used packs
queried_packs = ["暗黒時代", "陰謀", "基本", "繁栄"]
target_list = eval(DATA.read)
.select{|k,v| queried_packs.include? k}
.map{|k,v| v.map{|s| [k,s]}}.flatten(1)
set = Hash.new
10.times do
@Altech
Altech / browse-function-document.el
Last active December 16, 2015 19:10
This command enable you to browse local Haskell document of the pointed function. It uses ghc-mod and hoogle-command.
;; **requirements** :: hoogle(cabal), ghc-mod(cabal,elisp)
(defun haskell-open-doc ()
(interactive)
(let ((sym (thing-at-point 'symbol)))
(let* ((list-string (shell-command-to-string (concat "hoogle " sym)))
(list (haskell-open-doc-select-candidate (remove-if 'haskell-open-doc-filter (haskell-open-doc-parse list-string)))))
(if list
(let ((mod (nth 0 list)) (fun (nth 1 list)) (type (nth 2 list)))
(haskell-open-doc-uri-with-uri-fragment (concat (ghc-display-document-without-browse (ghc-resolve-package-name mod) mod nil) "#v:" fun)))))))