Skip to content

Instantly share code, notes, and snippets.

@hisui
hisui / func_style.pl
Created October 30, 2011 05:25
func_style/2
:- op(1200, xfx, ::-).
:- op( 30, fx, ^).
term_expansion(Head ::- Body0, Head :- Body1) :-
func_style(Body0, Body1).
replace_hats(X, X, Vars, Vars, (Z,Z)) :- var(X), !.
replace_hats(**, V, [V|Vars], Vars, (Z,Z)) :- !.
replace_hats(^X, V, Vars1, Vars2, ([P|Preds],Z)) :- !,
replace_hats(X, P, [V|Vars1], Vars2, (Preds,Z)).
@hisui
hisui / rjquery.rb
Created November 23, 2011 15:59
rjquery
# coding: utf-8
require "strscan"
require "set"
# HTMLを解析する
class RjStAX
attr_reader :scan, :node, :name, :attrs, :text
#include <iostream>
struct SecretLove
{
SecretLove(const std::string &msg)
:msg_4_u(msg)
{
}
private:
@hisui
hisui / al.rb
Created January 15, 2012 07:56
正規表現嗜好(ネタ)言語 - 作りかけ
require "strscan"
require "pp"
##
## Alインタープリター
##
# codes
AlFail = Object.new
@hisui
hisui / brainfxxk.pl
Created January 18, 2012 13:31
use of cyclic term
bf_memget([K:X|_], K, V) :- !, X = V.
bf_memget([ _|T], K, V) :- !, bf_memget(T, K, V).
bf_memget([], _, 0).
bf_memset([K:V|T], [K:_|T], K, V) :- !.
bf_memset([ H|U], [ H|T], K, V) :- !, bf_memset(U, T, K, V).
bf_memset([K:V], _, K, V).
bf_exec([], _, _) :- !.
@hisui
hisui / OperatorPrecedencePersers.scala
Last active September 6, 2020 17:41
Parser combinator for Operator-precedence
package jp.segfault.scala.util
import scala.util.parsing.combinator._
/**
* Parser combinator for Operator-precedence parser(http://en.wikipedia.org/wiki/Operator-precedence_parser).
*/
trait OperatorPrecedenceParsers extends Parsers {
trait Op[+T,U] {
@hisui
hisui / hoge.scala
Created February 16, 2012 08:35
test
import java.lang.reflect.{Proxy, InvocationHandler, Method}
object Prototype {
def clone[T](base:T, content:AnyRef)(implicit manifest:ClassManifest[T]):T = {
val metaclass = manifest.erasure
Proxy.newProxyInstance(metaclass.getClassLoader, Array(metaclass),
new InvocationHandler {
override def invoke(proxy:Object, method:Method, args:Array[Object]):Object = {
@hisui
hisui / brainfxxk.al.txt
Created February 20, 2012 13:11
brainfxxk in AL
brainfuck_run Script :- next(Script, "", "0", "").
error Msg :- puts("Error: !$Msg!\n"), halt.
inc {(?<I>.*)0$}, Res :- !, Res = "${I}1".
inc {(?<I>.*)1$}, Res :- !, inc(I, J), Res = "${J}0".
inc X, "1" :- !.
dec A, C :- dec0(A, B), B = {^0*(?<C>.+)}.
dec0 {(?<I>.*)1$}, Res :- !, Res = "${I}0".
@hisui
hisui / jitexpr.cpp
Created March 24, 2012 12:51
簡易言語のJITコンパイラー方式の言語処理系
// programmed by hisui(https://github.com/hisui)
/**
*
* jitexpr は簡易言語のJITコンパイラー方式の言語処理系です
*
* スクリプトの記述例:
* def fib(n) {
* if(n < 3) 1 else fib(n-1) + fib(n-2);
* }
* i = 0;
@hisui
hisui / tetris.cpp
Created May 5, 2012 16:39
プログラミング教材用テトリス(Win32)
// build: g++ tetris.cpp -o tetris.exe gdi32.dll -Xlinker --enable-stdcall-fixup
#include <windows.h>
#include <time.h>
#include <algorithm>
#include <stdexcept>
static const int CELL_DIM_X = 17;
static const int CELL_DIM_Y = 17;