text stringlengths 0 601k |
|---|
let is_active x = not ! disabled && ( ! current ) . active . ( number x ) |
let is_error x = not ! disabled && ( ! current ) . error . ( number x ) |
let alert_is_active { kind ; _ } = not ! disabled && let ( set , pos ) = ( ! current ) . alerts in Misc . Stdlib . String . Set . mem kind set = pos |
let alert_is_error { kind ; _ } = not ! disabled && let ( set , pos ) = ( ! current ) . alert_errors in Misc . Stdlib . String . Set . mem kind set = pos |
let mk_lazy f = let state = backup ( ) in lazy ( let prev = backup ( ) in restore state ; try let r = f ( ) in restore prev ; r with exn -> restore prev ; raise exn ) |
let set_alert ~ error ~ enable s = let upd = match s with | " all " -> ( Misc . Stdlib . String . Set . empty , not enable ) | s -> let ( set , pos ) = if error then ( ! current ) . alert_errors else ( ! current ) . alerts in let f = if enable = pos then Misc . Stdlib . String . Set . add else Misc . Stdlib . String . ... |
let parse_alert_option s = let n = String . length s in let id_char = function | ' a ' . . ' z ' | ' A ' . . ' Z ' | ' _ ' | ' ' ' \ | ' 0 ' . . ' 9 ' -> true | _ -> false in let rec parse_id i = if i < n && id_char s . [ i ] then parse_id ( i + 1 ) else i in let rec scan i = if i = n then ( ) else if i + 1 = n then ra... |
let parse_opt error active errflag s = let flags = if errflag then error else active in let set i = if i = 3 then set_alert ~ error : errflag ~ enable : true " deprecated " else flags . ( i ) <- true in let clear i = if i = 3 then set_alert ~ error : errflag ~ enable : false " deprecated " else flags . ( i ) <- false i... |
let parse_options errflag s = let error = Array . copy ( ! current ) . error in let active = Array . copy ( ! current ) . active in parse_opt error active errflag s ; current := { ( ! current ) with error ; active } |
let ( ) = parse_options false defaults_w ; ; |
let ( ) = parse_options true defaults_warn_error ; ; |
let ref_manual_explanation ( ) = let [ @ manual . ref " s : comp - warnings " ] chapter , section = 9 , 5 in Printf . sprintf " ( See manual section % d . % d ) " chapter section |
let message = function | Comment_start -> " this ` let sub_locs = if not alert . def . loc_ghost && not alert . use . loc_ghost then [ alert . def , " Definition " ; alert . use , " Expected signature " ; ] else [ ] in ` Active { id = alert . kind ; message ; is_error ; sub_locs ; } |
let reset_fatal ( ) = nerrors := 0 |
let check_fatal ( ) = if ! nerrors > 0 then begin nerrors := 0 ; raise Errors ; end ; ; ; |
let descriptions = [ 1 , " Suspicious - looking start - of - comment mark . " ; 2 , " Suspicious - looking end - of - comment mark . " ; 3 , " Deprecated synonym for the ' deprecated ' alert " ; 4 , " Fragile pattern matching : matching that will remain complete even \ n \ \ if additional constructors are added to one ... |
let help_warnings ( ) = List . iter ( fun ( i , s ) -> Printf . printf " % 3i % s \ n " i s ) descriptions ; print_endline " A all warnings " ; for i = Char . code ' b ' to Char . code ' z ' do let c = Char . chr i in match letter c with | [ ] -> ( ) | [ n ] -> Printf . printf " % c Alias for warning % i . \ n " ( Char... |
let err = T . err Warp_error |
type resample_t = | Nearest_neighbor | Bilinear | Cubic | Cubic_spline | Lanczos |
let int_of_resample = function | Nearest_neighbor -> 0 | Bilinear -> 1 | Cubic -> 2 | Cubic_spline -> 3 | Lanczos -> 4 |
module Options = struct module Raw = struct type warp_options_t type t = warp_options_t structure ptr let t : warp_options_t structure typ = structure " GDALWarpOptions " let f n k = field t n k let warp_options = f " warp_options " ( ptr string_opt ) let memory_limit = f " memory_limit " double let resample_alg = f " ... |
let reproject_image = Lib . c " GDALReprojectImage " ( Data_set . t @-> string_opt @-> Data_set . t @-> string_opt @-> int @-> double @-> double @-> ptr void @-> ptr void @-> ptr Options . Raw . t @-> returning err ) |
let reproject_image ( ? memory_limit = 0 . 0 ) ( ? max_error = 0 . 0 ) ? options ? src_wkt ? dst_wkt ~ src ~ dst alg = let options = match options with | None -> from_voidp Options . Raw . t null | Some { Options . o ; _ } -> o in reproject_image src src_wkt dst dst_wkt ( int_of_resample alg ) memory_limit max_error nu... |
let create_and_reproject_image = Lib . c " GDALCreateAndReprojectImage " ( Data_set . t @-> string_opt @-> string @-> string_opt @-> Driver . t @-> ptr string_opt @-> int @-> double @-> double @-> ptr void @-> ptr void @-> ptr Options . Raw . t @-> returning err ) |
let create_and_reproject_image ( ? memory_limit = 0 . 0 ) ( ? max_error = 0 . 0 ) ? options ? src_wkt ? dst_wkt ( ? create_options = [ ] ) src ~ filename driver alg = let options = match options with | None -> from_voidp Options . Raw . t null | Some { Options . o ; _ } -> o in let create_options = Lib . convert_creati... |
let auto_create_warped_vrt = Lib . c " GDALAutoCreateWarpedVRT " ( Data_set . t @-> string_opt @-> string_opt @-> int @-> float @-> ptr Options . Raw . t @-> returning Data_set . t_opt ) |
let auto_create_warped_vrt ? src_wkt ? dst_wkt ( ? max_error = 0 . 0 ) ? options src alg = let options = match options with | None -> from_voidp Options . Raw . t null | Some { Options . o ; _ } -> o in let result = auto_create_warped_vrt src src_wkt dst_wkt ( int_of_resample alg ) max_error options in match result wit... |
type warp_output_t = { geo_transform : Geo_transform . t ; dims : int * int ; } |
let suggested_warp_output arg = Lib . c " GDALSuggestedWarpOutput " ( Data_set . t @-> Foreign . funptr ( Transform . transform_t arg ) @-> arg @-> ptr double @-> ptr int @-> ptr int @-> returning err ) |
let suggested_warp_output ds transform = let transform_t = Transform . get_transform_t transform in let transform_f = Transform . get_transform_c transform in let geo_transform = Geo_transform . make ~ origin ( : 0 . 0 , 0 . 0 ) ~ pixel_size ( : 0 . 0 , 0 . 0 ) ~ rotation ( : 0 . 0 , 0 . 0 ) in let pixels = allocate_n ... |
module Operation = struct type raw_t = T . t let t = T . t type ' a t = { t : raw_t ; options : ' a Options . t ; } let create = Lib . c " GDALCreateWarpOperation " ( ptr Options . Raw . t @-> returning t ) let destroy = Lib . c " GDALDestroyWarpOperation " ( t @-> returning void ) let create options = let result = cre... |
let init ( ) = Gdal . Lib . init_dynamic ( ) ; Gdal . Lib . register_all ( ) ; ( ) |
let usage_and_exit ( ) = prerr_endline " Usage : warptut [ src ] [ dst ] " ; prerr_endline " [ src ] must exist " ; prerr_endline " [ dst ] must not exist " ; exit 1 |
let parse_args ( ) = try let s = Sys . argv . ( 1 ) in let d = Sys . argv . ( 2 ) in if Sys . file_exists s && not ( Sys . file_exists d ) then s , d else raise Exit with | _ -> usage_and_exit ( ) |
let ( ) = init ( ) ; let src_file , dst_file = parse_args ( ) in let src_ds = Gdal . Data_set . of_source_exn src_file in let dst_bands = Gdal . Data_set . get_count src_ds in let dst_dt = Gdal . Band . Data . Float32 in let driver = Gdal . Driver . get_by_name_exn " GTiff " in let dst_sr = Gdal . Spatial_reference . m... |
let rec highest_timestamp ( ? highest = 0 . ) folders = match folders with | [ ] -> highest | file :: rest -> ( let is_dir = Sys . is_directory file in match is_dir with | ` Yes -> let inside_dirs = Sys . ls_dir file in let inside_dirs = List . map inside_dirs ~ f ( : fun x -> file ^ " " / ^ x ) in highest_timestamp ~ ... |
let rec has_changed ( last_change : float ) ( folders : string list ) : float option = match folders with | [ ] -> None | file :: rest -> ( let is_dir = Sys . is_directory file in match is_dir with | ` Yes -> let inside_dirs = Sys . ls_dir file in let inside_dirs = List . map inside_dirs ~ f ( : fun x -> file ^ " " / ^... |
let rec watch last_timestamp path ~ f = Unix . sleep 1 ; match has_changed last_timestamp path with | None -> watch last_timestamp path ~ f | Some new_timestamp -> printf " some changes were observed ( timestamp % f ) . Rebuilding . . . \ n " %! new_timestamp ; ( try f ( ) with some_exception -> printf " there ' s an e... |
let main path ~ f = let last_timestamp = highest_timestamp path in watch last_timestamp path ~ f |
let src = Logs . Src . create " sesame . watch " ~ doc " : Current sesame file watcer " |
module Log = ( val Logs . src_log src : Logs . LOG ) |
type t = ( Fpath . t , string list ) Hashtbl . t |
let create ( ) = Hashtbl . create 256 |
let record ~ path ~ job_id watcher = Hashtbl . replace watcher ( Fpath . normalize path ) job_id |
let get_job_id x = let open Current . Syntax in let + md = Current . Analysis . metadata x in match md with Some { Current . Metadata . job_id ; _ } -> job_id | None -> None |
let job_id ~ path watcher = Hashtbl . find_opt watcher ( Fpath . normalize path ) |
module FS = struct open Lwt . Infix type t = { f : unit -> unit Lwt . t ; cond : unit Lwt_condition . t ; unwatch : unit -> unit Lwt . t ; } let run_job ~ watcher ~ engine ~ dir path = let path = Fpath . ( v dir // path ) in Hashtbl . iter ( fun k _ -> print_endline ( Fpath . to_string k ) ) watcher ; let state = Curre... |
module Js = struct let script ~ port = Fmt . str { |< script > var socket = new WebSocket ( ' ws :// localhost :% i / websocket ' ) ; socket . onopen = function ( ) { socket . send ( " Reload Me Please " ) ; ! } ; socket . onmessage = function ( e ) { window . location . reload ( ) } </ script > } | port [ @@ ocamlform... |
module Raw = struct module Response = struct type t = | Ok of Yojson . Safe . t | EndOfStream | Error of string end module Connection = struct type t = { send : Yojson . Safe . t -> unit Lwt . t ; receive : unit -> Response . t Lwt . t ; shutdown : unit -> unit Lwt . t ; } let send { send ; _ } = send let receive { rec... |
module Filter = struct type t = { base_names : string list ; whole_names : string list ; suffixes : string list ; } [ @@ deriving sexp , compare , hash ] let from_server_configurations ~ critical_files ~ extensions ~ source_paths ( ) = let base_name_of = function | CriticalFile . BaseName name -> Some name | CriticalFi... |
module Subscriber = struct module Setting = struct type t = { raw : Raw . t ; root : PyrePath . t ; filter : Filter . t ; } end type t = { setting : Setting . t ; connection : Raw . Connection . t ; initial_clock : string ; } let send_request ~ connection request = let open Lwt . Infix in Raw . Connection . send connec... |
module SinceQuery = struct module Since = struct module SavedState = struct type t = { storage : string ; project_name : string ; project_metadata : string option ; } [ @@ deriving sexp , compare , hash ] let watchman_expression_of { storage ; project_name ; project_metadata } = let storage_entry = " storage " , ` Stri... |
let test_low_level_apis _ = let open Lwt . Infix in let open Watchman . Raw in let test_connection connection = let assert_member_exists ~ key json = match Yojson . Safe . Util . member key json with | ` Null -> let message = Format . sprintf " Failed to find required JSON member : % s " key in assert_failure message |... |
let test_subscription _ = let open Lwt . Infix in let root = PyrePath . create_absolute " / fake / root " in let version_name = " fake_watchman_version " in let subscription_name = " my_subscription " in let initial_clock = " fake : clock : 0 " in let initial_success_response = ` Assoc [ " version " , ` String version_... |
let test_filter_expression context = let assert_expression ~ expected filter = let actual = Watchman . Filter . watchman_expression_of filter in assert_equal ~ ctxt : context ~ cmp : Yojson . Safe . equal ~ printer : Yojson . Safe . pretty_to_string expected actual in assert_expression { Watchman . Filter . base_names ... |
let test_filter_creation context = let assert_filter ~ expected : { Watchman . Filter . base_names = expected_base_names ; whole_names = expected_whole_names ; suffixes = expected_suffixes ; } { Watchman . Filter . base_names = actual_base_names ; whole_names = actual_whole_names ; suffixes = actual_suffixes ; } = let ... |
let test_since_query_request context = let open Watchman . SinceQuery in let root = PyrePath . create_absolute " / fake / root " in let filter = { Watchman . Filter . base_names = [ " . pyre_configuration " ] ; whole_names = [ ] ; suffixes = [ " . py " ] } in let assert_request ~ expected request = let actual = watchma... |
let test_since_query_response context = let open Watchman . SinceQuery in let assert_response ~ expected response = let actual = Response . of_watchman_response response in assert_equal ~ ctxt : context ~ cmp [ :% compare . equal : Response . t option ] ~ printer ( : fun response -> [ % sexp_of : Response . t option ] ... |
let test_since_query _ = let open Lwt . Infix in let mock_raw = let send _ = Lwt . return_unit in let receive ( ) = Lwt . return_none in Watchman . Raw . create_for_testing ~ send ~ receive ( ) in Lwt . catch ( fun ( ) -> Watchman . Raw . with_connection mock_raw ~ f ( : fun connection -> Watchman . SinceQuery . ( quer... |
let ( ) = " watchman_test " >::: [ " low_level " >:: OUnitLwt . lwt_wrapper test_low_level_apis ; " subscription " >:: OUnitLwt . lwt_wrapper test_subscription ; " filter_expression " >:: test_filter_expression ; " filter_creation " >:: test_filter_creation ; " since_query_request " >:: test_since_query_request ; " sin... |
let uri = ref " http :// 127 . 0 . 0 . 1 " / |
let username = ref " root " |
let password = ref " password " |
let start = ref 0 |
let interval = ref 5 |
let exn_to_string = function | Api_errors . Server_error ( code , params ) -> Printf . sprintf " % s % s " code ( String . concat " " params ) | e -> Printexc . to_string e |
let main ( ) = let rpc = make ! uri in Session . login_with_password ~ rpc ~ uname :! username ~ pwd :! password ~ version " : 1 . 0 " ~ originator " : watch_metrics " >>= fun session_id -> Lwt . finalize ( fun ( ) -> Host . get_all ~ rpc ~ session_id >>= fun hosts -> let host = List . hd hosts in Host . get_data_sourc... |
let _ = Arg . parse [ " - uri " , Arg . Set_string uri , ( Printf . sprintf " URI of server to connect to ( default % s ) " ! uri ) ; " - u " , Arg . Set_string username , ( Printf . sprintf " Username to log in with ( default % s ) " ! username ) ; " - pw " , Arg . Set_string password , ( Printf . sprintf " Password t... |
type watch = { name : string ; embed_path : string ; thumbnail_path : string ; description : string option ; published_at : string ; updated_at : string ; language : string ; category : string ; } |
type t = { watch : watch list } |
let get_publish_date json = match Ezjsonm . find json [ " originallyPublishedAt " ] with | ` Null -> ( match Ezjsonm . find json [ " publishedAt " ] with | ` String s -> s | _ -> failwith " Couldn ' t calculate the videos published date ) " | ` String s -> s | _ -> failwith " Couldn ' t calculate the videos original pu... |
let get_update_date json = match Ezjsonm . find_opt json [ " updatedAt " ] with | Some ( ` String s ) s -> s | _ -> failwith " Couldn ' t find the video ' s updatedAt date " |
let get_language_category json = let label = Ezjsonm . find json [ " label " ] in Ezjsonm . get_string label |
let get_string_or_none = function ` String s -> Some s | _ -> None |
let of_json json = { name = Ezjsonm . find json [ " name " ] |> Ezjsonm . get_string ; description = Ezjsonm . find json [ " description " ] |> get_string_or_none ; embed_path = Ezjsonm . find json [ " embedPath " ] |> Ezjsonm . get_string ; thumbnail_path = Ezjsonm . find json [ " thumbnailPath " ] |> Ezjsonm . get_st... |
let watch_to_yaml t = ` O ( [ ( " name " , ` String t . name ) name ] @ ( match t . description with | Some s -> [ ( " description " , ` String s ) s ] | None -> [ ] ) @ [ ( " embed_path " , ` String t . embed_path ) embed_path ; ( " thumbnail_path " , ` String t . thumbnail_path ) thumbnail_path ; ( " published_at " ,... |
let to_yaml t = ` O [ ( " watch " , ` A ( List . map watch_to_yaml t . watch ) watch ) watch ] |
let videos_url = Uri . of_string " https :// watch . ocaml . org / api / v1 / videos " |
let get_videos ? start ( ) = let query_params = match start with | None -> [ ( " count " , [ string_of_int max_count_per_request ] ) ] | Some s -> [ ( " start " , [ string_of_int s ] ) ; ( " count " , [ string_of_int max_count_per_request ] ) ; ] in let * response = Client . Oneshot . get ( Uri . add_query_params video... |
let get_all_videos ( ) = let get_videos_or_err results = try Ok ( List . map ( function Ok v -> v | Error err -> failwith ( Error . to_string err ) err ) err results ) results with Failure m -> Error ( ` Msg m ) m in let * total , first = get_videos ( ) in let + rest = if total > max_count_per_request then let reqs = (... |
let run ( ) = match Lwt_main . run @@ get_all_videos ( ) with | Ok v -> v | Error err -> Fmt . epr " % s " ( Error . to_string err ) err ; exit 1 |
let ( ) = let watch = run ( ) |> List . stable_sort ( fun w1 w2 -> String . compare w1 . name w2 . name ) name in let videos = { watch } in let yaml = to_yaml videos in Yaml . pp Format . std_formatter yaml |
let is_a_source_file path = ( match Path . extension path with | " . flv " | " . gif " | " . ico " | " . jpeg " | " . jpg " | " . mov " | " . mp3 " | " . mp4 " | " . otf " | " . pdf " | " . png " | " . ttf " | " . woff " -> false | _ -> true ) && Path . is_file path |
let subst_string s path ~ map = let len = String . length s in let longest_var = String . longest ( String . Map . keys map ) in let double_percent_len = String . length " " %% in let loc_of_offset ~ ofs ~ len = let rec loop lnum bol i = if i = ofs then let pos = { Lexing . pos_fname = Path . to_string path ; pos_cnum ... |
let subst_file path ~ map = let s = Io . read_file path in let s = if Path . is_root ( Path . parent_exn path ) && Package . is_opam_file path then " version : " " \%% ^ " VERSION_NUM " ^ " " %%\\ n " ^ s else s in match subst_string s ~ map path with | None -> ( ) | Some s -> Io . write_file path s |
module Dune_project = struct include Dune_project type ' a simple_field = { loc : Loc . t ; loc_of_arg : Loc . t ; arg : ' a } type t = { contents : string ; name : Package . Name . t simple_field option ; version : string simple_field option ; project : Dune_project . t } let filename = Path . in_source Dune_project .... |
let make_watermark_map ~ commit ~ version ~ dune_project ~ info = let dune_project = Dune_project . project dune_project in let version_num = let open Option . O in let + version = version in Option . value ~ default : version ( String . drop_prefix version ~ prefix " : v " ) in let name = Dune_project . name dune_proj... |
let subst vcs = let + ( version , commit ) , files = Memo . run ( Memo . fork_and_join ( fun ( ) -> Memo . fork_and_join ( fun ( ) -> Vcs . describe vcs ) ( fun ( ) -> Vcs . commit_id vcs ) ) ( fun ( ) -> Vcs . files vcs ) ) in let dune_project : Dune_project . t = match let files = List . fold_left files ~ init : Stri... |
let subst ( ) = match Sys . readdir " . " |> Array . to_list |> String . Set . of_list |> Vcs . Kind . of_dir_contents with | None -> Fiber . return ( ) | Some kind -> subst { kind ; root = Path . root } |
type exarray = { mutable len : int ; mutable data : t array ; } |
let make ( ) = { len = 0 ; data = [ ] ; || } |
let extend t = let len = Array . length t . data in t . data <- Array . init ( len + n ) ( fun i -> if i < len then t . data . ( i ) else empty ) |
let rec set a i v = if i >= Array . length a . data then begin extend a ; set a i v end else begin a . data . ( i ) <- v ; a . len <- max a . len ( i + 1 ) end |
let get a i = a . data . ( i ) |
let length a = a . len |
let data a = a . data |
type wave = { name : string ; nbits : int ; data : exarray ; } |
type waves = wave array |
let wrap sim = let ports p = List . map ( fun s -> { name = fst s ; nbits = B . width ( ! snd s ) ; data = make ( ) ; } ) p in let in_ports = ports sim . sim_in_ports in let out_ports = ports sim . sim_out_ports in let trace i x = List . iter2 ( fun a b -> set a . data i ( ! snd b ) ) x in let cycle = ref 0 in let sim_... |
module Gui = struct module D = Dom_html let jstr = Js . string let jstri x = jstr ( string_of_int x ) let line ( ~ ctx : D . canvasRenderingContext2D Js . t ) ~ x0 ~ y0 ~ x1 ~ y1 = let f = float_of_int in ctx ( ## moveTo ( f x0 ) ( f y0 ) ) ; ctx ( ## lineTo ( f x1 ) ( f y1 ) ) let delta d = let len = Array . length d ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.