This file contains hidden or 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
(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) |
This file contains hidden or 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
(setenv "PATH" (concat "<<PATH TO create_link.rb>>" ":" (getenv "PATH"))) | |
(require 'cl) | |
(defun create-link (url) | |
(interactive "sURL: ") | |
(let ((type (case major-mode | |
('markdown-mode "-t markdown") | |
('org-mode "-t org")))) | |
(insert (shell-command-to-string (concat "create_link.rb " type " " url))))) |
This file contains hidden or 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
#!/usr/bin/env ruby | |
# require `gem install nokogiri` | |
require 'nokogiri' | |
require 'open-uri' | |
require 'optparse' | |
opt = OptionParser.new |
This file contains hidden or 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
-- 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 |
This file contains hidden or 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
require 'pathname' | |
require 'fileutils' | |
require 'tempfile' | |
require 'tmpdir' | |
require 'nokogiri' | |
require 'fssm' | |
require 'pry' | |
require 'colorize' | |
class Pathname |
This file contains hidden or 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
-- 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] |
This file contains hidden or 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
# 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 |
This file contains hidden or 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
## 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 |
This file contains hidden or 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
# case1-1: one-to-one | |
QuerySet.add :count_users_inflow_source, ->(from, to) do | |
%w[customers creators].each do |users| | |
td.query('db',"SELECT * FROM #{users} WHERE #{specific_time(from,to)}"){|result| # queries are processed concurrently. | |
mongo.collection('collectionA').insert(cnt: result[0], type: uesrs) | |
} | |
end | |
end # return when all jobs finished. | |
# case1-2: many-to-one |
This file contains hidden or 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
(global-set-key (kbd "C-x C-c") 'close-on-mac) | |
(require 'cl) | |
(defun close-buffers-without-default () | |
(interactive) | |
(loop for buffer being the buffers | |
do ((lambda (buffer) | |
(if (and (not (string= (buffer-name buffer) "*GNU Emacs*")) | |
(not (string= (buffer-name buffer) "*scratch*")) | |
(not (string= (buffer-name buffer) "*Messages*"))) |