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
@sergeant-wizard
sergeant-wizard / nested_loop.ex
Created October 30, 2015 05:03
nested loop in elixir
defmodule Loop do
def each([head|tail], fun) do
[fun.(head)|each(tail, fun)]
end
def each([], _) do
[]
end
end
Loop.each [1, 2], fn element ->
@sergeant-wizard
sergeant-wizard / rgb2hex.rb
Created September 8, 2015 08:08
rgb to hex
[254, 253, 3].map { |v| v.to_s(16).rjust(2, '0') }.join
#include <iostream>
#include <stdint.h>
class Area;
class Quest;
template <typename T, typename Meaning>
struct Explicit
{
Explicit() {}
@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,
@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 / .gitattributes
Last active August 29, 2015 14:07
cpplint cleaner
*.cpp filter=cpplint_cleaner
*.h filter=cpplint_cleaner
@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 / 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 / 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 / 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\",\