Skip to content

Instantly share code, notes, and snippets.

View dgopstein's full-sized avatar

Dan Gopstein dgopstein

View GitHub Profile
@sunng87
sunng87 / reflection.clj
Created November 20, 2015 10:04
clojure: access private field/method via reflection
(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))))
@madvas
madvas / partial-right.clj
Created June 13, 2015 12:40
Clojure partial-right (Like a partial, but arguments are added to the end)
(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]
@Jfortin1
Jfortin1 / darken.R
Last active September 2, 2023 20:42
Darken or lighten colors in R
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)
# -*- 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)
@dmt
dmt / collection-type-multi.clj
Created July 21, 2011 09:47
multi-method collection type
(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 {})
@gus
gus / index.txt
Created November 30, 2009 21:55 — forked from toothrot/index.txt
Ruby/Clojure analogs
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: