text stringlengths 0 601k |
|---|
let rng ( ) = C . Random . device_rng " / dev / random " |
let from_hex s = C . transform_string ( C . Hexa . decode ( ) ) s |
let to_hex s = C . transform_string ( C . Hexa . encode ( ) ) s |
let from_base64 s = C . transform_string ( C . Base64 . decode ( ) ) s |
let to_base64 s = C . transform_string ( C . Base64 . encode_compact ( ) ) s |
let to_base64_m s = C . transform_string ( C . Base64 . encode_multiline ( ) ) s |
let hash s = C . hash_string ( C . Hash . sha256 ( ) ) s |
let symetric direction key s = let cipher = C . Cipher . aes ~ pad : C . Padding . _8000 key direction in C . transform_string cipher s |
let symetric_encrypt = symetric C . Cipher . Encrypt |
let symetric_decrypt = symetric C . Cipher . Decrypt |
let print_rsa_key rsa_key = print_endline ( Printf . sprintf " \ n \ |
let rsa_key = { \ n RSA . size = % d ; \ n \ |
let new_rsa_key_from_RSA rsa = let ret = new_rsa_key ( ) in rsa_set_n ret ( hex_of_string rsa . RSA . n ) ; rsa_set_e ret ( hex_of_string rsa . RSA . e ) ; rsa_set_d ret ( hex_of_string rsa . RSA . d ) ; rsa_set_p ret ( hex_of_string rsa . RSA . p ) ; rsa_set_q ret ( hex_of_string rsa . RSA . q ) ; rsa_set_dp ret ( hex... |
let new_rsa_empty_key ( ) = { C . RSA . size = 0 ; C . RSA . n = " " ; C . RSA . e = " " ; C . RSA . d = " " ; C . RSA . p = " " ; C . RSA . q = " " ; C . RSA . dp = " " ; C . RSA . dq = " " ; C . RSA . qinv = " " ; } |
let sign rsa_sig_privkey s = C . RSA . sign_CRT rsa_sig_privkey s |
let unsign rsa_sig_pubkey s = C . RSA . unwrap_signature rsa_sig_pubkey s |
let random_key ( ) = C . Random . string ( C . Random . secure_rng ) 32 |
let read_rsa_privkey file = try let rsa = rsa_read_privkey file in rsa_key_to_cryptokit_hex_rsa rsa |
let read_rsa_pubkey file = try let rsa = rsa_read_pubkey file in rsa_key_to_cryptokit_hex_rsa rsa |
let write_rsa_privkey file rsa = try let rsa_key = new_rsa_key ( ) in rsa_set_n rsa_key ( hex_of_string rsa . RSA . n ) ; rsa_set_e rsa_key ( hex_of_string rsa . RSA . e ) ; rsa_set_d rsa_key ( hex_of_string rsa . RSA . d ) ; rsa_set_p rsa_key ( hex_of_string rsa . RSA . p ) ; rsa_set_q rsa_key ( hex_of_string rsa . RS... |
let write_rsa_pubkey file rsa = try let rsa_key = new_rsa_key ( ) in rsa_set_n rsa_key ( hex_of_string rsa . RSA . n ) ; rsa_set_e rsa_key ( hex_of_string rsa . RSA . e ) ; evp_write_pubkey file rsa_key ; free_rsa_key rsa_key failwith " write RSA public key failure " |
let get_rsa_pubkey rsa = try let rsa_key = new_rsa_key ( ) in rsa_set_n rsa_key ( hex_of_string rsa . RSA . n ) ; rsa_set_e rsa_key ( hex_of_string rsa . RSA . e ) ; let ret = string_of_rsa_pem_pub rsa_key in free_rsa_key rsa_key ; ret failwith " write RSA public key failure " |
let string_of_sign_rsa_pub_key key sign_key issuer subject duration file = let rsa_key = new_rsa_key_from_RSA key in let rsa_sign_key = new_rsa_key_from_RSA sign_key in try let ret = sign_pub_key rsa_key rsa_sign_key issuer subject duration in ret with CRT_error -> failwith " Cannot sign public key " |
let sign_rsa_pub_key key sign_key issuer subject duration file = try let value = string_of_sign_rsa_pub_key key sign_key issuer subject duration file in let output = open_out file in output_string output value ; flush output ; close_out output with CRT_error -> failwith " Cannot sign public key " |
let create_rsa_key file len = let rsa = gen_rsa_key len in let ret = rsa_key_to_cryptokit_hex_rsa rsa in let _ = write_rsa_privkey file ret in print_rsa_key ret ; ret |
type t = Range . t list |
let size t = List . fold_left ~ f ( : fun ans v -> ans + Range . size v ) v ~ init : 0 t |
let is_empty t = size t = 0 |
let rec is_canonical ( vl : Range . t list ) list : bool = match vl with | [ ] | _ [ ] :: -> true | u ( :: v :: _ as tail ) tail -> u . Range . hi < v . Range . lo && is_canonical tail |
let to_canonical ( vl : Range . t list ) list : Range . t list = let compare_intervals u v = match Range . compare_containment u v with | Some x -> - x | None -> match Range . compare_positional u v with | Some x -> x | None -> assert false in let vl = List . sort ~ compare : compare_intervals vl in let rec canonize an... |
let of_range_list l = let f acc ( x , y ) y = if x <= y then ( Range . make_unsafe x y ) y :: acc else acc in to_canonical ( List . fold ~ f ~ init [ ] : l ) l |
let to_range_list t = List . map ~ f ( : fun { Range . lo ; hi } hi -> lo , hi ) hi t |
let to_list t = List . concat ( List . map ~ f : Range . to_list t ) t |
let union s t = to_canonical ( s @ t ) t |
let inter s t = let rec loop ans s t = match ( s , t ) t with | ( _ , [ ] ) -> ans | ( [ ] , _ ) _ -> ans | ( ( u :: s as ul ) ul , ( v :: t as vl ) vl ) vl -> if u . Range . lo > v . Range . hi then loop ans ul t else if u . Range . hi < v . Range . lo then loop ans s vl else match Range . intersect u v with | None ->... |
let diff s t = let rec loop ans s t = match ( s , t ) t with | ( _ [ ] ) , -> ans @ ( List . rev s ) s | ( [ ] , _ ) _ -> ans | ( ( u :: s as ul ) ul , ( v :: t as vl ) vl ) vl -> if u . Range . lo > v . Range . hi then loop ans ul t else if u . Range . hi < v . Range . lo then loop ( u :: ans ) ans s vl else match Ran... |
let subset s t = is_empty ( diff s t ) t |
type image = { img_url : string ; img_title : string ; img_link : string ; } |
type item = { it_title : string ; it_link : string ; it_description : string ; it_author : string option ; it_category : string option ; it_comments : string option ; it_pubDate : float option ; it_guid : ( string * bool ) option ; } |
let item_date it = it . it_pubDate |
let elm kind ( ? attrs = [ ] ) v = Node ( kind , attrs , [ PCDATA v ] ) |
let opt_elm kind ? attrs = Option . map ( elm kind ? attrs ) |
let some_elm kind ? attrs v = Some ( elm kind ? attrs v ) |
let format_date t = Netdate . mk_mail_date t |
let format_date_rdf t = Netdate . format " % Y -% m -% dT % H :% M :% SZ " ( Netdate . create ~ zone : 0 t ) |
let filter_concat ls = List . filter_map ( fun x -> x ) ( List . concat ls ) |
let filter_some = List . filter_map ( fun x -> x ) |
let encode_pcdata s = [ PCDATA s ] |
let xml_of_item item = Node ( " item " , [ ] , filter_concat [ [ some_elm " title " item . it_title ; some_elm " link " item . it_link ; some_elm " description " item . it_description ; opt_elm " author " item . it_author ; opt_elm " category " item . it_category ; opt_elm " comments " item . it_comments ; opt_elm " pu... |
let make ~ title ~ link ~ description ? self_link ? language ? copyright ? managingEditor ? webMaster ? pubDate ? lastBuildDate ? category ? generator ? ttl ? image items = let channel = filter_concat [ [ some_elm " title " title ; some_elm " link " link ; Option . map ( fun link -> Leaf ( " atom : link " , [ string_at... |
let make_rdf ~ title ~ link ~ description ~ date ? language ? copyright ? image items = let it_list_elm = Node ( " items " , [ ] , [ Node ( " rdf : Seq " , [ ] , List . map ( fun it -> Leaf ( " rdf : li " , [ string_attrib " resource " it . it_link ] ) ) items ) ] ) in let channel_elm = Node ( " channel " , [ string_at... |
let make_item ~ title ~ link ~ description ? author ? category ? comments ? pubDate ? guid ( ) = { it_title = title ; it_link = link ; it_description = description ; it_author = author ; it_category = category ; it_comments = comments ; it_pubDate = pubDate ; it_guid = guid } |
let pp_title ~ char ppf title = let sub = String . map ( fun _ -> char ) title in Format . fprintf ppf " [ @< v 0 >% s @ % s @ @ ] " @ title sub |
let pp_h1 = pp_title ~ char ' ' :# |
let pp_h2 = pp_title ~ char ' ' :* |
let pp_h3 = pp_title ~ char ' ' := |
let pp_h4 = pp_title ~ char ' ` ' : |
let pp_raw_html ppf str = Format . fprintf ppf " [ @< v . . > raw :: html @ @ % s @ @ ] " @ ( Re . Str . global_replace ( Re . Str . regexp " \ n " ) " \ n " str ) |
let pp_html ppf f = Format . fprintf ppf " [ @< v 2 . . > raw :: html @ @ % a ] @@\ n @\ n " ( fun ppf ( ) -> f ppf ) ( ) |
let pp_ref ppf name = Format . fprintf ppf " . . _ % s :@\ n @\ n " name |
let style = { css | < style > . wy - nav - content { max - width : 100 ; % } . tab { overflow : hidden ; border : 1px solid # ccc ; background - color : # f1f1f1 ; } . tab button { background - color : inherit ; float : left ; border : none ; outline : none ; cursor : pointer ; padding : 5px 10px ; } . tab button : hov... |
let script = { script | < script > function showTab ( elt , tab , ref ) { var i , tabcontent , tablinks ; tabcontent = document . getElementsByClassName ( ref ) ; for ( i = 0 ; i < tabcontent . length ; i ) ++ { tabcontent [ i ] . style . display = ' none ' ; } tablinks = elt . parentNode . children ; for ( i = 0 ; i <... |
type t = { t : float ; shape : RTCShape . t ; trail : RTCShape . t list ; point : RTCTuple . t ; under_point : RTCTuple . t ; eyev : RTCTuple . t ; normalv : RTCTuple . t ; reflectv : RTCTuple . t ; inside : bool ; n1 : float ; n2 : float ; } |
let prepare ( i : RTCShape . t RTCIntersection . t ) r ( xs : RTCShape . t RTCIntersection . xslist ) = let point = RTCRay . position r i . t in let eyev = RTCTuple . neg r . direction in let normalv = RTCShape . normal_at ~ hit ( : Some i ) i . shape i . trail point in let inside = ( RTCTuple . dot normalv eyev ) < 0 ... |
let schlick ( comps : t ) = let reflectance cos_i = let r0 = ( ( comps . n1 . - comps . n2 ) . / ( comps . n1 . + comps . n2 ) ) ** 2 . in r0 . + ( 1 . . - r0 ) . * ( 1 . . - cos_i ) ** 5 . in let cos_i = RTCTuple . dot comps . eyev comps . normalv in if comps . n1 > comps . n2 then let n = comps . n1 . / comps . n2 in... |
let material ( comps : t ) = RTCShape . material ~ trail : comps . trail comps . shape |
let parameters_of ( shape : RTCShape . t ) = match shape . shape with | Cylinder ( minimum , maximum , closed ) -> ( minimum , maximum , closed ) | Cone ( minimum , maximum , closed ) -> ( minimum , maximum , closed ) | _ -> failwith " expected a cylinder or cone " |
let intersect_caps trail shape min max closed ( ray : RTCRay . t ) radius_at xs = let check_cap t radius = let x = ray . origin . x . + t . * ray . direction . x and z = ray . origin . z . + t . * ray . direction . z in ( x ** 2 . . + z ** 2 . ) <= radius ** 2 . in if ( not closed ) || ( ( abs_float ray . direction . y... |
let intersect ( shape : RTCShape . t ) ( ? trail [ ] ) = ( r : RTCRay . t ) afn bfn cfn radius_at = let ( minimum , maximum , closed ) = parameters_of shape in let a = afn r in let b = bfn r in let xs = if ( abs_float a ) < RTCConst . epsilon then if ( abs_float b ) < RTCConst . epsilon then [ ] else let c = cfn r in l... |
let normal_at shape ( point : RTCTuple . t ) nfn = let ( minimum , maximum , _ ) = parameters_of shape in let dist = point . x ** 2 . . + point . z ** 2 . in if dist < 1 . && point . y >= maximum . - RTCConst . epsilon then RTCTuple . vector 0 . 1 . 0 . else if dist < 1 . && point . y <= minimum . + RTCConst . epsilon ... |
let intersection_allowed_union lhit inl inr = ( lhit && ( not inr ) ) || ( ( not lhit ) && ( not inl ) ) |
let intersection_allowed_intersect lhit inl inr = ( lhit && inr ) || ( ( not lhit ) && inl ) |
let intersection_allowed_difference lhit inl inr = ( lhit && ( not inr ) ) || ( ( not lhit ) && inl ) |
let filter_intersections ( shape : RTCShape . t ) xs = let ( left , right , rule ) = match shape . shape with | Union ( l , r , fn ) -> ( l , r , fn ) | Intersect ( l , r , fn ) -> ( l , r , fn ) | Difference ( l , r , fn ) -> ( l , r , fn ) | _ -> failwith " expected a CSG operate to filter_intersections " in let rec ... |
let build operation = let local_intersect ( shape : RTCShape . t ) ( ? trail [ ] ) = ( r : RTCRay . t ) = let ( left , right ) = match shape . shape with | Union ( l , r , _ ) -> ( l , r ) | Intersect ( l , r , _ ) -> ( l , r ) | Difference ( l , r , _ ) -> ( l , r ) | _ -> failwith " expected CSG object in local_inter... |
let union left right = build ( Union ( left , right , intersection_allowed_union ) ) |
let intersection left right = build ( Intersect ( left , right , intersection_allowed_intersect ) ) |
let difference left right = build ( Difference ( left , right , intersection_allowed_difference ) ) |
type t = { color : RTCColor . t ; pattern : RTCPattern . t option ; ambient : float ; diffuse : float ; specular : float ; shininess : float ; reflective : float ; transparency : float ; refractive_index : float ; } |
let build ( ? color = RTCColor . build 1 . 1 . 1 . ) ( ? pattern = None ) ( ? ambient = 0 . 1 ) ( ? diffuse = 0 . 9 ) ( ? specular = 0 . 9 ) ( ? shininess = 200 . 0 ) ( ? reflective = 0 . 0 ) ( ? transparency = 0 . 0 ) ( ? refractive_index = 1 . 0 ) ( ) = { color ; pattern ; ambient ; diffuse ; specular ; shininess ; r... |
let equal m1 m2 = ( RTCColor . equal m1 . color m2 . color ) && ( m1 . ambient = m2 . ambient ) && ( m1 . diffuse = m2 . diffuse ) && ( m1 . specular = m2 . specular ) && ( m1 . shininess = m2 . shininess ) && ( m1 . reflective = m2 . reflective ) && ( m1 . transparency = m2 . transparency ) && ( m1 . refractive_index ... |
let lighting m transform ( light : RTCLight . point_light ) point eyev normalv shadowed = let color = match m . pattern with | None -> m . color | Some pattern -> RTCPattern . at_object pattern transform point in let effective_color = RTCColor . mult color light . intensity in let lightv = RTCTuple . norm ( RTCTuple . ... |
type t = float array array |
let identity = [ | [ | 1 . ; 0 . ; 0 . ; 0 . ] ; | [ | 0 . ; 1 . ; 0 . ; 0 . ] ; | [ | 0 . ; 0 . ; 1 . ; 0 . ] ; | [ | 0 . ; 0 . ; 0 . ; 1 . ] | ] | |
let equal a b = let diff v1 v2 = abs_float ( v1 . - v2 ) in let zero x = x < RTCConst . epsilon in let row_collapse row_a row_b = Array . for_all zero ( Array . map2 diff row_a row_b ) in Array . for_all ( fun x -> x ) ( Array . map2 row_collapse a b ) |
let mult a b = let compute row col = Array . fold_left ( . ) + 0 . ( Array . mapi ( fun i _ -> a . ( row ) . ( i ) . * b . ( i ) . ( col ) ) a ) in Array . mapi ( fun row _ -> Array . mapi ( fun col _ -> compute row col ) b ) a |
let tmult a ( b : RTCTuple . t ) = let x = a . ( 0 ) . ( 0 ) . * b . x . + a . ( 0 ) . ( 1 ) . * b . y . + a . ( 0 ) . ( 2 ) . * b . z . + a . ( 0 ) . ( 3 ) . * b . w in let y = a . ( 1 ) . ( 0 ) . * b . x . + a . ( 1 ) . ( 1 ) . * b . y . + a . ( 1 ) . ( 2 ) . * b . z . + a . ( 1 ) . ( 3 ) . * b . w in let z = a . ( 2... |
let transpose a = Array . mapi ( fun row _ -> Array . mapi ( fun col _ -> a . ( col ) . ( row ) ) a ) a |
let submatrix m row col = let dim = ( Array . length m ) - 1 in let result = Array . make_matrix dim dim 0 . in for y = 0 to dim do if y <> row then let y ' = if y < row then y else y - 1 in for x = 0 to dim do if x <> col then let x ' = if x < col then x else x - 1 in result . ( y ' ) . ( x ' ) <- m . ( y ) . ( x ) do... |
let rec determinant = function | [ | [ | a ; b ] ; | [ | c ; d ] | ] | -> a . * d . - b . * c | m -> Array . fold_left ( . ) + 0 . ( Array . mapi ( fun i _ -> m . ( 0 ) . ( i ) . * ( cofactor m 0 i ) ) m ) let el = minor m row col in match ( row + col ) with | n when n mod 2 = 0 -> el | _ -> . - el |
let invertible m = ( abs_float ( determinant m ) ) >= RTCConst . epsilon |
let inverse m = let det = determinant m in if ( abs_float det ) < RTCConst . epsilon then raise ( NotInvertible " matrix is not invertible " ) else let calc row col = ( cofactor m row col ) . / det in Array . mapi ( fun y row -> Array . mapi ( fun x _ -> calc x y ) row ) m |
type t = { ignored_count : int ; vertices : RTCTuple . t array ; normals : RTCTuple . t array ; default_group : RTCShape . t ; groups : ( string , RTCShape . t ) Hashtbl . t } |
type acc_t = { ignored_count : int ; vertices : RTCTuple . t list ; normals : RTCTuple . t list ; faces : RTCShape . t list ; finalv : RTCTuple . t array ; finaln : RTCTuple . t array ; current_group : string ; groups : ( string , RTCShape . t ) Hashtbl . t } |
let next_opt ( stream : string Stream . t ) = match ( Stream . peek stream ) with | None -> None | _ -> Some ( Stream . next stream ) |
let parse ( stream : string Stream . t ) = let compile ( acc : acc_t ) = let vertices = [ ] and normals = [ ] in let finalv = match acc . vertices with | [ ] -> acc . finalv | v -> Array . append acc . finalv ( Array . of_list ( List . rev v ) ) in let finaln = match acc . normals with | [ ] -> acc . finaln | v -> Arra... |
let parse_file filename = let stream_lines_of_channel channel = Stream . from ( fun _ -> try Some ( input_line channel ) with End_of_file -> None ) in let channel = open_in filename in parse ( stream_lines_of_channel channel ) |
let named_group ( obj : t ) name = Hashtbl . find obj . groups name |
let to_group ( obj : t ) = match List . of_seq ( Hashtbl . to_seq_values obj . groups ) with | [ ] -> failwith " obj file contains no geometry " | single :: [ ] -> single | groups -> RTCGroup . build ~ children : groups ( ) |
type t = { fn : RTCTuple . t -> texture_t ; transform : RTCMatrix . t ; inverse_transform : RTCMatrix . t } | Solid of RTCColor . t | Pattern of t |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.