Skip to content

Instantly share code, notes, and snippets.

@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(_)),
@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 / gale_shapley.py
Created October 1, 2013 10:29
Gale-Shapley Algorithm for stable marriage problem
"""
Gale-Shapley Algorithm
"""
import random
def shuffled(lst):
tmp = lst[:]
random.shuffle(tmp)
return tmp
@muupan
muupan / clean_downloads.sh
Created September 17, 2013 19:56
$HOME/Downloads直下にあるファイル及びディレクトリを変更日時で整理するシェルスクリプト
#!/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 / gdl-kif.vim
Created September 8, 2013 04:44
A sintax file for Game Description Language (GDL) in Knowledge Interchange Format (KIF).
" 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 / 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
@muupan
muupan / gist:6120294
Created July 31, 2013 08:21
Terminal及びMacVimでESCまたはControl+[を押したときにIMEを英数モードにするKeyRemap4MacBook設定
<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 / 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 / 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 / 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