Skip to content

Instantly share code, notes, and snippets.

View gofer's full-sized avatar

Gofer gofer

View GitHub Profile
@gofer
gofer / list_shuffle.sml
Created August 15, 2018 16:36
List Shuffle in StandardML/NJ
fun shuffle xs = let
val rand = let
val seed = let
val max = IntInf.fromInt (
case(Int.maxInt)
of (Option.SOME max) => max
| Option.NONE => raise Fail("Can't get Int.maxInt")
);
val time = Time.now ();
val (_, seed1) = IntInf.divMod (Time.toSeconds time, max);
@gofer
gofer / qsort.sml
Created August 15, 2018 16:30
Quick Sort in Standard ML
(* クイックソート *)
(* val qsort = fn : ('a * 'a -> order) -> 'a list -> 'a list *)
(* val takePivot = fn : ('a * 'a -> order) -> 'a list -> 'a *)
fun qsort compare nil = nil
| qsort compare [x] = [x]
| qsort compare xs =
let
val pivot = takePivot compare xs;
val (ys, zs) = List.foldr (
fn (v, (ys, zs)) =>
@gofer
gofer / lambda_calc.js
Last active February 17, 2018 08:58
JavaScriptで(型無し)ラムダ計算
const I = (x) => x;
const K = (x) => (y) => x;
const S = (x) => (y) => (z) => x (z) (y (z));
const SII = (x) => S (I) (I) (x);
const KSII = (x) => K (SII) (x);
const Y = (x) => S (KSII) (S (S (K (S)) (K)) (KSII)) (x);
const T = K;
@gofer
gofer / sub_list.sml
Created November 21, 2017 14:54
Sub List
(* subList : 'a list -> 'a list list *)
fun subList v =
List.foldl
List.@
[ nil ]
(
List.map
(
fn x => (
fn v =>
@gofer
gofer / diffie_hellman.rb
Created October 12, 2017 13:47
Diffie-Hellman鍵交換アルゴリズム
require 'prime'
N = 100000
def nth_prime(n)
Prime.each.take(n).last
end
def power(x, n)
if n <= 1 then
GCC_HOME=/usr/local/gcc-5.2.0
GLIBC_HOME=/home/gofer/.local/glibc-2.22
OBJS_HOME=$(GCC_HOME)/lib/gcc/x86_64-unknown-linux-gnu/5.2.0
CC=gcc
CCFLAGS=-std=c99 -Wall -O3
LDFLAGS=--eh-frame-hdr -m elf_x86_64
#LDFLAGS+=-nostdlib -nostartfiles -static
LDFLAGS+=-rpath $(GLIBC_HOME)/lib -dynamic-linker=$(GLIBC_HOME)/lib/ld-linux-x86-64.so.2
LDFLAGS+=-L$(GCC_HOME)/lib -L$(GCC_HOME)/lib64 -L$(GLIBC_HOME)/lib -L$(OBJS_HOME) -R$(GLIBC_HOME)/lib
@gofer
gofer / Dockerfile
Last active November 15, 2017 03:29
NSD on Docker
FROM alpine:latest
MAINTAINER Gofer (@gofer_ex) <[email protected]>
ARG nsd_version=4.1.14
ARG control_port=8952
ENV NSD_VERSION=$nsd_version
ENV CONTROL_PORT=$control_port
@gofer
gofer / README.md
Last active May 9, 2017 19:18
BIOS hello world

How to build?

as -32 -o ./main.o ./main.s
ld -m elf_i386 -T ld.script -o ./a.out ./main.o
objcopy -j .text -j .data -O binary ./a.out ./boot.text.bin
@gofer
gofer / PKGBUILD
Last active March 27, 2017 12:34
GNU Hello PKGBUILD
# Contributor: Gofer <[email protected]>
pkgname=hello
pkgver=2.10
pkgrel=1
pkgdesc="The GNU Hello program produces a familiar, friendly greeting."
arch=('i686' 'x86_64')
url="https://www.gnu.org/software/hello/"
license=('GPL')
depends=('glibc')
@gofer
gofer / build.sh
Created March 25, 2017 18:48
LLVM+Clang 4.0.0
#!/bin/bash
VERSION='4.0.0'
DOWNLOAD='curl -O' # or 'wget'
EXTRACT='tar xf'
${DOWNLOAD} http://releases.llvm.org/${VERSION}/llvm-${VERSION}.src.tar.xz
${DOWNLOAD} http://releases.llvm.org/${VERSION}/cfe-${VERSION}.src.tar.xz
${DOWNLOAD} http://releases.llvm.org/${VERSION}/compiler-rt-${VERSION}.src.tar.xz