Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 13:27
    Blacksmoke16 labeled #12065
  • 13:27
    Blacksmoke16 labeled #12065
  • 09:18
    I3oris opened #12065
  • May 21 17:59
    HertzDevil labeled #12064
  • May 21 17:59
    HertzDevil labeled #12064
  • May 21 17:59
    HertzDevil labeled #12064
  • May 21 17:59
    HertzDevil opened #12064
  • May 20 20:01
    beta-ziliani milestoned #12033
  • May 20 19:13
    beta-ziliani milestoned #12040
  • May 20 18:57
    beta-ziliani milestoned #11984
  • May 20 18:50
    beta-ziliani review_requested #11972
  • May 18 13:16
    hugopl closed #12062
  • May 17 20:20
    Blacksmoke16 synchronize #12044
  • May 17 18:19
    straight-shoota edited #11947
  • May 17 18:19
    straight-shoota milestoned #11947
  • May 17 18:18
    straight-shoota closed #11971
  • May 17 18:18
    straight-shoota closed #11970
  • May 17 17:21
    HertzDevil labeled #12063
  • May 17 17:21
    HertzDevil labeled #12063
  • May 17 17:21
    HertzDevil labeled #12063
George Dietrich
@Blacksmoke16
np
works quite well. e.g. can do like id = db.exec "insert into users (name, email) returning id", "Bob", "example@gmail.com", as: Int64

oops

id = db.exec "insert into users (name, email) values (?, ?) returning id", "Bob", "example@gmail.com", as: Int64

throw that in some module and is pretty easy to do like SomeModule.save user
From IRC (bridge bot)
@FromIRC
<Sankalp> @Blacksmoke16: cool lib!
George Dietrich
@Blacksmoke16
:heart:
Elias Perez
@eliasjpr
Hello, sharing this small library about http session management https://shards.info/github/azutoolkit/session/
Anhedonia
@anhedonia:sakura.ci
[m]
I have a question about C bindings, is there an easy way to pass an IO instance (STDOUT for example, preferably instance of IO::Memory) to a C function that takes FILE* as an argument?
lib SomeCLib
    type File = Void
    fun function(file : File*) : Void
end

io = IO::Memory.new
SomeCLib.function(???)
Remilia Scarlet
@remiliascarlet:nanako.mooo.com
[m]
If I'm not mistaken, if the IO is actually a File, then you can use that_io.fd to get the raw file descriptor.
https://crystal-lang.org/api/1.4.1/IO/FileDescriptor.html#fd%3AInt-instance-method
Not sure about other subclasses of IO, though.
Remilia Scarlet
@remiliascarlet:nanako.mooo.com
[m]
It could be that I'm missing something in the standard library that already does this for you, but a few quick searches isn't pulling up much ^_^; So unless it exists, you could wrap fdopen, then use your wrapped function long with #fd to get a FILE* pointer. But again, that's with actual files (including STDOUT and friends).
Anhedonia
@anhedonia:sakura.ci
[m]
yeah this works, just gonna hack my way through
lib C
    type File = Void

    fun fprintf(stream : Pointer(File), format : Pointer(LibC::Char), ...) : Void
    fun fdopen(fd : LibC::Int, mode : Pointer(LibC::Char)) : Pointer(File)
end

file = C.fdopen(STDOUT.fd, "w")
C.fprintf(file, "Hello from C\n")
George Dietrich
@Blacksmoke16
out of curiosity, does:
file = pointerof(STDOUT.fd)

C.fprint(file, "Hello from C\n")
Anhedonia
@anhedonia:sakura.ci
[m]
nope
George Dietrich
@Blacksmoke16
rip
Remilia Scarlet
@remiliascarlet:nanako.mooo.com
[m]
Yeah, fd is an integer representing the handle, FILE* is some sort of structure, iirc :(
Been a while since I've done anything with C
George Dietrich
@Blacksmoke16
makes sense
From IRC (bridge bot)
@FromIRC
<frojnd> Hi there.
Ali Naqvi
@naqvis
Hi
From IRC (bridge bot)
@FromIRC
<frojnd> I would like to add array of object inside {foo: arr}.to_json but I get error like unexpected tocken arr: https://carc.in/#/r/d6jc any ideas?
George Dietrich
@Blacksmoke16
use () with puts
puts({foo: baz})
From IRC (bridge bot)
@FromIRC
<frojnd> @Blacksmoke16 thank you~
<frojnd> s/~/!
George Dietrich
@Blacksmoke16
essentially related to crystal-lang/crystal#6573
Quinton Miller
@HertzDevil
is this meant to work?
x = 123_i8
y : Int16 = x
Ali Naqvi
@naqvis
shouldn't be, as iirc, Crystal doesn't do implicit conversion
oprypin
@oprypin:matrix.org
[m]
@HertzDevil: yea it's new in 1.3.0 i think crystal-lang/crystal#11431
Quinton Miller
@HertzDevil
yeah i mean if that pr is meant to cover the above case
oprypin
@oprypin:matrix.org
[m]
oh ok
Ali Naqvi
@naqvis
i hope they don't. As its better to be explicit than having half apple half banana
oprypin
@oprypin:matrix.org
[m]
don't know if it's meant but looks nice to me
ah so it doesn't currently work as such. i was confused by the phrasing
From IRC (bridge bot)
@FromIRC
<frojnd> Hi there.
<frojnd> I'm trying to pass a json payload looks like this: {"uploads":[{"name":"foo", "bar":["foo","bar"]}, {"name":"bar", "bar":["foo"]}]} I'm using Kemal framework. Problem is that I don't know how to get further down uploads. How to catch params inside upload array. For uploads I do: uploads = env.params.json["uploads"].as(Array)
<frojnd> But how do I loop over name and bar?
From IRC (bridge bot)
@FromIRC
<frojnd> Ok I'm inside uploads loop and elemts are of of type JSON::Any how can I parse so I can get to the name and bar?
<frojnd> Wow, just pp elemnt puted json string for each element! Nice
George Dietrich
@Blacksmoke16
frojnd: you have two options
1) do what you're doing now and work with JSON::Any. E.g. to print the name of each obj you could do like:
env.params.json["uploads"].as_a.each do |upload|
  pp upload.as_h["name"].as_s
end
2) define the structure of your payloads as structs and use https://crystal-lang.org/api/JSON/Serializable.html, something like:
uploads = Array(Upload).from_json env.request.body
From IRC (bridge bot)
@FromIRC
<f1refly> <>
<f1refly> wrong channel sry
<f1refly> {}
<f1refly> fuck