Skip to content

Instantly share code, notes, and snippets.

@muupan
muupan / add_env_with_colon.sh
Created February 27, 2014 18:19
Add a value to an environmental variable while avoiding putting an unnecessary colon.
# Add a value to an environmental variable while avoiding putting an unnecessary colon.
# Usage: add_env_with_colon PATH $HOME/local/bin
function add_env_with_colon {
ENV_VAR_NAME=$1
VALUE_TO_ADD=$2
CURRENT_VALUE=${!ENV_VAR_NAME}
if [ -n "$CURRENT_VALUE" ]; then
export $ENV_VAR_NAME=$VALUE_TO_ADD:$CURRENT_VALUE
else
@muupan
muupan / find_unique_n.pl
Last active August 29, 2015 14:03
find_unique_n/4: Finding up to N unique solutions of a goal in Prolog (tested in Yet Another Prolog)
:- module(find_unique_n, [find_unique_n/4]).
:- meta_predicate find_unique_n(?,?,:,?).
:- use_module(library(ordsets)).
:- use_module(library(lists)).
find_unique_n(N, Term, Goal, Solutions) :-
N > 0,
( retractall(unique_solutions(_)),
#include <iostream>
#include <memory>
#include <random>
#include <caffe/caffe.hpp>
#include <glog/logging.h>
int main(int argc, char** argv) {
// glogの初期化
google::InitGoogleLogging(argv[0]);
@muupan
muupan / roulette.cpp
Created December 22, 2014 09:51
roulette wheel selection using std::discrete_distribution
#include <array>
#include <iostream>
#include <random>
int main() {
constexpr std::array<double, 3> fitness_values = {1, 1.5, 2};
// Constructor is O(n)
std::discrete_distribution<std::size_t> dist(fitness_values.begin(), fitness_values.end());
std::array<size_t, 3> table;
table.fill(0);
@muupan
muupan / CMakeLists.txt
Created March 8, 2015 01:29
CMakeLists.txt that makes all the header and source files visible from Qt Creator
# CMakeLists.txt that makes all the header and source files visible from Qt Creator
cmake_minimum_required(VERSION 2.8)
execute_process(
COMMAND find . -name *.cpp -or -name *.hpp -or -name *.h -or -name *.cc -or -name *.hh
COMMAND tr "\n" ";"
OUTPUT_VARIABLE QTCREATOR_SRCS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
add_custom_target(qtcreator SOURCES ${QTCREATOR_SRCS})
@muupan
muupan / gist:546c239982dc06967436
Last active September 9, 2015 08:22
byobu/tmux configuration; add these lines to ~/.byobu/keybindings.tmux
# Move the current window left/right by Ctrl+Shift+Left/Right
bind-key -n C-S-Left swap-window -t -1
bind-key -n C-S-Right swap-window -t +1
# Move to the prev/next window by Shift+Left/Right
bind-key -n S-Left prev
bind-key -n S-Right next
@muupan
muupan / Makefile
Created June 27, 2013 16:09
使い回しMakefile test/gtest/にgtest.h, gtest-all.cc, gtest_main.ccを入れる
# Common macros
CXX := g++
CXXFLAGS := -Wall -std=c++0x -I./src
# Macros for build
CXXFLAGS_RELEASE := -O3 -march=native -flto -DNDEBUG
CXXFLAGS_DEBUG := -g -O0
CXX_FILES := $(shell find src \( -name \*.cpp -or -name \*.cc \) -print)
OBJS := $(shell echo $(CXX_FILES) | perl -p -e 's/.(cpp|cc)/.o/g')
TARGET := main
@muupan
muupan / fizzbuzz.pl
Last active December 20, 2015 04:29
FizzBuzz in Prolog It would be better to use between/3.
fizzbuzz(_n) :-
fizzbuzz_sequence(1, _n).
fizzbuzz_sequence(_max, _max) :-
fizzbuzz_number(_max), !.
fizzbuzz_sequence(_min, _max) :-
fizzbuzz_number(_min),
_next is _min + 1,
fizzbuzz_sequence(_next, _max).
@muupan
muupan / fizzbuzz.kif
Created July 24, 2013 16:43
FizzBuzz in Game Description Language version 1 Play a FizzBuzz game from 1 to 30
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; FizzBuzz in GDLv1
; 2013/07/25
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Role
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(role player)
@muupan
muupan / gunbai.vim
Last active December 22, 2015 01:29
A sintax file for Gunbai Script (for SamurAI Coding 2013).
" A sintax file for Gunbai Script (for SamurAI Coding 2013).
"
" Put this file in .vim/syntax/ and and add set filetype gunbai.
" Example:
" au BufRead,BufNewFile *.gb set filetype=gunbai
syntax region gunbaiLineComment start=+#+ end=+$+
syntax keyword gunbaiConditional if elif else endif
syntax keyword gunbaiRepeat while endwhile
syntax keyword gunbaiCase break continue