Skip to content

Instantly share code, notes, and snippets.

View philtomson's full-sized avatar

Phil Tomson philtomson

View GitHub Profile
@philtomson
philtomson / cpp_quiz_118
Created March 7, 2014 17:32
C++ Quiz #118
#include <iostream>
void print(char const *str) { std::cout << str; }
void print(short num) { std::cout << num; }
int main() {
print("abc");
print(0);
print('A');
}
@philtomson
philtomson / qtree.ml
Last active December 28, 2015 07:59
quad tree implementation in OCaml (not yet complete)
type base = A | C | G | T | ROOT ;;
let base_to_s b = match b with
| A -> "A"
| C -> "C"
| G -> "G"
| T -> "T"
| _ -> "ROOT";;
let char_to_base c = match c with
| 'a' | 'A' -> A
@philtomson
philtomson / graphics_in_toplevel
Created October 23, 2012 17:09
Using Graphics module in Ocaml toplevel
(* SEE: http://mirror.ocamlcore.org/wiki.cocan.org/tips_for_using_the_ocaml_toplevel.html *)
$ ocaml
# #use "topfind" ;;
Findlib has been successfully loaded. Additional directives:
#require "package";; to load a package
#list;; to list the available packages
#camlp4o;; to load camlp4 (standard syntax)
#camlp4r;; to load camlp4 (revised syntax)
#predicates "p,q,...";; to set these predicates
@philtomson
philtomson / dep_gen.rb
Created September 20, 2012 00:28
generates a dependency graph that can run tasks in parallel
require 'rubygems'
require 'json'
require 'pp'
require 'rake'
class MAS
attr_reader :scripts, :parallel_tasks
def initialize
@scripts = JSON.parse(File.read("mas.json"))
@to_run = []
@philtomson
philtomson / mas.json
Created September 20, 2012 00:27
test json file for dep_gen.rb
{
"A" :
{
"path": "",
"args": "",
"depends": []
},
"B" :
{
"path": "",
@philtomson
philtomson / deg_graph.ml
Created September 19, 2012 14:32
dependency graph
type node = { cmd: string;
deps: node list }
let nodeA = { cmd = "A";
deps = [] }
let nodeB = { cmd = "B";
deps = [] }
@philtomson
philtomson / op_parser.cpp
Created September 15, 2012 17:02
Using boost::program_options
//To compile:
//g++ -I /usr/include/boost -o op_parser op_parser.cpp /usr/lib64/libboost_program_options-mt.a
#include <iostream>
#include "boost/program_options.hpp"
namespace po = boost::program_options;
using namespace std;
int main(int argc, char** argv){
string list_file;
@philtomson
philtomson / test.cpp
Created September 11, 2012 03:27
some c++11 testing
//compile with:
//g++ -std=c++11 -o test test.cpp
#include <iostream>
#include <map>
#include <vector>
typedef std::vector<std::string> StrVec;
typedef std::map<std::string, StrVec > MapStr2Vec;
MapStr2Vec mmap;
@philtomson
philtomson / puzzle_2.ml
Created May 29, 2012 21:15
puzzle_2 with swap ops in tournament selection 25% of the time
(* Inspired by this puzzle from NPR:
http://www.npr.org/2012/01/29/146034893/this-puzzle-is-the-pits
(see the 'Next Weeks' challenge section there):
"Next Week's Challenge from listener Ed Pegg Jr.: Write the digits from
1 to 9 in a line. If you put times signs after the 2 and 4, a plus
sign after the 5, and a minus sign after the 7, you have
12 x 34 x 5 + 67 - 89, which equals 2018.
That's six years off from our current year 2012. This example uses
four arithmetic symbols. The object is to use just three of the
following arithmetic operations: addition, subtraction, multiplication
@philtomson
philtomson / counting.ml
Created May 7, 2012 17:26
counting base 5
(* POSET probably works better than RING here *)
module type RING =
sig
type t
val max : t
val min : t
val succ : t -> t
val val_to_s : t -> string
end