This file contains 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
(defn invoke-private-method [obj fn-name-string & args] | |
(let [m (first (filter (fn [x] (.. x getName (equals fn-name-string))) | |
(.. obj getClass getDeclaredMethods)))] | |
(. m (setAccessible true)) | |
(. m (invoke obj args)))) | |
(defn private-field [obj fn-name-string] | |
(let [m (.. obj getClass (getDeclaredField fn-name-string))] | |
(. m (setAccessible true)) | |
(. m (get obj)))) |
This file contains 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
(defn partial-right | |
"Takes a function f and fewer than the normal arguments to f, and | |
returns a fn that takes a variable number of additional args. When | |
called, the returned function calls f with additional args + args." | |
([f] f) | |
([f arg1] | |
(fn [& args] (apply f (concat args [arg1])))) | |
([f arg1 arg2] | |
(fn [& args] (apply f (concat args [arg1 arg2])))) | |
([f arg1 arg2 arg3] |
This file contains 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
darken <- function(color, factor=1.4){ | |
col <- col2rgb(color) | |
col <- col/factor | |
col <- rgb(t(col), maxColorValue=255) | |
col | |
} | |
lighten <- function(color, factor=1.4){ | |
col <- col2rgb(color) |
This file contains 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
# -*- coding: utf-8 -*- | |
require 'nokogiri' | |
require 'open-uri' | |
# Microsoft Academic Search APIを扱うためのクラス | |
class MsacademicApiWrapper | |
# 引数の論文IDに対応する論文のタイトルを返す | |
def self.get_title(id) | |
xml = get_paper_info(id) |
This file contains 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
(defmulti col-type class) | |
(defmethod col-type clojure.lang.PersistentList [_] :list) | |
(defmethod col-type clojure.lang.PersistentArrayMap [_] :map) | |
(defmethod col-type clojure.lang.PersistentVector [_] :vector) | |
(defmethod col-type clojure.lang.PersistentHashSet [_] :set) | |
(defmethod col-type :default [col] (if (seq? col) :seq :oops)) | |
(col-type []) | |
-> :vector | |
(col-type {}) |
This file contains 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
For each Ruby module/class, we have Ruby methods on the left and the equivalent | |
Clojure functions and/or relevant notes are on the right. | |
For clojure functions, symbols indicate existing method definitions, in the | |
clojure namespace if none is explicitly given. clojure.contrib.*/* functions can | |
be obtained from http://github.com/kevinoneill/clojure-contrib/tree/master, | |
ruby-to-clojure.*/* functions can be obtained from the source files in this | |
gist. | |
If no method symbol is given, we use the following notation: |