Skip to content

Instantly share code, notes, and snippets.

View heavywatal's full-sized avatar

Watal M. Iwasaki heavywatal

View GitHub Profile
library(tidyverse)
library(furrr)
library(future)
future::plan("multicore")
L = 1000
M = 100
N = 200
w = rgamma(L, 1)
prob = w / sum(w)
@heavywatal
heavywatal / thread_pool.py
Last active December 21, 2022 08:36
Example of thread pool in Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Example of thread pool
https://docs.python.org/3/library/concurrent.futures.html
https://docs.python.org/3/library/multiprocessing.html
"""
import concurrent.futures as confu
import multiprocessing.pool as mpp
import time
@heavywatal
heavywatal / R_colors.R
Last active February 18, 2016 02:47
List colors with ggplot2
library(ggplot2)
library(dplyr)
library(stringr)
library(pipeR)
.data = data_frame(fill=colours()) %>>%
mutate(basename=str_extract(fill, '[^\\d]+'), number=extract_numeric(fill)) %>>%
dplyr::filter(!(basename %in% c('gray', 'grey') & (number %% 10 != 0))) %>>%
replace_na(list(number=0)) %>>%
arrange(basename, number) %>>%
@heavywatal
heavywatal / private.xml
Last active August 29, 2015 14:23
Karabiner private.xml for Emacs keybindings on RStudio
<?xml version="1.0"?>
<root>
<appdef>
<appname>RStudio</appname>
<equal>org.rstudio.RStudio</equal>
</appdef>
<item>
<name>RStudio</name>
<list>
<item>
@heavywatal
heavywatal / gist:2234887
Created March 29, 2012 08:15
MS Word Macros for Emacs keybind
Sub KillLine()
Selection.MoveDown Unit:=wdParagraph, Extend:=wdExtend
Selection.Cut
End Sub
Sub BackSpace()
Selection.TypeBackspace
End Sub
Sub Delete()
Selection.Delete
End Sub
@heavywatal
heavywatal / gist:2130242
Created March 20, 2012 02:24
allocate alphabets to indicate significance of the deferences among levels
signif_levels = function(tbl) {
colnames(tbl) = c("lhs", "rhs", "significant")
tbl$lhs = as.character(tbl$lhs)
tbl$rhs = as.character(tbl$rhs)
print(tbl); cat('\n')
output = data.frame(group=unique(c(tbl$lhs, tbl$rhs)), level=''
, stringsAsFactors=FALSE)
print(output$group); cat('\n')
nakama_list = list()
j = 1
@heavywatal
heavywatal / mi2term.scpt
Created March 19, 2012 06:45
Selected text in mi.app is executed on Terminal.app
#!/usr/bin/osascript
tell application "mi"
set CommandLines to selection of front document
end tell
tell application "Terminal"
activate
ignoring application responses
do script with command CommandLines in front window
end ignoring