text stringlengths 12 786k |
|---|
type objectType object method alpha : bool t prop method depth : bool t prop method stencil : bool t prop method antialias : bool t prop method premultipliedAlpha : bool t prop method preserveDrawingBuffer : bool t prop method preferLowPowerToHighPerformance : bool t prop method failIfMajorPerformanceCaveat : b... |
let defaultContextAttributes = Js . Unsafe . ( obj [ | " alpha " , inject _true ; " depth " , inject _true ; " stencil " , inject _false ; " antialias " , inject _true ; " premultipliedAlpha " , inject _false ; " preserveDrawingBuffer " , inject _false ; "... |
type ' a uniformLocation object method size : int readonly_prop method _type : uniformType readonly_prop method name : js_string t readonly_prop end object method rangeMin : int readonly_prop method rangeMax : int readonly_prop method precision : int readonly_prop end object method canvas : Dom_html . canva... |
module Event = struct let webglcontextlost = Dom_html . Event . make " webglcontextlost " let webglcontextrestored = Dom_html . Event . make " webglcontextrestored " let webglcontextcreationerror = Dom_html . Event . make " webglcontextcreationerror " end object method getContext : js_strin... |
let getContext ( c : Dom_html . canvasElement t ) = let c : canvasElement t = Js . Unsafe . coerce c in let ctx = c ## getContext ( Js . string " webgl " ) in if Opt . test ctx then ctx else c ## ( getContext ( Js . string " experimental - webgl " ) ) |
let getContextWithAttributes ( c : Dom_html . canvasElement t ) attribs = let c : canvasElement t = Js . Unsafe . coerce c in let ctx = c ## getContext_ ( Js . string " webgl " ) attribs in if Opt . test ctx then ctx else c ## getContext_ ( Js . string " experimental - webgl " ) ... |
let error f = Printf . ksprintf ( fun s -> Firebug . console ## error ( Js . string s ) ; failwith s ) f |
let debug f = Printf . ksprintf ( fun s -> Firebug . console ## log ( Js . string s ) ) f |
let alert f = Printf . ksprintf ( fun s -> Dom_html . window ## alert ( Js . string s ) ; failwith s ) f |
let check_error gl = if gl ## getError <> gl . ## _NO_ERROR_ then error " WebGL error " |
let init_canvas canvas_id = let canvas = Opt . get ( Opt . bind ( Dom_html . document ## getElementById ( string canvas_id ) ) Dom_html . CoerceTo . canvas ) ( fun ( ) -> error " can ' t find canvas element % s " canvas_id ) in let gl = Opt . get ( try WebGL . getContext ... |
let load_shader ( gl : WebGL . renderingContext t ) shader text = gl ## shaderSource shader text ; gl ## compileShader shader ; if not ( to_bool ( gl ## getShaderParameter shader gl . ## _COMPILE_STATUS_ ) ) then error " An error occurred compiling the shaders : \ n % s \ n % s " ( ... |
let create_program ( gl : WebGL . renderingContext t ) vert_src frag_src = let vertexShader = gl ## createShader gl . ## _VERTEX_SHADER_ in let fragmentShader = gl ## createShader gl . ## _FRAGMENT_SHADER_ in load_shader gl vertexShader vert_src ; load_shader gl fragmentShader frag_src ; let pro... |
let get_source src_id = let script = Opt . get ( Opt . bind ( Dom_html . document ## getElementById ( string src_id ) ) Dom_html . CoerceTo . script ) ( fun ( ) -> error " can ' t find script element % s " src_id ) in script . ## text |
let float32array a = let array = new % js Typed_array . float32Array ( Array . length a ) in Array . iteri ( fun i v -> Typed_array . set array i v ) a ; array |
module Proj3D = struct type t = float array let scale x y z : t = [ | x ; 0 . ; 0 . ; 0 . ; 0 . ; y ; 0 . ; 0 . ; 0 . ; 0 . ; z ; 0 . ; 0 . ; 0 . ; 0 . ; 1 . ] | let translate x y z : t = [ | 1 . ; 0 . ; 0 . ; 0 . ; ... |
type line = | V of ( float * float * float ) | VN of ( float * float * float ) | F of ( ( int * int ) * ( int * int ) * ( int * int ) ) |
let line_regexp = Regexp . regexp " ( v | vn | f ) \\ ( [ ^\\ ] ) +\\ ( [ ^\\ ] ) +\\ ( [ ^\\ ] ) " + |
let couple_regexp = Regexp . regexp " ( [ 0 - 9 ] ) ( [ +// 0 - 9 ] ) " + |
let read_coord_couple c = match Regexp . string_match couple_regexp c 0 with | None -> None | Some res -> ( match List . map ( Regexp . matched_group res ) [ 1 ; 2 ] with | [ Some v ; Some vn ] -> Some ( int_of_string v , int_of_string vn ) | _ -> None ) |
let read_line l = match Regexp . string_match line_regexp l 0 with | None -> None | Some res -> ( match List . map ( Regexp . matched_group res ) [ 1 ; 2 ; 3 ; 4 ] with | [ Some " v " ; Some x ; Some y ; Some z ] -> Some ( V ( float_of_string x , float_of_string y ,... |
let concat a = let length = Array . fold_left ( fun len l -> len + List . length l ) 0 a in let next = let pos = ref ( - 1 ) in let l = ref [ ] in let rec aux _ = match ! l with | t :: q -> l := q ; t | [ ] -> incr pos ; l := a . ( ! pos ) ; aux 0 in aux in Array . ... |
let make_model vertex norm face = let vertex ' = Array . init ( Array . length face ) ( fun i -> let ( av , _an ) , ( bv , _bn ) , ( cv , _cn ) = face . ( i ) in let a1 , a2 , a3 = vertex . ( av - 1 ) in let b1 , b2 , b3 = vertex . ( bv - 1 ) in l... |
let read_model a = let vertex = ref [ ] in let norm = ref [ ] in let face = ref [ ] in Array . iter ( fun s -> match read_line s with | None -> ( ) | Some ( F ( a , b , c ) ) -> face := ( a , b , c ) :: ! face | Some ( V ( a , b , c ) ) -> vertex := ( ... |
let http_get url = XmlHttpRequest . get url >>= fun r -> let cod = r . XmlHttpRequest . code in let msg = r . XmlHttpRequest . content in if cod = 0 || cod = 200 then Lwt . return msg else fst ( Lwt . wait ( ) ) |
let getfile f = try Lwt . return ( Sys_js . read_file ~ name : f ) with Not_found -> http_get f >|= fun s -> s |
let fetch_model s = getfile s >|= fun s -> let a = Regexp . split ( Regexp . regexp " \ n " ) s in read_model ( Array . of_list a ) |
let pi = 4 . . * atan 1 . |
let start ( pos , norm ) = let fps_text = Dom_html . document ## createTextNode ( Js . string " loading " ) in Opt . iter ( Opt . bind ( Dom_html . document ## getElementById ( string " fps " ) ) Dom_html . CoerceTo . element ) ( fun span -> Dom . appendChild span fp... |
let go _ = ignore ( debug " fetching model " ; catch ( fun ( ) -> fetch_model " monkey . model " >>= start ) ( fun exn -> error " uncaught exception : % s " ( Printexc . to_string exn ) ) ) ; _true |
let _ = Dom_html . window . ## onload := Dom_html . handler go |
type event_kind = | New_thread | Thread_switch | Cycle_start | Cycle_end | Pid_is | Event | Measure_start | Measure_end | Trace_end |
type event = { name : string ; categories : string list ; phase : event_kind ; timestamp : int ; pid : int ; tid : int } |
type events = event list |
let create_event ( ? categories = [ ] ) ( ? pid = 0 ) 0 ( ? tid = 0 ) 0 ~ phase ~ timestamp name = { name ; categories ; phase ; timestamp ; pid ; tid } |
module Output = struct module JSON = struct let phase_of_kind = function | New_thread | Pid_is -> ` String " M " | Cycle_start -> ` String " b " | Cycle_end -> ` String " e " | Thread_switch -> ` String " X " | Event -> ` String " i " | Measure_start -> ` String " B " ... |
let emitk ~ buf ( k : event_kind ) event_kind pos = let num = match k with | New_thread -> 0 | Thread_switch -> 1 | Cycle_start -> 2 | Cycle_end -> 3 | Pid_is -> 4 | Event -> 5 | Measure_start -> 6 | Measure_end -> 7 | Trace_end -> 8 in Bigstring . set_uint8_exn buf ~ pos num ; po... |
let emiti ~ buf ( i : int ) int pos = Bigstring . set_uint64_le_exn buf ~ pos i ; pos + 8 |
let emits ~ buf ( s : string ) string ( pos : int ) int = let sl = String . length s in let pos = emiti ~ buf sl pos in Bigstring . From_string . blit ~ src : s ~ src_pos : 0 ~ len : sl ~ dst : buf ~ dst_pos : pos ; pos + sl |
let finish wr ~ buf final_len = Writer . write_bigstring wr ~ pos : 0 ~ len : final_len buf |
let emit_event wr ~ buf ( event : event ) event = match event . phase with | New_thread -> emitk ~ buf New_thread 0 |> emiti ~ buf event . timestamp |> emiti ~ buf event . tid |> emits ~ buf event . name |> finish ~ buf wr | Thread_switch -> emitk ~ buf Thread_switch 0 |> emiti ~ buf event ... |
module type IO = sig type ' + a t val ( ) >>= : ' a t -> ( ' a -> ' b t ) -> ' b t val return : ' a -> ' a t end |
module type S = sig type ' + a io type ' a result = | Ok of ' a | Error of int type ( ' a , ' body ) op = ' body Rd . t -> ( ' a result * ' body Rd . t ) io type ' body provider = ( ' body , ' body ) op type ' body acceptor = ( bool , ' body ) op type www_au... |
let default_variances = [ " Accept " ; " Accept - Encoding " ; " Accept - Charset " ; " Accept - Language " ] |
module type CLOCK = sig val now : unit -> int end |
module Make ( IO : IO ) ( Clock : CLOCK ) = struct type ' + a io = ' a IO . t open IO type ' a result = | Ok of ' a | Error of int type ( ' a , ' body ) op = ' body Rd . t -> ( ' a result * ' body Rd . t ) io type ' body provider = ( ' body , ' body ) op... |
module Session = struct module Backend = struct include Session . Lift . IO ( Deferred ) ( Session . Memory ) let create ( ) = Session . Memory . create ( ) end include Session_webmachine . Make ( Deferred ) ( Backend ) end |
module UnixClock = struct let now ( ) = int_of_float ( Unix . gettimeofday ( ) ) end inherit [ Body . t ] resource inherit [ Body . t ] Session . manager ~ cookie_key backend method private increment session rd = let value = string_of_int ( 1 + int_of_string session . Session . ... |
let main ( ) = let port = 8080 in let mem = Session . Backend . create ( ) in let routes = [ " " , /* fun ( ) -> new counter mem ] in let dispatch = dispatch ' routes in let handler ~ body _ request = dispatch ~ body ~ request >>| begin function | None -> ( ` Not_found , ... |
let _ = Mirage_crypto_rng_unix . initialize ( ) ; Scheduler . go_main ~ main ( ) |
module Session = struct module Backend = struct include Session . Lift . IO ( Lwt ) ( Session . Memory ) let create ( ) = Session . Memory . create ( ) end include Session_webmachine . Make ( Lwt ) ( Backend ) end |
module UnixClock = struct let now ( ) = int_of_float ( Unix . gettimeofday ( ) ) end inherit [ Cohttp_lwt . Body . t ] resource inherit [ Cohttp_lwt . Body . t ] Session . manager ~ cookie_key backend method private increment session rd = let value = string_of_int ( 1 + int_of_s... |
let main ( ) = let port = 8080 in let mem = Session . Backend . create ( ) in let routes = [ " " , /* fun ( ) -> new counter mem ] in let dispatch = dispatch ' routes in let callback _conn request body = dispatch ~ body ~ request >|= begin function | None -> ( ` Not_found ... |
let ( ) = Mirage_crypto_rng_unix . initialize ( ) ; Lwt_main . run ( main ( ) ) |
let logger ( handler : Cohttp_lwt_unix . Server . conn -> Cohttp . Request . t -> Cohttp_lwt . Body . t -> ( Cohttp . Response . t * Cohttp_lwt . Body . t ) Lwt . t ) ( conn : Cohttp_lwt_unix . Server . conn ) ( request : Cohttp . Request . t ) ( body : Cohttp_lwt... |
let server = let app_args = App_args . default in let common_args = Common_args . default in let websim_args = Websim_args . default in let options = App_args . options app_args @ Websim_args . options websim_args @ Common_args . options common_args in let usage_msg : string = " kappa webservice ... |
let ( ) = let ( ) = Lwt . async_exception_hook := ignore in ignore ( Lwt_main . run server ) |
let og_image html = let open Soup in let soup = parse html in try soup $ " meta [ metaproperty = og : image ] image " |> R . attribute " content " |> Option . some with Failure _ -> None |
let image_src html = let open Soup in let soup = parse html in try soup $ " link [ linkrel " =\ image_src ] " " \ |> R . attribute " href " |> Option . some with Failure _ -> None |
let twitter_image html = let open Soup in let soup = parse html in try soup $ " meta [ metaname " =\ twitter : image ] " " \ |> R . attribute " content " |> Option . some with Failure _ -> None |
let og_description html = let open Soup in let soup = parse html in try soup $ " meta [ metaproperty = og : description ] description " |> R . attribute " content " |> Option . some with Failure _ -> None |
let description html = let open Soup in let soup = parse html in try soup $ " meta [ metaproperty = description ] description " |> R . attribute " content " |> Option . some with Failure _ -> None |
let preview_image html = let preview_image = match og_image html with | None -> ( match image_src html with | None -> twitter_image html | Some x -> Some x ) x | Some x -> Some x in match Option . map String . trim preview_image with | Some " " -> None | Some x -> Some x | None -> None |
let description html = let preview_image = match og_description html with None -> description html | Some x -> Some x in match Option . map String . trim preview_image with | Some " " -> None | Some x -> Some x | None -> None |
type t = { image : string option ; description : string option } |
let all url = let html = Http_client . get_sync url |> Result . get_ok in { image = preview_image html ; description = description html } |
let websocket_handler stream socket = let frames , push_frame = Lwt_stream . create ( ) in let message_is_binary = ref ` Binary in let frame ~ opcode ~ is_fin ~ len : _ payload = match opcode with | ` Connection_close -> push_frame ( Some ( ` Close , payload ) ) | ` Ping -> push_f... |
let client_websocket_handler : Stream . stream -> Websocketaf . Wsd . t -> Websocketaf . Client_connection . input_handlers = Obj . magic websocket_handler |
module Wsprotocol ( IO : Iteratees . Monad ) = struct module I = Iteratees . Iteratee ( IO ) open I type ' a t = ' a I . t let sanitize s = let result = Buffer . create ( String . length s ) in for i = 0 to String . length s - 1 do if ( String . unsafe_get s i >= ' \ 000 '... |
module Async_IO = Websocket . Make ( Cohttp_async . Io ) |
let set_tcp_nodelay writer = let socket = Socket . of_fd ( Writer . fd writer ) Socket . Type . tcp in Socket . setopt socket Socket . Opt . nodelay true |
let src = Logs . Src . create " websocket . async . client " ~ doc " : Websocket client for Async " |
let client ( ? name = " websocket . client " ) ( ? extra_headers = Header . init ( ) ) ( ? random_string = Rng . init ( ) ) ? initialized ~ app_to_ws ~ ws_to_app ~ net_to_ws ~ ws_to_net uri = let drain_handshake r w = let nonce = Base64 . encode_exn ( random_string 16 ) ... |
let client_ez ? opcode ( ? name = " websocket . client_ez " ) ? extra_headers ? heartbeat ? random_string uri net_to_ws ws_to_net = let app_to_ws , reactor_write = Pipe . create ( ) in let to_reactor_write , client_write = Pipe . create ( ) in let client_read , ws_to_app = Pipe . ... |
let src = Logs . Src . create " websocket . async . server " ~ doc " : Websocket server for Async " |
let server ( ? name = " websocket . server " ) ( ? check_request = fun _ -> Deferred . return true ) ( ? select_protocol = fun _ -> None ) ~ reader ~ writer ~ app_to_ws ~ ws_to_app ( ) = let handshake r w = Request . read r >>= ( function | ` Ok r -> Deferred . return ... |
let upgrade_connection ( ? select_protocol = fun _ -> None ) ( ? ping_interval = Time_ns . Span . of_int_sec 50 ) ~ app_to_ws ~ ws_to_app ~ f request = let headers = Cohttp . Request . headers request in let key = Option . value_exn ~ message " : missing sec - websocket - key " ( ... |
module Lwt_IO = Websocket . Make ( Cohttp_lwt_unix . IO ) |
let send_frames stream oc = let buf = Buffer . create 128 in let send_frame fr = Buffer . clear buf ; Lwt_IO . write_frame_to_buf ~ mode : Server buf fr ; Lwt_io . write oc @@ Buffer . contents buf in Lwt_stream . iter_s send_frame stream |
let read_frames ic oc handler_fn = let read_frame = Lwt_IO . make_read_frame ~ mode : Server ic oc in let rec inner ( ) = read_frame ( ) >>= Lwt . wrap1 handler_fn >>= inner in inner ( ) |
let upgrade_connection request incoming_handler = let headers = Cohttp . Request . headers request in ( match Cohttp . Header . get headers " sec - websocket - key " with | None -> Lwt . fail_invalid_arg " upgrade_connection : missing header ` sec - websocket - key ` " | Some key -> L... |
module Make ( IO : Graphql_intf . IO ) ( Ws : Graphql_websocket . Connection . S with type ' a IO . t = ' a IO . t ) = struct module Json = Yojson . Basic . Util let ( >>= ) = IO . bind type t = { conn : Ws . t ; subscriptions : ( string , unit -> unit ) Hashtbl . ... |
let section = Lwt_log . Section . make " websocket_lwt_unix " |
let http_error msg = Lwt . fail ( HTTP_Error msg ) |
let protocol_error msg = Lwt . fail ( Protocol_error msg ) |
let set_tcp_nodelay flow = let open Conduit_lwt_unix in match flow with | TCP { fd ; _ } -> Lwt_unix . setsockopt fd Lwt_unix . TCP_NODELAY true | _ -> ( ) |
let fail_unless eq f = if not eq then f ( ) else Lwt . return_unit |
let fail_if eq f = if eq then f ( ) else Lwt . return_unit |
let drain_handshake req ic oc nonce = Request . write ( fun _writer -> Lwt . return ( ) ) req oc >>= fun ( ) -> Response . read ic >>= ( function | ` Ok r -> Lwt . return r | ` Eof -> Lwt . fail End_of_file | ` Invalid s -> Lwt . fail @@ Failure s ) >>= fun response -> l... |
let connect ctx client url nonce extra_headers = let open Cohttp in let headers = Header . add_list extra_headers [ ( " Upgrade " , " websocket " ) ; ( " Connection " , " Upgrade " ) ; ( " Sec - WebSocket - Key " , nonce ) ; ( " Sec - WebSocket - Version " , ... |
type conn = { read_frame : unit -> Frame . t Lwt . t ; write_frame : Websocket . Frame . t -> unit Lwt . t ; oc : Lwt_io . output_channel } |
let read { read_frame ; _ } = read_frame ( ) |
let write { write_frame ; _ } frame = write_frame frame |
let close_transport { oc ; _ } = Lwt_io . close oc |
let connect ( ? extra_headers = Cohttp . Header . init ( ) ) ( ? random_string = Websocket . Rng . init ( ) ) ( ? ctx = Lazy . force Conduit_lwt_unix . default_ctx ) ? buf client url = let nonce = Base64 . encode_exn ( random_string 16 ) in connect ctx client url nonce ex... |
let write_failed_response oc = let body = " 403 Forbidden " in let body_len = String . length body |> Int64 . of_int in let response = Cohttp . Response . make ~ status ` : Forbidden ~ encoding ( : Cohttp . Transfer . Fixed body_len ) ( ) in let open Response in write ~ flush : tru... |
let server_fun ? read_buf ? write_buf check_request flow ic oc react = let read = function | ` Ok r -> Lwt . return r | ` Eof -> Lwt_log . info ~ section " Remote endpoint closed connection " >>= fun ( ) -> Lwt . fail End_of_file | ` Invalid reason -> Lwt_log . info_f ~ section " I... |
let establish_server ? read_buf ? write_buf ? timeout ? stop ( ? on_exn = fun exn -> ! Lwt . async_exception_hook exn ) ( ? check_request = check_origin_with_host ) ( ? ctx = Lazy . force Conduit_lwt_unix . default_ctx ) ~ mode react = let module C = Cohttp in Conduit_lwt_unix . serve... |
let mk_frame_stream recv = let f ( ) = recv ( ) >>= fun fr -> match fr . Frame . opcode with | Frame . Opcode . Close -> Lwt . return_none | _ -> Lwt . return ( Some fr ) in Lwt_stream . from f |
let establish_standard_server ? read_buf ? write_buf ? timeout ? stop ? on_exn ? check_request ( ? ctx = Lazy . force Conduit_lwt_unix . default_ctx ) ~ mode react = let f client = react ( Connected_client . make_standard client ) in establish_server ? read_buf ? write_buf ? timeout ? stop ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.