Skip to content

Instantly share code, notes, and snippets.

View ymattu's full-sized avatar

Yuya MATSUMURA ymattu

View GitHub Profile
@ymattu
ymattu / latlong2mesh.sas
Last active July 15, 2017 05:59
緯度経度から標準地域メッシュコードを算出
libname sasfunc "X:\sastest" ;
proc fcmp outlib=sasfunc.functions.geo ;
function latlong2mesh(lat, long) ;
/* latitude */
lat_in_min = lat * 60 ;
code12 = int(lat_in_min / 40) ;
data foo;
input customer_number lat long;
datalines;
1 35.039200 135.728965
2 35.626065 139.884678
;
run;
/* 緯度経度、shapefileの全組み合わせを取ってくる */
proc sql;
libname map "path\to\lib"
proc mapimport out=map.japanshp datafile="path\to\N03-140401_GML\N03-14_140401.shp";
run;
library(rvest)
library(stringr)
find_pref_city <- function(lat, lon) {
nominatim_url <- str_c("http://nominatim.openstreetmap.org/reverse?format=xml&lat=",
lat,
"&lon=",
lon,
"&zoom=18&addressdetails=1")
xmldata <- read_xml(nominatim_url)
data new;
set sashelp.iris;
rename SepalLength=new_variable;
run;
proc print data=new(obs=6);
run;
proc print data=sashelp.iris(obs=6);
run;
data gps;
input x y;
rownum = _n_;
datalines;
143.21 -33.494
119.306 26.0614
119.306 26.0614
143.21 -33.494
113.25 23.1167
139.751 35.685
@ymattu
ymattu / save_ein.el
Created May 15, 2017 01:38
Emacs Ipython Notebook で保存できないエラーをなんとかする
(defun save-buffer (&optional arg)
(interactive "p")
(if (eq major-mode 'ein:notebook-multilang-mode)
(ein:notebook-save-notebook-command)
(let ((modp (buffer-modified-p))
(make-backup-files (or (and make-backup-files (not (eq arg 0)))
(memq arg '(16 64)))))
(and modp (memq arg '(16 64)) (setq buffer-backed-up nil))
(if (and modp (buffer-file-name))
(message "Saving file %s..." (buffer-file-name)))
@ymattu
ymattu / join.sh
Last active October 24, 2020 03:56
複数のcsvを連結し、最初のファイル以外はヘッダーを削除するシェルスクリプト
#!/bin/bash
counter=0
for file in `\find . -maxdepth 1 -name '*.csv'`;
do
echo $file
if [ $counter == 0 ]; then
cat $file > join_result.csv
else
@ymattu
ymattu / insert_chunk.el
Last active December 22, 2016 04:15
emacsのpolymodeでチャンクを挿入するコード
;; チャンク挿入
(defun tws-insert-r-chunk (header)
"Insert an r-chunk in markdown mode. Necessary due to interactions between polymode and yas snippet"
(interactive "sHeader: ")
(insert (concat "```{r " header "}\n\n```"))
(forward-line -1))
(define-key poly-markdown+r-mode-map (kbd "M-n M-r") 'tws-insert-r-chunk)
(defun tws-insert-py-chunk (header)