text stringlengths 0 601k |
|---|
let buffer = ref " " |
let kill ( ) = buffer := Text . get text ( TextIndex ( Insert , [ ] ) ) ( TextIndex ( Insert , [ LineEnd ] ) ) ; Text . delete text ( TextIndex ( Insert , [ ] ) ) ( TextIndex ( Insert , [ LineEnd ] ) ) ; ; |
let yank ( ) = Text . insert text ( TextIndex ( Insert , [ ] ) ) ! buffer [ ] |
let _ = bind text [ [ Control ] , KeyPressDetail " y " ] ( BindSet ( [ ] , fun _ -> yank ( ) ) ) ; ; |
let _ = bind text [ [ Control ] , KeyPressDetail " k " ] ( BindSet ( [ ] , fun _ -> kill ( ) ) ) ; ; |
let _ = scroll_link scrollbar text ; pack [ text ; f ] [ ] ; pack [ f ] [ ] ; mainLoop ( ) ; ; |
let ( ) = let text = " joy " in let surface = Cairo . Image . create Cairo . Image . ARGB32 ~ w : 600 ~ h : 600 in let cr = Cairo . create surface in Cairo . scale cr 600 . 600 . ; Cairo . set_font_size cr 0 . 5 ; Cairo . set_source_rgb cr 0 . 0 0 . 0 0 . 0 ; Cairo . select_font_face cr " Georgia " ~ weight : Bold ; le... |
type stats = int * int * int * int * int array |
let lines ( l , _ , _ , _ , _ ) = l |
let characters ( _ , c , _ , _ , _ ) = c |
let words ( _ , _ , w , _ , _ ) = w |
let sentences ( _ , _ , _ , s , _ ) = s |
let frequency ( _ , _ , _ , _ , h ) x = h . ( int_of_char x ) |
let stats_from_channel in_channel = let lines = ref 0 and characters = ref 0 and words = ref 0 and sentences = ref 0 and histogram = Array . make 256 0 in try while true do let line = input_line in_channel in lines := ! lines + 1 ; characters := ! characters + String . length line ; String . iter ( fun c -> match c wit... |
let stats_from_file filename = let channel = open_in filename in let result = stats_from_channel channel in close_in channel ; result |
let texpts = [ [ || 0 . 0 ; 0 . 0 ; 0 . 0 ; 1 . 0 ] ; | [ | 1 . 0 ; 0 . 0 ; 1 . 0 ; 1 . 0 ] ] || |
let ctrlpoints = [ [ ||- 1 . 5 ; - 1 . 5 ; 4 . 9 ; - 0 . 5 ; - 1 . 5 ; 2 . 0 ; 0 . 5 ; - 1 . 5 ; - 1 . 0 ; 1 . 5 ; - 1 . 5 ; 2 . 0 ] ; | [ |- 1 . 5 ; - 0 . 5 ; 1 . 0 ; - 0 . 5 ; - 0 . 5 ; 3 . 0 ; 0 . 5 ; - 0 . 5 ; 0 . 0 ; 1 . 5 ; - 0 . 5 ; - 1 . 0 ] ; | [ |- 1 . 5 ; 0 . 5 ; 4 . 0 ; - 0 . 5 ; 0 . 5 ; 0 . 0 ; 0 . 5 ; 0 .... |
let pi = acos ( - 1 . 0 ) |
let display togl = GlClear . clear [ ` color ; ` depth ] ; GlDraw . color ( 1 . 0 , 1 . 0 , 1 . 0 ) ; GlMap . eval_mesh2 ~ mode ` : fill ~ range1 ( : 0 , 20 ) ~ range2 ( : 0 , 20 ) ; Gl . flush ( ) ; Togl . swap_buffers togl |
let make_image ( ) = let image = GlPix . create ` ubyte ~ height : image_height ~ width : image_width ~ format ` : rgb in let raw = GlPix . to_raw image and pos = GlPix . raw_pos image in for i = 0 to image_width - 1 do let ti = 2 . 0 . * pi . * float i . / float image_width in for j = 0 to image_height - 1 do let tj =... |
let myinit ( ) = let ctrlpoints = Raw . of_matrix ~ kind ` : double ctrlpoints and texpts = Raw . of_matrix ~ kind ` : double texpts in GlMap . map2 ~ target ` : vertex_3 ( 0 . 0 , 1 . 0 ) ~ order : 4 ( 0 . 0 , 1 . 0 ) ~ order : 4 ctrlpoints ; GlMap . map2 ~ target ` : texture_coord_2 ( 0 . 0 , 1 . 0 ) ~ order : 2 ( 0 ... |
let my_reshape togl = let h = Togl . height togl and w = Togl . width togl in GlDraw . viewport ~ x : 0 ~ y : 0 ~ w ~ h ; GlMat . mode ` projection ; GlMat . load_identity ( ) ; let r = float h . / float w in if w <= h then GlMat . ortho ~ x ( :- 4 . 0 , 4 . 0 ) ~ y ( :- 4 . 0 . * r , 4 . 0 . * r ) ~ z ( :- 4 . 0 , 4 .... |
let main ( ) = let top = openTk ( ) in let togl = Togl . create top ~ rgba : true ~ depth : true ~ width : 300 ~ height : 300 ~ double : true in Wm . title_set top " Texture Surf " ; myinit ( ) ; Togl . reshape_func togl ~ cb ( : fun ( ) -> my_reshape togl ) ; Togl . display_func togl ~ cb ( : fun ( ) -> display togl )... |
let _ = main ( ) |
type bunny = { position : Raylib . Vector2 . t ; speed : Raylib . Vector2 . t ; color : Raylib . Color . t ; } |
let setup ( ) = let open Raylib in init_window width height " raylib [ textures ] example - bunnymark " ; let tex_bunny = load_texture " resources / wabbit_alpha . png " in set_target_fps 60 ; tex_bunny |
let rec loop bunnies bunnies_count tex_bunny = match Raylib . window_should_close ( ) with | true -> Raylib . close_window ( ) | false -> let open Raylib in let bunnies , bunnies_count = if is_mouse_button_down MouseButton . Left then let rec inner bunnies bunnies_count = function | 0 -> ( bunnies , bunnies_count ) | i... |
let ( ) = setup ( ) |> loop [ ] || 0 |
type vec2 = { x : float ; y : float } |
type bunny = { position : vec2 ; speed : vec2 ; color : Raylib . Color . t } |
let setup ( ) = let open Raylib in init_window width height " raylib [ textures ] example - bunnymark " ; let tex_bunny = load_texture " resources / wabbit_alpha . png " in set_target_fps 60 ; tex_bunny |
let rec loop bunnies bunnies_count tex_bunny = match Raylib . window_should_close ( ) with | true -> Raylib . close_window ( ) | false -> let open Raylib in let bunnies , bunnies_count = if is_mouse_button_down MouseButton . Left then let rec inner bunnies bunnies_count = function | 0 -> ( bunnies , bunnies_count ) | i... |
let ( ) = setup ( ) |> loop [ ] || 0 |
let position = Raylib . Vector2 . create 350 . 0 280 . 0 |
let setup ( ) = let open Raylib in init_window width height " raylib [ textures ] example - texture rectangle " ; let scarfy = load_texture " resources / scarfy . png " in let frame_rec = Rectangle . create 0 . 0 0 . 0 ( Float . of_int ( Texture . width scarfy ) . / 6 . 0 ) ( Float . of_int ( Texture . height scarfy ) ... |
let rec loop scarfy frame_rec counter frame frames_speed = match Raylib . window_should_close ( ) with | true -> Raylib . close_window ( ) | false -> let open Raylib in let module R = Raylib . Rectangle in let counter = succ counter in let counter , frame , frame_rec = if counter >= 60 / frames_speed then let frame = s... |
let ( ) = let scarfy , frame_rec = setup ( ) in loop scarfy frame_rec 0 0 8 |
let setup ( ) = let open Raylib in init_window width height " raylib [ textures ] example - texture source and destination rectangles " ; let scarfy = load_texture " resources / scarfy . png " in let frame_width = Texture . width scarfy / 6 in let frame_height = Texture . height scarfy in let source_rec = Rectangle . c... |
let rec loop rotation ( scarfy , source_rec , dest_rec , origin ) = match Raylib . window_should_close ( ) with | true -> Raylib . close_window ( ) | false -> let open Raylib in begin_drawing ( ) ; clear_background Color . raywhite ; draw_texture_pro scarfy source_rec dest_rec origin rotation Color . white ; draw_line ... |
let ( ) = setup ( ) |> loop 0 . 0 |
let handles = Hashtbl . create 401 |
let add_handle var cbid = try let r = Hashtbl . find handles var in r := cbid :: ! r with Not_found -> Hashtbl . add handles var ( ref [ cbid ] ) |
let exceptq x = let rec ex acc = function [ ] -> acc | y :: l when y == x -> ex acc l | y :: l -> ex ( y :: acc ) l in ex [ ] |
let rem_handle var cbid = try let r = Hashtbl . find handles var in match exceptq cbid ! r with [ ] -> Hashtbl . remove handles var | remaining -> r := remaining with Not_found -> ( ) |
let rem_all_handles var = try let r = Hashtbl . find handles var in List . iter ( internal_untracevar var ) ! r ; Hashtbl . remove handles var with Not_found -> ( ) |
let handle vname ~ callback : f = let id = new_function_id ( ) in let wrapped _ = clear_callback id ; rem_handle vname id ; f ( ) in Hashtbl . add callback_naming_table id wrapped ; add_handle vname id ; if ! Protocol . debug then begin prerr_cbid id ; prerr_string " for variable " ; prerr_endline vname end ; internal_... |
module StringSet = Set . Make ( struct type t = string let compare = compare end ) |
let freelist = ref ( StringSet . empty ) |
let memo = Hashtbl . create 101 |
let add w v = let w = Widget . forget_type w in let r = try Hashtbl . find memo w with Not_found -> let r = ref StringSet . empty in Hashtbl . add memo w r ; r in r := StringSet . add v ! r |
let free v = rem_all_handles v ; freelist := StringSet . add v ! freelist |
let freew w = try let r = Hashtbl . find memo w in StringSet . iter free ! r ; Hashtbl . remove memo w with Not_found -> ( ) |
let _ = add_destroy_hook freew |
let counter = ref 0 |
let getv ( ) = let v = if StringSet . is_empty ! freelist then begin incr counter ; " camlv ( " ^ string_of_int ! counter " ) " ^ end else let v = StringSet . choose ! freelist in freelist := StringSet . remove v ! freelist ; v in set v " " ; v |
let create ? on : w ( ) = let v = getv ( ) in begin match w with Some w -> add w v | None -> ( ) end ; v |
let free v = freelist := StringSet . add v ! freelist |
let cCAMLtoTKtextVariable s = TkToken s |
let name s = s |
let coerce s = s |
module Encoding = struct let recode ? nln ? encoding out_encoding ( src : [ ` Channel of in_channel | ` String of string ] ) ( dst : [ ` Channel of out_channel | ` Buffer of Buffer . t ] ) = let rec loop d e = match Uutf . decode d with | ` Uchar _ as u -> ignore ( Uutf . encode e u ) ; loop d e | ` End -> ignore ( Uut... |
let utf16_offsetAt ( text : string ) ( { line ; character } : Position . t ) = if line < 0 then 0 else let lofs = Encoding . utf16_line_offsets text in let al = Array . length lofs in if line >= al - 1 then lofs . ( al - 1 ) else let this_lofs = lofs . ( line ) in let next_line_offset = lofs . ( line + 1 ) in max ( min... |
let byte_offsetAt t pos = 2 * utf16_offsetAt t pos |
let utf16_range_change ( text_utf8 : string ) ( { start ; end_ } : Range . t ) change_utf16 = let text = Encoding . utf8_to_utf16 text_utf8 in let doc_length = String . length text in let start_ofs = byte_offsetAt text start in let end_ofs = byte_offsetAt text end_ in let buf = Buffer . create ( String . length change_... |
let make ( t : DidOpenTextDocumentParams . t ) = t . textDocument |
let documentUri ( t : t ) = Uri0 . t_of_yojson ( ` String t . uri ) |
let version ( t : t ) = t . version |
let languageId ( t : t ) = t . languageId |
let text ( t : t ) = t . text |
let apply_content_change ? version ( t : t ) ( change : TextDocumentContentChangeEvent . t ) = let version = match version with | None -> t . version + 1 | Some version -> version in let change_text = Encoding . utf8_to_utf16 change . text in let utf16_text = match change . range with | None -> change_text | Some range... |
let tuple_range start end_ = Some { Range . start = ( let line , character = start in { Position . line ; character } ) ; end_ = ( let line , character = end_ in { Position . line ; character } ) } |
let test text range ~ change = let td = let uri = DocumentUri . of_path " " in let version = 1 in let languageId = " fake language " in let textDocument = { TextDocumentItem . uri ; version ; languageId ; text } in Text_document . make { DidOpenTextDocumentParams . textDocument } in let td = Text_document . apply_conte... |
let msg = " Loaded Font " |
let setup ( ) = let open Raylib in init_window 800 450 " raylib [ text ] example - font filters " ; let font = load_font_ex " resources / KAISG . ttf " 96 None in gen_texture_mipmaps ( addr ( Font . texture font ) ) ; let font_size = Font . base_size font in let font_position = Vector2 . create 40 . 0 ( ( Float . of_in... |
let rec loop font font_size font_position filter = match Raylib . window_should_close ( ) with | true -> let open Raylib in clear_dropped_files ( ) ; unload_font font ; close_window ( ) | false -> let open Raylib in let font_size = font_size + ( Int . of_float ( get_mouse_wheel_move ( ) ) * 4 ) in let filter = if is_ke... |
let ( ) = let font , font_size , font_position = setup ( ) in loop font font_size font_position ` Point |
type t = { content : Tensor . t ; char_for_label : char Map . M ( Int ) . t } |
let create ~ filename = let file_descr = Unix . openfile filename [ O_RDONLY ] 0 in let content = Unix . map_file file_descr Int8_unsigned C_layout false [ | - 1 ] | |> Bigarray . array1_of_genarray in Unix . close file_descr ; let label_for_char = Hashtbl . Poly . create ( ) in for i = 0 to Bigarray . Array1 . dim con... |
let total_length t = Tensor . shape t . content |> List . hd_exn |
let char t ~ label = Map . find_exn t . char_for_label label |
let labels t = Map . length t . char_for_label |
let iter ? device t ~ f ~ seq_len ~ batch_size = let total_length = total_length t in let start_indexes = Tensor . randperm ~ n ( : total_length - seq_len ) ~ options ( : T Int64 , Cpu ) in for index = 0 to ( ( total_length - seq_len - 1 ) / batch_size ) - 1 do let xs , ys = List . init batch_size ~ f ( : fun i -> let ... |
let scan_indent view ( start : GText . iter ) ( stop : GText . iter ) = let data = ref [ ] in let iter = ref ( start # set_line_index 0 ) in let stop = stop # set_line_index 0 in while ! iter # compare stop < 0 do if List . mem ! iter # char blanks then ( iter := ! iter # forward_find_char not_blank ) ; let indent = ! ... |
let style = if use_glow then ` ON_OFF_DASH else ` SOLID |
let color_hl_fg = ` NAME " # 000000 " |
let color_hl_bg = ` NAME " # e0f0ff " |
let color_hl_bg1 = ` NAME " # fff0e0 " |
let draw_indent_lines view ( drawable : GDraw . drawable ) start stop y0 = let left_margin = view # left_margin + 1 in let buffer = view # tbuffer in let current_iter : GText . iter = buffer # get_iter ` INSERT in let y_current_line , _ = view # get_line_yrange current_iter # forward_line in let y_current_line = y_curr... |
let key_press ? project view = view # event # connect # key_press ~ callback : begin fun ev -> let state = GdkEvent . Key . state ev in let key = GdkEvent . Key . keyval ev in match state with | [ ] -> if key = _Tab then begin let ocp_indent_applied = ( match view # tbuffer # file with Some file when not ( file # filen... |
let realize view = let self = view in if not self # realized then begin ignore ( self # misc # connect # after # realize ~ callback : begin fun ( ) -> ( match self # gutter . Gutter . bg_color with | ` WHITE -> self # gutter . Gutter . bg_color <- ( match Oe_config . gutter_bg_color with | ` CALC x -> Color . set_value... |
let select_lines_from_gutter view = let self = view in ignore ( self # event # connect # after # button_press ~ callback : begin fun ev -> let window = GdkEvent . get_window ev in match self # get_window ` LEFT with | Some w when ( Gobject . get_oid w ) = ( Gobject . get_oid window ) -> let y0 = Gdk . Rectangle . y sel... |
object ( self ) val mutable text_color : GDraw . color = ` BLACK val mutable base_color : GDraw . color = ` WHITE val mutable indent_lines_color_solid : GDraw . color = ` BLACK val mutable indent_lines_color_dashed : GDraw . color = ` BLACK val mutable highlight_current_line : string option = None val mutable current_l... |
let tag_bind widget tag eventsequence action = check_class widget widget_text_table ; tkCommand [ | cCAMLtoTKwidget widget_text_table widget ; TkToken " tag " ; TkToken " bind " ; cCAMLtoTKtextTag tag ; cCAMLtoTKeventSequence eventsequence ; begin match action with | BindRemove -> TkToken " " | BindSet ( what , f ) -> ... |
let tag_bind ~ tag ~ events ( ? extend = false ) ( ? breakable = false ) ( ? fields = [ ] ) ? action widget = tkCommand [ | cCAMLtoTKwidget widget ; TkToken " tag " ; TkToken " bind " ; cCAMLtoTKtextTag tag ; cCAMLtoTKeventSequence events ; begin match action with | None -> TkToken " " | Some f -> let cbId = register_c... |
let of_int amount = Int64 . ( mul 1_000_000L ( of_int amount ) ) |
let one = of_int 1 |
let to_string amount = let mult_int = 1_000_000L in let rec left amount = let ( d , r ) = ( Int64 . ( div amount 1000L ) , Int64 . ( rem amount 1000L ) ) in if d > 0L then Format . asprintf " % s % 03Ld " ( left d ) r else Format . asprintf " % Ld " r in let right amount = let triplet v = if v mod 10 > 0 then Format . ... |
let to_float amount = Float . mul ( Int64 . to_float amount ) 0 . 000_001 |
let ( + ) = Int64 . add |
type iterator = { mutable i : int ; mutable sum : int } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.