Skip to content

Instantly share code, notes, and snippets.

@ytomino
ytomino / urlsort.ml
Last active Apr 18, 2022
Sorting URLs
View urlsort.ml
let split_domain = String.split_on_char '.';;
let url_re =
Str.regexp "^\\([^:]*://\\)?\\([^/]*\\)\\(/[^?]*\\)?\\(\\?.*\\)?$";;
let split_url x =
let protocol, domain, path, query =
if Str.string_match url_re x 0 then (
let protocol = try Str.matched_group 1 x with Not_found -> "" in
let domain = Str.matched_group 2 x in
@ytomino
ytomino / c-bits-byteswap.adb
Last active Mar 17, 2022
zlib in x86_64-linux-gnu
View c-bits-byteswap.adb
-- This file is translated by "headmaster" version 0.31-1157199 (devel).
-- The original C header's license should be applied to this file.
-- All conditional-directives are expanded for the exclusive use of your
-- environment, it is not recommended to commit this file to any repository.
-------------------------------------------------------------------------------
package body C.bits.byteswap is
function bswap_32 (bsx : unsigned_int) return unsigned_int is
begin
return builtin_bswap32 (bsx);
end bswap_32;
@ytomino
ytomino / c-asm_generic-errno.ads
Last active Mar 17, 2022
iconv (glibc) in x86_64-linux-gnu
View c-asm_generic-errno.ads
-- This file is translated by "headmaster" version 0.31-1157199 (devel).
-- The original C header's license should be applied to this file.
-- All conditional-directives are expanded for the exclusive use of your
-- environment, it is not recommended to commit this file to any repository.
-------------------------------------------------------------------------------
package C.asm_generic.errno is
pragma Preelaborate;
EADDRINUSE : constant := 98;
EADDRNOTAVAIL : constant := 99;
EADV : constant := 68;
@ytomino
ytomino / c-alloca.ads
Last active Mar 17, 2022
GMP, MPFR, and MPC in x86_64-linux-gnu
View c-alloca.ads
-- This file is translated by "headmaster" version 0.31-1157199 (devel).
-- The original C header's license should be applied to this file.
-- All conditional-directives are expanded for the exclusive use of your
-- environment, it is not recommended to commit this file to any repository.
-------------------------------------------------------------------------------
with C.stddef;
package C.alloca is
pragma Preelaborate;
function alloca (size : stddef.size_t) return void_ptr;
pragma Import (C, alloca, "alloca");
@ytomino
ytomino / c-bits-byteswap.adb
Last active Aug 10, 2021
OpenSSL in x86_64-linux-gnu
View c-bits-byteswap.adb
-- This file is translated by "headmaster" version 0.30-e83b81d (devel).
-- The original C header's license should be applied to this file.
-- All conditional-directives are expanded for the exclusive use of your
-- environment, it is not recommended to commit this file to any repository.
-------------------------------------------------------------------------------
package body C.bits.byteswap is
function bswap_32 (bsx : unsigned_int) return unsigned_int is
begin
return builtin_bswap32 (bsx);
end bswap_32;
@ytomino
ytomino / c-bits-mman.ads
Created Jun 15, 2021
Boehm GC in x86_64-linux-gnu
View c-bits-mman.ads
-- This file is translated by "headmaster" version 0.30-e83b81d (devel).
-- The original C header's license should be applied to this file.
-- All conditional-directives are expanded for the exclusive use of your
-- environment, it is not recommended to commit this file to any repository.
-------------------------------------------------------------------------------
package C.bits.mman is
pragma Preelaborate;
MAP_32BIT : constant := 64;
MAP_DENYWRITE : constant := 2048;
MAP_EXECUTABLE : constant := 4096;
@ytomino
ytomino / c-alloca.ads
Last active Jun 10, 2021
libyaml in x86_64-linux-gnu
View c-alloca.ads
-- This file is translated by "headmaster" version 0.30-e83b81d (devel).
-- The original C header's license should be applied to this file.
-- All conditional-directives are expanded for the exclusive use of your
-- environment, it is not recommended to commit this file to any repository.
-------------------------------------------------------------------------------
with C.stddef;
package C.alloca is
pragma Preelaborate;
function alloca (size : stddef.size_t) return void_ptr;
pragma Import (C, alloca, "alloca");
@ytomino
ytomino / c-alloca.ads
Last active Jun 10, 2021
libxml2 in x86_64-linux-gnu
View c-alloca.ads
-- This file is translated by "headmaster" version 0.30-e83b81d (devel).
-- The original C header's license should be applied to this file.
-- All conditional-directives are expanded for the exclusive use of your
-- environment, it is not recommended to commit this file to any repository.
-------------------------------------------------------------------------------
with C.stddef;
package C.alloca is
pragma Preelaborate;
function alloca (size : stddef.size_t) return void_ptr;
pragma Import (C, alloca, "alloca");
@ytomino
ytomino / magicmoduletype.ml
Created Apr 25, 2021
GADTの型パラメータをObj.magicで一致させることで無関係な後続の式の型チェックを回避できる
View magicmoduletype.ml
module type T1 = sig
type t (* any abstract type *)
val one: t
end;;
module M1: T1 = Int;;
type 'a repr = C1: M1.t repr (* GADT is needed *)
let one: string =
@ytomino
ytomino / bing-daily-wallpaper
Last active Oct 8, 2019
Use "bing Wallpaper" on macOS
View bing-daily-wallpaper
#!/bin/bash
# Thanks to https://ubuntuforums.org/showthread.php?t=2074098
[[ -z "$HOME" ]] && exit 1
[[ -z "$TMPDIR" ]] && exit 1
# $bing is needed to form the fully qualified URL for
# the Bing pic of the day
bing="www.bing.com"