Skip to content

Instantly share code, notes, and snippets.

@channgo2203
channgo2203 / prob1.ml
Created May 23, 2016 18:05
Finding shortest substrings that contain all strings in a given list
(*
* find the shortest substring of str containing the strings str1 str2,...,strm in a list
*)
(* use core for more efficient with long strings *)
open Core.Std
open Printf
(*
* find substring sub in string str forward from pos
@channgo2203
channgo2203 / listplus.mli
Created May 23, 2016 18:14
Extra List Interface
(**************************************************************************)
(*
* Listplus
*
*
* Copyright 2016 Van-Chan Ngo.
*
* All rights reserved. This file is distributed under the terms of
* the GNU Lesser General Public License version 2.1, with the
* special exception on linking described in the file LICENSE.
@channgo2203
channgo2203 / listplus.ml
Created May 23, 2016 18:16
Extra List Implementation
let rec last l =
match l with
| [] -> None
| [x] -> Some x
| _::t -> last t
let biggest_prefix l =
let rec bpre_aux xs ys = match xs with
| [] -> ys
| [x] -> ys
@channgo2203
channgo2203 / introrx.md
Created June 10, 2016 15:14 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@channgo2203
channgo2203 / reactiveschemes.cpp
Created July 11, 2016 19:34
Reactive Sytem Implementation Schemes
InitializeMemory();
foreach input_event do
ComputeOutput();
UpdateMemory();
end
InitializeMemory();
foreach period do
let swap i j a =
try
let tmp = a.(j) in
a.(j) <- a.(i);
a.(i) <- tmp; a
with
_ -> raise (Invalid_argument "out-of-range")
(* auxiliary function *)
(* a[0 .. smaller - 1] : smaller region
let swap i j a =
try
let tmp = a.(j) in
a.(j) <- a.(i);
a.(i) <- tmp; a
with
_ -> raise (Invalid_argument "out-of-range")
(* auxiliary function *)
(* a[0 .. smaller - 1] : smaller region
let insert_all_positions x l =
let rec aux prev acc l =
match l with
| [] -> (prev @ [x]) :: acc |> List.rev
| hd::tl as l -> aux (prev @ [hd]) ((prev @ [x] @ l) :: acc) tl
in aux [] [] l;;
let rec permutation l =
match l with
permutation [1;2;3;4;5;6;7;8;9];;
Stack overflow during evaluation (looping recursion?).
@channgo2203
channgo2203 / merge_git_repo_as_subdir
Created July 2, 2020 20:54 — forked from smdabdoub/merge_git_repo_as_subdir
Merge one git repository into another repository as a sub-directory
# based on the following:
# http://saintgimp.org/2013/01/22/merging-two-git-repositories-into-one-repository-without-losing-file-history/
# http://blog.caplin.com/2013/09/18/merging-two-git-repositories/
git clone repo_main
git clone repo_sub
cd repo_main
git remote add repo_sub ../repo_sub
git fetch repo_sub