Skip to content

Instantly share code, notes, and snippets.

View mryoshio's full-sized avatar

YOSHIOKA A mryoshio

View GitHub Profile
@mryoshio
mryoshio / lake_count.cpp
Created December 15, 2013 06:44
lake count
#include <iostream>
#include <fstream>
#define N 10
#define M 12
using namespace std;
char lake[10][12];
@mryoshio
mryoshio / dfs.cpp
Created December 15, 2013 05:59
sonomamma dfs
#include <iostream>
#define MAX_N 20
using namespace std;
int a[MAX_N];
int n, k;
bool dfs(int i, int sum) {
@mryoshio
mryoshio / constructor_destructor.cpp
Created December 11, 2013 16:29
play with constructor / destructor in C++
#include <iostream>
#include <vector>
using namespace std;
struct X
{
int val;
void out(const string& s, int nv) {
@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 / 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
#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 / 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;
@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 / 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 / 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