Skip to content

Instantly share code, notes, and snippets.

@muupan
muupan / Makefile
Created Jun 27, 2013
使い回しMakefile test/gtest/にgtest.h, gtest-all.cc, gtest_main.ccを入れる
View Makefile
# 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 Dec 20, 2015
FizzBuzz in Prolog It would be better to use between/3.
View fizzbuzz.pl
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 Jul 24, 2013
FizzBuzz in Game Description Language version 1 Play a FizzBuzz game from 1 to 30
View fizzbuzz.kif
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; FizzBuzz in GDLv1
; 2013/07/25
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Role
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(role player)
@muupan
muupan / gist:6120294
Created Jul 31, 2013
Terminal及びMacVimでESCまたはControl+[を押したときにIMEを英数モードにするKeyRemap4MacBook設定
View gist:6120294
<item>
<name>ESC/Control+[ to EISUU mode in Terminal/MacVim</name>
<appendix>Change ESC to ESC, ESC, JIS_EISUU</appendix>
<appendix>Change Control+[ to ESC, ESC, JIS_EISUU</appendix>
<identifier>private.app_terminal_esc_with_eisuu</identifier>
<only>TERMINAL, VI</only>
<inputsource_only>JAPANESE</inputsource_only>
<autogen>--KeyToKey-- KeyCode::ESCAPE, KeyCode::ESCAPE, KeyCode::ESCAPE, KeyCode::JIS_EISUU</autogen>
<autogen>--KeyToKey-- KeyCode::JIS_BRACKET_LEFT, VK_CONTROL, KeyCode::ESCAPE, KeyCode::ESCAPE, KeyCode::JIS_EISUU</autogen>
</item>
@muupan
muupan / gunbai.vim
Last active Dec 22, 2015
A sintax file for Gunbai Script (for SamurAI Coding 2013).
View gunbai.vim
" 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
@muupan
muupan / gdl-kif.vim
Created Sep 8, 2013
A sintax file for Game Description Language (GDL) in Knowledge Interchange Format (KIF).
View gdl-kif.vim
" A sintax file for Game Description Language (GDL) in Knowledge
" Interchange Format (KIF).
"
" Put this file in .vim/syntax/ and and add set filetype gdl-kif
" Example:
" au BufRead,BufNewFile *.kif set filetype=gdl-kif
syntax region gdlKifLineComment start=+;+ end=+$+
syntax match gdlKifArrow '<='
syntax keyword gdlKifFactRelation base init true next
@muupan
muupan / clean_downloads.sh
Created Sep 17, 2013
$HOME/Downloads直下にあるファイル及びディレクトリを変更日時で整理するシェルスクリプト
View clean_downloads.sh
#!/bin/sh
dir="$HOME/Downloads"
cd $dir
files=`ls -1`
# Set IFS (Internal Field Separator)
# See http://linux.just4fun.biz/%E9%80%86%E5%BC%95%E3%81%8D%E3%82%B7%E3%82%A7%E3%83%AB%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%97%E3%83%88/%E3%82%B9%E3%83%9A%E3%83%BC%E3%82%B9%E3%81%8C%E5%90%AB%E3%81%BE%E3%82%8C%E3%82%8B%E6%96%87%E5%AD%97%E5%88%97%E3%82%921%E8%A1%8C%E3%81%A8%E3%81%97%E3%81%A6%E6%89%B1%E3%81%86%E6%96%B9%E6%B3%95.html
IFS_BACKUP=$IFS
@muupan
muupan / gale_shapley.py
Created Oct 1, 2013
Gale-Shapley Algorithm for stable marriage problem
View gale_shapley.py
"""
Gale-Shapley Algorithm
"""
import random
def shuffled(lst):
tmp = lst[:]
random.shuffle(tmp)
return tmp
@muupan
muupan / add_env_with_colon.sh
Created Feb 27, 2014
Add a value to an environmental variable while avoiding putting an unnecessary colon.
View add_env_with_colon.sh
# 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 Aug 29, 2015
find_unique_n/4: Finding up to N unique solutions of a goal in Prolog (tested in Yet Another Prolog)
View find_unique_n.pl
:- 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(_)),