Skip to content

Instantly share code, notes, and snippets.

@tanitanin
tanitanin / gnuplot.h
Last active December 24, 2015 06:09
GnuplotをC++で使うためのクラス
#pragma once
#include <iostream>
#include <string>
#include <memory>
#include <cstdio>
#include <cstdarg>
using namespace std;
@tanitanin
tanitanin / hello.rb
Last active December 24, 2015 23:39
Daemonsでデーモン化したスクリプトをCapistranoから起動できるようにする
##### hello.rb
#!/usr/bin/env ruby
require 'daemons'
require 'logger'
# Initialize
logpath = File.expand_path("app.log")
log = Logger.new(logpath)
log.info("Completely initialized")
@tanitanin
tanitanin / rvm.cap
Created October 10, 2013 12:42
Capistrano v3でcapistrano/rvmがまだinstall/gemset createを実装してなかったので自分用に書いたメモ
# lib/capistrano/rvm.cap
namespace :rvm do
desc 'RVM install in :rvm_type or :rvm_custom_path'
task :install do |host|
on roles(:app) do
rvm_path = '~/.rvm'
#rvm_path = '/usr/local/rvm' if :rvm_type == :system
#rvm_path = :rvm_custom_path if :rvm_custom_path
rvm_dir = File.dirname(rvm_path)
execute "mkdir -p #{rvm_path} && cd #{rvm_dir} && curl -L https://get.rvm.io | bash"
@tanitanin
tanitanin / pipestream.h
Last active December 27, 2015 05:49
popenをfstreamっぽく使うためのラッパー
#pragma once
#include <cstdio>
#include <iostream>
#include <memory>
#include <stdexcept>
class invalid_command : std::runtime_error {
public:
invalid_command(const std::string &cause)
@tanitanin
tanitanin / thread_pool.rb
Last active January 4, 2016 21:39
Thrad Pool for arbitarily killing in Ruby
#!/bin/ruby
require 'thread'
class ThreadPool
def initialize(size, &session)
@size = size
@queue = SizedQueue.new(size)
@map = {}
@map_mutex = Mutex.new
session.call(self)
*** ruby-2.0.0-p353/file.c.origin 2014-02-03 14:10:23.019204500 +0900
--- ruby-2.0.0-p353/file.c 2014-02-03 14:10:50.577250200 +0900
***************
*** 4181,4187 ****
#ifdef __CYGWIN__
#include <winerror.h>
! extern unsigned long __attribute__((stdcall)) GetLastError(void);
#endif
*** ruby-1.9.3-p484.origin/file.c 2013-07-10 10:33:05.000000000 +0900
--- ruby-1.9.3-p484/file.c 2014-02-03 14:17:21.054461600 +0900
***************
*** 4126,4132 ****
#ifdef __CYGWIN__
#include <winerror.h>
! extern unsigned long __attribute__((stdcall)) GetLastError(void);
#endif
@tanitanin
tanitanin / iVerilog.mk
Created May 23, 2014 06:48
Verilog simulation by using iVerilog
# Makefile for iVerilog testing
SRC_DIR := src
TEST_DIR := test
SIM_DIR := sim
TESTS := $(sort $(patsubst $(TEST_DIR)/%.v,$(SIM_DIR)/%.vcd,$(wildcard $(TEST_DIR)/test_*.v)))
VERILOGS := $(sort $(wildcard $(SRC_DIR)/*.v))
.PHONY: $(SIM_DIR)/test_%.sim
$(SIM_DIR)/test_%.sim: $(TEST_DIR)/test_%.v
#pragma once
#include <algorithm>
template<class Iterator>
bool next_combination(Iterator first1, Iterator last1, Iterator first2, Iterator last2) {
if((first1 == last1) || (first2 == last2)) return false;
Iterator m1 = last1, m2 = last2; --m2;
while(--m1 != first1 && !(*m1 < *m2)) {}
const bool result = !((m1 == first1) && !(*first1 < *m2));
@tanitanin
tanitanin / vec.h
Last active August 29, 2015 14:07
Vector
#pragma once
#include <vector>
template<class T, size_t N = 1>
class vec : public std::vector<vec<T,N-1>> {
public:
explicit vec() : std::vector<vec<T,N-1>>() {}
template<class Size, class... Sizes>
explicit vec(Size n, Sizes... ns) : std::vector<vec<T,N-1>>(n,vec<T,N-1>(ns...)) {}