Skip to content

Instantly share code, notes, and snippets.

View mryoshio's full-sized avatar

YOSHIOKA A mryoshio

View GitHub Profile
@mryoshio
mryoshio / dynamodb_table_hashmodel.rb
Created July 13, 2013 17:37
Ruby class to handle DynamoDB table using HashModel
class Book < AWS::Record::HashModel
set_shard_name :Book
string_attr :title
string_attr :author
string_attr :content
end
unless Book.dynamo_db_table.exists?
Book.create_table 1, 20
@mryoshio
mryoshio / dijkstra_sample.cpp
Created July 16, 2013 16:25
dijkstra algorithm sample.
#include <iostream>
#define STATION_NUMBER (6)
#define START_STATION (0)
using namespace std;
string stations[] = { "Yokohama", "Musashikosugi", "Shinagawa", "Shibuya", "Shimbashi", "Tameikesannno" };
int current_cost[STATION_NUMBER] = { -1, -1, -1, -1, -1, -1 };
@mryoshio
mryoshio / options.rb
Created September 5, 2013 02:12
Have rails respond to HTTP OPTIONS method.
# Implementation for HTTP OPTIONS method in rails 3.2.13
# inspired by https://gist.github.com/ajturner/832700
# routes.rb
match '/*any_path', :controller => 'application', :action => 'method_for_options_method', :constraints => { :method => 'OPTIONS' }
# application_controller.rb
def method_for_options_method
render :nothing => true, :status => 200
end
@mryoshio
mryoshio / apache_405_for_options.conf
Created September 5, 2013 02:16
Apache returns 405 (method not allowed) with this against OPTIONS method.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^OPTIONS
RewriteRule .* - [R=405,L]
</IfModule>
@mryoshio
mryoshio / bit_base.cpp
Created September 22, 2013 07:52
basic calculations with bit operation
#include <iostream>
#define df(f) cout << "# " << f << endl
using namespace std;
void get_bit(int num, int i) {
df(__func__ << "(" << num << ", " << i << ")");
cout << "Get " << i << "'th bit is : ";
cout << ((num & (1 << i)) != 0) << endl;
@mryoshio
mryoshio / bit_insert.cpp
Created September 22, 2013 08:40
insert m into n, bit position i to j
#include <iostream>
using namespace std;
// see http://d.hatena.ne.jp/kobapan/20090208/1281901941
int strbin2i (const std::string &s) {
int out = 0;
for (int i = 0, size = s.size() ; i < size ; ++i ) {
out *= 2;
out += ((int)s[i] == 49) ? 1 : 0;
#include <boost/utility/binary.hpp>
#include <iostream>
using namespace std;
#define B(x) BOOST_BINARY(x)
void row1() {
cout << "# row1" << endl;
cout << (B(0110) + B(0010)) << endl;
@mryoshio
mryoshio / binary_op.h
Created September 23, 2013 15:14
sample str <-> int functions in C++
#ifndef BINARY_OP_H
#define BINARY_OP_H
#include <vector>
#include <sstream>
using namespace std;
// see http://d.hatena.ne.jp/kobapan/20090208/1281901941
@mryoshio
mryoshio / fluent_s3_sample.conf
Created September 28, 2013 08:09
fluent sample conf for s3 plugin
<source>
type tail
format apache2
path /var/log/apache2/access_log
pos_file /var/log/fluent/tmp/apache2.access_log.pos
tag s3.apache.access
</source>
# S3 plugin test
<match s3.*.*>
@mryoshio
mryoshio / batcth_write_dynamodb.rb
Created September 28, 2013 16:56
sample ruby script to batch write onto DynamoDB
require 'aws'
require 'aws-sdk'
ACCESS_KEY_ID='access key'
SECRET_ACCESS_KEY='secret access key'
TABLE='table name'
MAX_ITEMS=100
AWS.config({
access_key_id: ACCESS_KEY_ID,