Skip to content

Instantly share code, notes, and snippets.

View neetsdkasu's full-sized avatar
🔰
take it easy

Leonardone @ NEETSDKASU neetsdkasu

🔰
take it easy
View GitHub Profile
@neetsdkasu
neetsdkasu / move_files_from_subdir_to_here.bat
Created July 1, 2015 21:08
サブディレクトリ以下にある全てのファイル(mp3)をスクリプトディレクトリ(指定ディレクトリ)に移動する。
@echo off
setlocal
if "%~1"=="" goto thatdir
set destdir="%~1"
goto doit
:thatdir
set destdir="%~dp0"
:doit
for /R %%i in (*.mp3) do move "%%i" %destdir%
endlocal
@neetsdkasu
neetsdkasu / strreverse.R
Last active October 7, 2015 16:21
Reverse a String in R ( strReverse function ) [ R言語での文字列の反転 ]
strReverse <- function(x) {
return(paste(rev(strsplit(x, NULL)[[1]]), collapse=""))
}
# example 1
s <- strReverse("abcdefghij")
cat(s) # output is "jihgfedcba"
# example 2
@neetsdkasu
neetsdkasu / strconcat.R
Last active September 7, 2015 15:50
Concatenate Strings in R ( strConcat function ) [ R言語での文字列の連結 ]
strConcat <- function(x, sep="") {
return(paste(x, collapse=sep))
}
# example 1
s <- strConcat(c("abc", "efg", "hij"))
cat(s) # output is "abcefghij"
# example 2
@neetsdkasu
neetsdkasu / convert.R
Last active September 7, 2015 15:50
R言語 文字列と数値の変換
# 数値から文字列へ
n <- 100
s <- as.character(n)
# 文字列から数値へ
s <- "1234"
n <- as.integer(s)
@neetsdkasu
neetsdkasu / readstdin.R
Last active February 12, 2020 03:37
R言語 標準入力からEOFまでの全行読み込み
# example 1
f <- file("stdin") # 標準入力
s <- readLines(f) # 全行読み込み
cat(s[1]) # 1行目を出力
# example 2
s <- readLines("stdin") # 直接指定してもOK
cat(s, sep="\n") # 配列 s の全ての要素を"\n"(改行文字)区切りで出力
@neetsdkasu
neetsdkasu / genBF.rb
Last active February 14, 2016 15:57
Brainf*ck Code Generator (固定文字列表示のみ) - ruby
# Brainf*ck Code Generator (固定文字列表示のみ)
# Author: Leonardone @ NEETSDKASU
# License: MIT License
def test_genBF()
f = 'TextFile.txt'
ARGV << f if ARGV.empty? && ARGF.eof? && FileTest.exist?(f)
puts genBF(ARGF.read, 60, 10) if !ARGF.eof?
end
@neetsdkasu
neetsdkasu / Permutation.java
Last active December 2, 2015 13:04
並べ替え全パターン生成(置換Permutationと言うらしい)
// package myapp.util;
import java.util.Arrays;
public class Permutation
{
protected final int[] unuses, stack;
protected int stack_end = 0;
protected boolean hasnext = true;
@neetsdkasu
neetsdkasu / PrimitiveArrayUtil.java
Last active November 22, 2015 13:10
プリミティブ配列ユーティリティ(PrimitiveArrayUtil)
// package myapp.util;
/*
* wrap ... e.g. int[] -> Integer[]
* unwrap ... e.g. Integer[] -> int[]
* toInt ... e.g. double[] -> int[]
* toDouble ... e.g. int[] -> double[]
*
*/
@neetsdkasu
neetsdkasu / split.hs
Last active April 1, 2016 17:05
split string (haskell)
-- Data.Text.split の代替(?)
s = ",1,2,345,6,,7,8,"
x = split (== ',') s -- x = ["","1","2","345","6","","7","8",""]
split :: (a -> Bool) -> [a] -> [[a]]
split f str = loop str where
loop [] = [[]]
loop t = case s of
[] -> [w]
@neetsdkasu
neetsdkasu / splitOn.hs
Last active April 1, 2016 15:45
split sting (haskell)
-- Data.List.Split.splitOn や Data.Text.splitOn の代替(?)
import Data.List(isPrefixOf)
s = "bc k abcd Efg abc b c xyz bcbc xyz bc"
d = "bc"
x = splitOn d s -- x = [""," k a","d Efg a"," b c xyz ",""," xyz ",""]
splitOn :: Eq a => [a] -> [a] -> [[a]]
splitOn [] str = error "splitOn: empty input" -- Data.Textのはエラーだが、Rubyみたいに文字単位分割したいなら [[c] | c <- str]