Better HN
topnewbestaskshowjobs
Log inSign up

test9753

52 karma · joined Dec 23, 2016 (9y ago) · 27 submissions

Submissions

comment 5y ago · link · parent

A Singly Linked List implementation in Terra (just testing out):

https://pastebin.com/xt3Wddtu

Output:

https://pastebin.com/KwSTiN8L

comment 6y ago · link · parent

How does this compare to a wiki[1] ?

[1] https://en.wikipedia.org/wiki/Wiki

comment 7y ago · link · parent

There is some discussion on Reddit: https://old.reddit.com/r/rust/comments/dpurlj/rust_2020_gui_...

4.

Rust 2020: GUI and Community(raphlinus.github.io ↗)

4 points · by test9753 · 7y ago · 1 comment

comment 7y ago · link · parent

~buf is shorthand for ~buf:buf

comment 7y ago · link · parent

Beating Decades of Optimized C with 27 Lines of Ocaml:

  type t = { mutable words: int; mutable chars: int; mutable lines: int; mutable in_word: bool ; mutable finished: bool};;

  let () =
    match Core.Sys.argv with
    | [| prog_name |] -> Core.Printf.eprintf "Usage: %s file1 file2 ...\n" prog_name
    | _ -> (
      let args = Core.Array.slice Core.Sys.argv 1 @@ Core.Array.length Core.Sys.argv in
      let buf_size = 65536 in (* 64 KB -> Caml IO buffer size *)
      let buf = Core.Bytes.create buf_size in
      Core.Array.fold args ~init:() ~f:(fun _ file ->
        Core.In_channel.with_file file ~f:(fun in_ch ->
          let c = { words = 0; chars = 0; lines = 0; in_word = false; finished = false } in
          let set_words () = if c.in_word then c.words <- c.words + 1 in
          while not c.finished do
            let len = Core.In_channel.input in_ch ~buf ~pos:0 ~len:buf_size |> Core.Int.to_int in
            if len > 0 then (
              for i = 0 to (len - 1) do
                match (Core.Caml.Bytes.get buf i) with
                | ' ' | '\t' | '\r' -> (c.chars <- c.chars + 1; set_words (); c.in_word <- false)
                | '\n'              -> (c.chars <- c.chars + 1; set_words (); c.in_word <- false; c.lines <- c.lines + 1)
                | _                 -> (c.chars <- c.chars + 1; c.in_word <- true)
              done
            ) else ( c.finished <- true )
          done;
          set_words ();
          Core.Printf.printf "%s -> lines: %d, words: %d, characters: %d\n" file c.lines c.words c.chars)))
  ;;
Testing:

  $ ls -lh test_file.txt 
  -rw-r--r--  1 user  group   508M Oct 16 12:01 test_file.txt

  $ time wc test_file.txt 
  4863460 54621760 532480000 test_file.txt

  real 0m3.368s
  user 0m3.137s
  sys  0m0.195s

  #Ocaml version:
  $ time ./wcl.native test_file.txt 
  test_file.txt -> lines: 4863460, words: 54621760, characters: 532480000

  real 0m2.480s
  user 0m2.345s
  sys  0m0.123s

7.

Raspberry Pi 4 Cooling [video](youtube.com ↗)

2 points · by test9753 · 7y ago · discuss

comment 7y ago · link · parent

I wonder if most of these older standards could be replaced by new standards that use SQLite as the Application File Format [0], making life easier for everyone.

[0] https://www.sqlite.org/appfileformat.html

comment 7y ago · link · parent

One approach to solve the slicing issue: https://play.rust-lang.org/?version=stable&mode=debug&editio...

comment 7y ago · link · parent

Video of the penguin & the man: https://www.youtube.com/watch?v=oks2R4LqWtE

11.

Homemade plane with HANDMADE jet engine [video](youtube.com ↗)

1 points · by test9753 · 7y ago · discuss

comment 8y ago · link · parent

Reminded me of an old news article (2009): The dark side of Dubai [ https://www.independent.co.uk/voices/commentators/johann-har... ]

comment 8y ago · link · parent

Purely functional data structures for OCaml, translated from Chris Okasaki's book "Purely Functional Data Structures":

https://github.com/mmottl/pure-fun

14.

Why I'm applying for citizenship in São Tomé(olifro.st ↗)

1 points · by test9753 · 8y ago · 1 comment

comment 8y ago · link · parent

In Ocaml [LOC: 24] [Level: Beginner]

  open Core

  let () =
    if Array.length Sys.argv <> 5 then
      Printf.eprintf "Invalid args\nUsage: %s <input.csv> <column-name> <replacement-string> <output.csv>" Sys.argv.(0)
    else
      let input_file, column_name, replacement, output_file = Sys.argv.(1), Sys.argv.(2),Sys.argv.(3),Sys.argv.(4) in 
      In_channel.with_file input_file ~f:(fun in_ch ->
      match In_channel.input_line in_ch with 
      | None -> Printf.eprintf "Cannot read first line"
      | Some first_line ->
        let columns = String.split first_line ~on:',' in 
        match List.findi columns ~f:(fun _ col -> col = column_name) with 
        | None -> Printf.eprintf "Cannot find column: %s" column_name
        | Some (index, _) ->
          let _ = Out_channel.with_file output_file ~f:(fun out_ch ->
            Out_channel.output_string out_ch (first_line ^ "\n");
            In_channel.fold_lines in_ch ~init:() ~f:(fun _ line ->
              let in_columns = String.split line ~on:',' in 
              let out_columns = List.mapi ~f:(fun i col -> if i = index then replacement else col) in_columns in 
              let out_line = (String.concat ~sep:"," out_columns) ^ "\n" in
              Out_channel.output_string out_ch out_line
            )
          ) in ())

comment 9y ago · link · parent

Mirror: https://archive.is/xh48z

17.

Popek-Goldberg machines considered harmful(blog.includeos.org ↗)

1 points · by test9753 · 9y ago · 1 comment

comment 9y ago · link · parent

Existing error handling facilities in Rust may not suit every use-case. For me personally, the difficulty with the `?` operator (and try! macro) is that the File + Line info about the source of error is lost. Also, I want something simpler than the approach taken by the `error-chain` crate. My current solution is to use some custom macros to check for errors and display an execution trace (example here: https://play.rust-lang.org/?gist=a7fb903ce2bbb37914ab380d342... )

comment 9y ago · link · parent

Found this paper useful: "The Case for Writing a Kernel in Rust" (https://www.tockos.org/assets/papers/rust-kernel-apsys2017.p...) linked from the "tock os" blog post: https://www.tockos.org/blog/2017/apsys-paper/

comment 9y ago · link · parent

Off-topic: the "Halide Talk" video in that page was very good: https://www.youtube.com/watch?v=3uiEyEKji0M

comment 9y ago · link · parent

For simple vector diagrams, I've found https://www.draw.io (similar to MS Visio) to be very convenient. The code is also open source (Apache-2.0): https://github.com/jgraph/draw.io

comment 9y ago · link · parent

Sentio CEO demoing the "SuperBook": https://www.youtube.com/watch?v=KFVRw0xWVAo

comment 9y ago · link · parent

instead of sending jamming signals, they could deploy a bunch of "bouncer" drones along the perimeter to knock down the unwanted drones. don't know if its going to be very effective, but at least it will be fun to watch. XD

comment 9y ago · link · parent

<quote>

The goal of this crate is to provide Rust bindings to the Web APIs and to allow a high degree of interoperability between Rust and JavaScript.

</quote>

25.

A standard library for the client-side Web (Rust)(github.com ↗)

2 points · by test9753 · 9y ago · 1 comment

comment 9y ago · link · parent

That last paragraph was absolutely hilarious. Thank you :-)

comment 9y ago · link · parent

Saw this video on youtube: https://www.youtube.com/watch?v=s0t1wAkjFBo

  <quote>
NASA's Use of HoloLens Puts St. Louis Scientist on Mars with Curiosity Rover

If anyone sees Raymond E. Arvidson, PhD, walking the halls of Washington University wearing Microsoft HoloLens, then he's not entirely walking on Earth. HoloLens combined with OnSight, a software tool developed by NASA's Jet Propulsion Laboratory in collaboration with Microsoft, allows Arvidson to be absorbed in the Martian landscape conducting 'field' research. Arvidson may actually be walking on university flooring, but the software is allowing him to virtually walk on Mars with NASA's Mars rover Curiosity. In his role as Curiosity Surface Properties Scientist, Arvidson is planning Curiosity's next move.

  </quote>