Skip to content

Instantly share code, notes, and snippets.

View daigotanaka's full-sized avatar
😎
https://handoff.cloud

Daigo Tanaka daigotanaka

😎
https://handoff.cloud
View GitHub Profile
@daigotanaka
daigotanaka / importer-for-evernote-mac
Last active August 29, 2015 14:05
AppleScript to import instapaper (or any list of URLs) to Evernote on Mac
-- See http://www.daigolab.org/instapaper-to-evernote-mac/ for instruction
-- Basic settings
set myNotebook to "Instapaper"
set delayInSeconds to 1
set giveUpAfter to 30
set oldToNewOrder to true
-- Function to make sure Evernote is up
to makeSureEvernoteIsUp(giveUpAfter)
tell application "Evernote" to activate
@daigotanaka
daigotanaka / gist:ad9c256f0620d23a9bb9
Created November 23, 2014 19:22
onename.io verification
Verifying that +daigo is my openname (Bitcoin username). https://onename.io/daigo
@daigotanaka
daigotanaka / rutils.py
Created November 24, 2014 22:55
rpy knit2.html example
import imp
def rmarkdown_page(page_id, **kwargs):
page = Page.objects.get(id=page_id)
if not RPY2_INSTALLED:
logger.info("rpy2 not found. I won't convert the raw text.")
return page.body
with open("/var/tmp/tmp.Rmd", "w") as f:
f.write(page.body)
ro.r("library('knitr');"
@daigotanaka
daigotanaka / rmd_caption_helper.R
Last active August 29, 2015 14:14
Rmarkdown caption tool
require(knitr)
render_caption = function(caption) {
paste('<p class="caption">', caption, "</p>", sep="")
}
knit_hooks$set(html.cap = function(before, options, envir) {
if(!before) {
render_caption(options$html.cap)
} else {
# Do nothing (or set isTable flag to render_caption at the top?
@daigotanaka
daigotanaka / rchart-helper.R
Last active August 29, 2015 14:14
rChart helper
# Modify stdout by rChart so I can customize tooltip and etc
require(rCharts)
renderChart = function (ct, chartId, include_assets = F, ...)
{
add_ext_widgets(ct$lib)
assetHTML <- ifelse(include_assets, paste(paste(add_lib_assets(ct$lib,
...), collapse = "\n"), "\n", add_style_(ct$params$width,
ct$params$height), collapse = "\n"), "")
chartDiv = render_template(ct$templates$chartDiv, list(chartId = chartId,
lib = ct$LIB$name, container = ct$container))
@daigotanaka
daigotanaka / subscriber-macro-example.clj
Last active August 29, 2015 14:27
Macro to define subscriber functions in ClojureScript
; the macro source
; To understand pub sub in clojure and ClojureScript, read this:
; https://yobriefca.se/blog/2014/06/04/publish-and-subscribe-with-core-dot-asyncs-pub-and-sub/
; define this in my-app/src/my-app/macros.clj
(ns my-app.macros)
(defmacro defsubfn
"Macro for subscriber function in pub-sub pattern"
[fnname channel body]
`(do
@daigotanaka
daigotanaka / cached_psql_query.r
Last active November 24, 2015 16:47
R: cache the values from PostgreSQL into RDS files for secondary accesses
# Caches the query result in rds file under `getwd()`/psql_cache.
# It assumes pg_host, pg_port, pg_dbname, pg_user, pg_password variables in the env.
# Remove the cache files if the update value is needed.
# Expire:
# positive integer n: Expire if the existing cache is older than n minutes
# 0: Expire now
# -1: Always use the existing cache if it exists
cachedPsqlQuery <- function(queryName, query, expire=-1, cachePath="./psql_cache") {
require(RPostgreSQL)
@daigotanaka
daigotanaka / multi-plot.R
Created November 25, 2015 00:45
Multi-plot
# Adopted from http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)
# And uploaded as gist for my personal use.
#
# Multiple plot function
#
# ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects)
# - cols: Number of columns in layout
# - layout: A matrix specifying the layout. If present, 'cols' is ignored.
#
# If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE),
@daigotanaka
daigotanaka / stepwise_vif.R
Created December 1, 2015 17:26
Stepwise VIF function
#stepwise VIF function
stepwiseVIF <- function(in_frame,thresh=10,trace=T){
require(fmsb)
if(class(in_frame) != "data.frame") in_frame <- data.frame(in_frame)
#get initial vif value for all comparisons of variables
vif_init <- NULL
for(val in names(in_frame)){
form_in <- formula(paste(val," ~ ."))
@daigotanaka
daigotanaka / uninstallpkg
Last active March 6, 2016 19:10
Uninstall things you installed with a pkg on Mac
#!/bin/bash
# Uninstall things you installed with a pkg on Mac
# Tested on El Capitan
# Please run this at your own risk
# Read: http://superuser.com/questions/36567/how-do-i-uninstall-any-apple-pkg-package-file
if [ "$EUID" -ne 0 ]
then
echo "Please run as root"