Skip to content

Instantly share code, notes, and snippets.

View YukiSakamoto's full-sized avatar

Yuki Sakamoto YukiSakamoto

  • Osaka, Japan
  • 07:09 (UTC +09:00)
View GitHub Profile
@YukiSakamoto
YukiSakamoto / RestrictionEnzymeMap.cpp
Created July 15, 2012 18:58
RestrictionEnzyme_map
#include <vector>
#include <algorithm>
#include <iostream>
#define IN
#define OUT
typedef std::vector<int> int_v;
inline int diff(int a, int b)
{ return (a < b)? (b - a) : (a - b); }
@YukiSakamoto
YukiSakamoto / gillespie_draft.rb
Created July 19, 2012 03:01
Gillespie Algorithm(draft)
require 'csv'
#==================================================
# Math Util Methods
#==================================================
def factorial(i)
ans = 1
1.upto(i) { |x| ans *= x }
return ans
end
@YukiSakamoto
YukiSakamoto / gillespie2.rb
Created July 24, 2012 04:42
Gillespie Algorithm( draft_2nd )
require 'csv'
CSV_Output = false
#==================================================
# Math Util Methods
#==================================================
def factorial(i)
ans = 1
1.upto(i) { |x| ans *= x }
@YukiSakamoto
YukiSakamoto / mersenne_twister.cpp
Created July 30, 2012 13:29
Mersenne Twister Algorithm
#include <iostream>
#include <boost/random.hpp>
using namespace boost;
int main(void)
{
boost::mt19937 gen(static_cast<double>(time(0)));
boost::uniform_real<> range(0, 1);
boost::variate_generator< boost::mt19937, boost::uniform_real<> > random(gen, range);
@YukiSakamoto
YukiSakamoto / lcs.c
Created August 23, 2012 13:57
Lcs Problem
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char str_a[] = "bcdefghijklmnopqrstuvwxyz";
char str_b[] = "bdfpqa";
int max_3(int v1, int v2, int v3)
{
@YukiSakamoto
YukiSakamoto / meta_sample.rb
Created August 23, 2012 14:20
ruby sample(method_missing and dispatch)
class SampleClass
def send(method_name, *args)
puts "#{method_name}, #{args}\n"
end
def method_missing(method_name, *args)
if method_name.to_s.match(/get_(.*)?_value/)
puts "Getter: #{$1}"
elsif method_name.to_s.match(/set_(.*?)_value/)
puts "Setter: #{$1}"
@YukiSakamoto
YukiSakamoto / member_variable_attribute.cpp
Created August 26, 2012 10:05
Macros that defines accessors of class-instance variables.
#define ATTR_READER(name,type) \
public: \
type get_ ## name(void) { \
return this-> name; \
}
#define ATTR_WRITER(name,type) \
public: \
void set_ ## name(type new_val) { \
this-> name = new_val; \
@YukiSakamoto
YukiSakamoto / cleanup.c
Created August 28, 2012 16:04
attribute(cleanup) sample
#include <stdio.h>
#include <stdlib.h>
#define cleanup_free_scope __attribute__((cleanup(my_free)))
#define cleanup_print_scope __attribute__((cleanup(my_print_int)))
void my_print_int(int *i)
{
printf("argument = %d\n", *i);
}
@YukiSakamoto
YukiSakamoto / hook_enter_and_exit.c
Created August 30, 2012 06:52
gcc finstrument-functions test
#include <stdio.h>
/* When compiling, set 'finstrument-functions'!
*
* gcc -finstrument-functions hook.c
*
* フックされた時に呼ばれる関数の定義は、macの場合、profile_func_enter, profile_func_exitにしないと
* いけないみたい。Linuxの場合は頭に__cyg_をそれぞれ付ける(LINUXの場合はマングリングしないはずだから_は気にしない。)
*/
@YukiSakamoto
YukiSakamoto / construct.c
Created September 2, 2012 15:10
gcc extension-sample(constructor & destructor)
#include <stdio.h>
__attribute__((constructor))
int pre_main(void)
{
printf("%s\n", __func__);
getchar();
return 0;
}