Skip to content

Instantly share code, notes, and snippets.

View sergeant-wizard's full-sized avatar
😵

Ryo Miyajima sergeant-wizard

😵
  • Preferred Networks
  • Tokyo
View GitHub Profile
# file spec/libs/lottery_spec.rb
require 'spec_helper'
RSpec.describe 'lib/lottery' do
describe 'Lottery.pick' do
let(:characters) { create_list(:character, 2) }
let(:num_samples) { 10000 }
subject do
num_chosen = 0
num_samples.times do
#include <iostream>
#include <unistd.h>
class bar{
public:
bar(){}
~bar(){}
void setLambda(std::function<void()> func){
_func = func;
}
@sergeant-wizard
sergeant-wizard / return_value_optimization.cpp
Created September 19, 2014 14:46
return value optimization
#include <iostream>
#include <unistd.h>
class myClass{
public:
myClass(){
std::cout << "constructor called" << std::endl;
}
~myClass(){
std::cout << "destructor called" << std::endl;
@sergeant-wizard
sergeant-wizard / json_memory_usage.cpp
Created September 22, 2014 07:05
json memory usage
#include "dist/json/json.h"
int main(void){
Json::Reader reader;
Json::Value rootJson;
bool parseResult = reader.parse(" \
\"areas\" : [ \
{\
\"background_image\" : \"background_cave\",\
\"description\" : \"desc\",\
@sergeant-wizard
sergeant-wizard / return_value_inheritance.cpp
Created September 26, 2014 07:27
return value inheritance
#include <iostream>
class Super{
public:
virtual void func(){
std::cout << "super" << std::endl;
}
virtual Super* someFunc(){
std::cout << "Super::someFunc()" << std::endl;
@sergeant-wizard
sergeant-wizard / risky_callback.cpp
Created September 30, 2014 01:21
risky callback
#include <iostream>
#include <unistd.h>
class bar{
public:
bar(){}
~bar(){}
void setPointer(void* pointer){
std::cout << "setPointer called" << std::endl;
_pointer = pointer;
@sergeant-wizard
sergeant-wizard / composition_and_inheritance.cpp
Created October 4, 2014 05:03
composition and inheritance
class SomeClass{
public:
virtual void func() {
std::cout << "SomeClass::func called" << std::endl;
}
};
class SubOfSomeClass : public SomeClass {
public:
virtual void func() override {
@sergeant-wizard
sergeant-wizard / .gitattributes
Last active August 29, 2015 14:07
cpplint cleaner
*.cpp filter=cpplint_cleaner
*.h filter=cpplint_cleaner
@sergeant-wizard
sergeant-wizard / uc_20141217.md
Last active August 29, 2015 14:11
understanding computation 勉強会 2014/12/17

復習

statements change the environment, expressions do not

Statement

do-nothing statement を定義

Assignment statement

右辺が簡約できる場合

  • 簡約した結果を再び代入
  • Environmentは変化しない
@sergeant-wizard
sergeant-wizard / weighted_probability_lottery.cpp
Created March 12, 2015 00:58
Weighted Probability Lottery
double throwDice() {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<> dis(0, 1);
return dis(gen);
}
template<class T>
typename std::vector<T>::const_iterator lottery(
const std::vector<T>& list,