Below you will find pages that utilize the taxonomy term “programming”
Posts
Jq and Human Readable Bytes
I wrote a short jq module for converting bytes to more human readable form.
Ruby by Examples
Ruby: Or, how to get the anonymous module from Kernel#load with wrap=true?
With the same technique than in my earlier article it is also possible to capture the anonymous wrapper module that Kernel#load method with wrap=true uses to build the sandbox. This way you can load configuration or other data without polluting your namespace.
Ruby by Examples
Ruby: How to implement statfs syscall for Ruby 1.8 (pre Fiddle)
Here is statfs implementation for older Ruby releases that don’t have Fiddle:
Ruby by Examples
Ruby: How to implement statfs syscall with Ruby Fiddle FFI
Ruby will retire its broken Kernel#syscall method in the future. In the current Ruby releases you cannot provide NUL octets to syscalls which breaks almost all syscalls using a struct to provide parameters to it (Ruby bug 1472). Luckily starting Ruby 1.9.2 there is Fiddle standard library that can be used to call foreign functions like C-library’s functions, including the wrappers for syscalls. Unfortunate part is that Fiddle is still (2.
Ruby by Examples
Ruby: How to return value from loaded file?
Have you ever wanted to get return value from file which is read with Kernel#load without resorting to global variables or constants. It is actually quite simple when you realize that you can use non-local exit (continuations) to do that.