Skip to content

Instantly share code, notes, and snippets.

View carushi's full-sized avatar

carushi carushi

View GitHub Profile
@carushi
carushi / GetCapitalRNA
Last active August 29, 2015 14:02
Transform a string into correct RNA (or DNA) sequence
char CapitalRNA(char c)
{
if (c == '$') return c;
c = toupper(c);
switch(c) {
case 'A': case 'C': case 'G': case'U': case 'N': return c;
case 'T': case 'K': case 'Y': case 'B': return 'U';
case 'W': case 'R': case 'M':
case 'H': case 'V': case 'D': return 'A';
case 'S': return 'C';
@carushi
carushi / ptest.py
Last active August 29, 2015 14:07
permutation_test
import random
def set(a, b):
print "before a", a
print "before b", b
for i in range(len(a)):
next = b[i]
prev = i
tmp = a[prev]
@carushi
carushi / ggboxplot.R
Last active August 29, 2015 14:11
simple boxplot (ggplot)
ggbox <- function(ofile, data, ...) {
require(ggplot2)
require(reshape)
tdata <- data.frame(t(rbind(c(0:(dim(data)[2]-1)), data)))
tdata <- melt.data.frame(tdata,id.vars="X1",variable_name="temp")
tdata$X1 <- factor(tdata$X1, levels = c(0:(dim(data)[2]-1)), ordered = TRUE)
g <- ggplot(tdata, aes(x = X1, y = value))
g <- g + geom_boxplot()
g <- g + ylab("hoge")
png(ofile)
@carushi
carushi / hist.R
Created January 9, 2015 08:07
Histogram drawn with same width
# a := matrix の各カラムのヒストグラムを同じ幅で描く
width = 1
for (i in 1:dim(a)[1]) {
plot(hist(a[,i], breaks=seq(min(a[,i]), max(a[,i])+width, width)))
}
# max(a[,i])だけだとmax(a[,i])を網羅しない可能性があるので
@carushi
carushi / ggboxplot_scaled.R
Created February 17, 2015 03:33
simple orderd boxplot (ggplot)
ggboxscaled <- function(ofile, data, ...) {
require(ggplot2)
require(reshape)
tdata <- data.frame(t(rbind(c(0:(dim(data)[2]-1)), data)))
tdata <- melt.data.frame(tdata,id.vars="X1",variable_name="temp")
tdata$X1 <- as.character(tdata$X1)
g <- ggplot(tdata, aes(x = X1, y = value))
g <- g + geom_boxplot()
g <- g + ylab("hoge")
meate <- as.character(c(0:(dim(data)[2]-1))*2)
@carushi
carushi / bin_print.py
Last active August 29, 2015 14:22
print binary data
import binascii
import struct
file = "binary_file"
f = open(file, "rb")
buf = f.read(8) #^@^@^@^@^@^@^@^@
print(binascii.b2a_hex(buf)) #3bf50f0eb696493f
print(struct.unpack('<d', buf)) #0.000780905622491
f.close()
@carushi
carushi / 0222.cc
Created June 26, 2015 02:41
AOJ 0222 4 primes
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef vector<int> Array;
int main(void) {
Array limit;
int d;
while (1) {
@carushi
carushi / test.fs
Created June 29, 2015 16:49
solve test problem in F#
let lines =
Seq.initInfinite (fun _ -> System.Console.In.ReadLine())
|> Seq.takeWhile(fun line -> line <> null)
|> Seq.toList;;
let rec filtered lines =
match lines with
| [] -> []
| x::res ->
if System.String.Equals(x, "42", System.StringComparison.CurrentCultureIgnoreCase) then []
@carushi
carushi / test_tweepy.py
Created July 7, 2015 09:22
tweepy test
import tweepy
consumer_key = "hoge"
consumer_secret = "hogehoge"
access_key = "piyo"
access_secret = "piyopiyo"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth_handler=auth)
api.update_status(status="!")
@carushi
carushi / greet.go
Created October 16, 2015 05:20
cli and gopher test
package main
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/toashd/gopher"
"os"
"time"
)