Skip to content

Instantly share code, notes, and snippets.

@hfabre
hfabre / test.rb
Created November 23, 2017 15:51
Deeply test json response with json entry
def deeply_validate_json_response(entry, out)
entry.each do |k, v|
if v.is_a? Hash
deeply_validate_json_response(v, out[k.to_s])
elsif v.is_a? Array
v.each { |obj| deeply_validate_json_response(obj, out[k.to_s]) }
else
v.must_equal out[k.to_s]
end
end
@hfabre
hfabre / replace_old_hash.md
Created April 5, 2019 13:59
Replace pre-1.9 hash by the new syntaxe

find: :(\w+)=>
replace: $1:

Keybase proof

I hereby claim:

  • I am hfabre on github.
  • I am hfabre (https://keybase.io/hfabre) on keybase.
  • I have a public key ASCt6Bla5ly_N3dcU0X9yo3E_a4scNwK8WrIZZPugpYRvwo

To claim this, I am signing this object:

@hfabre
hfabre / main.go
Created October 11, 2020 10:57
Demo sqweek gtk3 bug
package main
import (
"github.com/sqweek/dialog"
r "github.com/lachee/raylib-goplus/raylib"
)
func main() {
path := ""
@hfabre
hfabre / hook.rb
Last active November 3, 2020 22:01
Grappling hook
def center_x
@x / 2
end
def center_y
@y / 2
end
def normalize(x, y)
magn = Math.sqrt(x*x + y*y)
pub const Color = struct {
a: u8,
r: u8,
g: u8,
b: u8
};
var new_mrb = mruby.open();
var mrb_color_class = new_mrb.define_class("Color", new_mrb.object_class());
new_mrb.define_method(mrb_color_class, "initialize", mrb_initialize_color, .{ .req = 3 });
@hfabre
hfabre / upload_live.ex
Created June 17, 2024 15:54 — forked from nshafer/upload_live.ex
Process uploaded file
def handle_event("import", _params, socket) do
results =
consume_uploaded_entries(socket, :import, fn %{path: path}, _entry ->
temp_dir = Briefly.create!(type: :directory)
csv_file = Path.join(temp_dir, "import.csv")
# Attempt to create a new hard link to the file
case File.ln(path, csv_file) do
:ok ->
{:ok, csv_file}