Skip to content

Instantly share code, notes, and snippets.

View avsm's full-sized avatar
💭
never gonna git u up, never gona git u down, never gonna turn around and reset u

Anil Madhavapeddy avsm

💭
never gonna git u up, never gona git u down, never gonna turn around and reset u
View GitHub Profile
module Int = struct
type t = int
let compare : int -> int -> int = compare
end
module M = Map.Make(Int)
type +'a elt
type 'a map = 'a elt M.t
let addA (x : 'a) (m : [> `A of 'a] map) =
(* defines the Ast.binding for a function of form:
let fun_name ?(opt_arg1) ?(opt_arg2) final_ident = function_body ...
XXX: figure out the quotation magic for this, if such exists
*)
let function_with_label_args _loc ~fun_name ~final_ident ~function_body ~return_type opt_args =
let opt_args = opt_args @ [ <:patt< $lid:final_ident$ >> ] in
let rec fn _loc = function
|hd::tl ->
Ast.ExFun(_loc,
Ast.McArr(_loc,
@avsm
avsm / gist:166645
Created August 12, 2009 18:03 — forked from jaked/gist:166609
(* defines the Ast.binding for a function of form:
let fun_name ?(opt_arg1) ?(opt_arg2) final_ident = function_body ...
*)
let function_with_label_args _loc ~fun_name ~final_ident ~function_body ~return_type opt_args =
let opt_args = opt_args @ [ <:patt< $lid:final_ident$ >> ] in
<:binding< $lid:fun_name$ =
$List.fold_right (fun b a ->
<:expr<fun $b$ -> $a$ >>
) opt_args <:expr< ( $function_body$ : $return_type$ ) >>
$ >>
#!/usr/bin/env ruby
require 'rubygems'
require 'findmyiphone'
username = ENV.fetch("MOBILEME_USERNAME")
password = ENV.fetch("MOBILEME_PASSWORD")
puts "logging in as: #{username}@me.com"
i = FindMyIphone.new(username, password)
Ast.ExApp (_loc,
Ast.ExApp (_loc,
Ast.ExApp (_loc, Ast.ExId (_loc, Ast.IdLid (_loc, "fn")),
Ast.ExId (_loc, Ast.IdLid (_loc, "arg1"))),
Ast.ExId (_loc, Ast.IdLid (_loc, "arg2"))),
Ast.ExId (_loc, Ast.IdLid (_loc, "arg3")))
#!/usr/bin/env python
import sys, os, subprocess
import XenAPI, inventory, xmlrpclib
xenconsole = "/usr/lib/xen/bin/xenconsole"
def attach_console(session, uuid):
vmref = session.xenapi.VM.get_by_uuid(uuid)
try:
module type FLOW = sig
(* Type of an individual flow *)
type t
(* Type that manages a collection of flows *)
type mgr
(* Type that identifies a flow source and destination endpoint *)
type src
type dst
(* Read and write to a flow *)
@avsm
avsm / gist:918401
Created April 13, 2011 20:59
Echo server
let echo () =
lwt mgr, mgr_t = Manager.create () in
let src = None, 8081 in
Flow.listen mgr (`TCPv4 (src,
(fun (addr, port) t ->
Console.log "From %s:%d" (ipv4_addr_to_string addr) port);
let rec echo () =
lwt res = Flow.read t in
match res with
|None ->
@avsm
avsm / gist:984125
Created May 21, 2011 01:29
delimcc fragment that seems to fail on ocamlopt but work in ocamlc
open Printf
open Delimcc
let p = new_prompt ()
let main () =
let kr = ref (fun _ -> ()) in
push_prompt p (fun () ->
let foo = 15 in
let bar = foo +
@avsm
avsm / hmod.ml
Created September 1, 2011 22:47
hotplug with objects
module type DEVICE = sig
type t
val create: string -> t
val id: t -> string
val read: t -> string
end
module Dummy : DEVICE = struct
type t = string
let create id = id