Is there a timer or interval function in Crystal?
I checked the docs for a timer, interval, and under the Time class, but did not see anything.
Something like setInterval() or setTimeout() from JavaScript?
I need to verify if a constant is defined to do a conditional.
I was trying this but "defined" method not exists on this language:
if defined(constant)
value = :foo
else
value = :bar
end
Is recursive proc posible in Crystal?
Something like lambda in Ruby
I'm trying to do a y-combinator in Crystal,something like Ruby one:
puts -> {
fact_improver = ->(partial) {
-> (n) { n.zero? ? 1 : n * partial.(n-1) }
}
y = ->(f) {
…
I’m trying to figure out how c bindings in crystal work. For starters I’m wondering how I would include a simple hello world c function into crystal. Always good to start with the basics right? Here’s the function I’d like to include:
#include…
I want to execute a shell script while handling stdout and stderr output. Currently I execute commands using Process.run, with shell=false and three pipes for stdin, stdout and stderr. I spawn fibers to read from stdout and stderr and log (or…
I have a JSON response which is an Array of Hash:
[{"project" => {"id" => 1, "name" => "Internal"},
{"project" => {"id" => 2, "name" => "External"}}]
My code looks like this:
client = HTTP::Client.new(url, ssl: true)
response =…
I'm having some hard time learning the idea behind Fibers\coroutines and the implementation in Crystal.
I hope this is the right place to ask this, I'll totally accept a "not here" answer :)
This is my usual way of handling multi-threading in…
I want to access the serial port using Crystal lang.
I have following code in python. I want to write the equivalent Crystal-lang code for a pet project.
import serial
def readSerData():
s = ser.readline()
if s:
print(s)
…
I have a Kemal-based RESTful web service that returns "very big" (from 10 to 17M in size) chunks of JSON data, which is produced by to_json method from the "big" Hash structure.
According to GC warning messages my code "may lead to memory leaks"…
I'm testing about serialization with bytes or slices, just learning and trying. I would like to bind 3 parameters in a single 10 bytes field, but I don't now how to concatenate them in Crystal or whether it is possible. I know I can achieve this by…
I read the documentation on Procs in the Crystal Language book on the organizations’s site. What exactly is a proc? I get that you define argument and return types and use a call method to call the proc which makes me think it’s a function. But why…
What is the idiomatic way to write the equivalent of an algebraic data type in Crystal? E.g. In Haskell I might have
data Stage = StageInitial String | StageFinished String
So I want to have two stages, each which has a string payload. Later on I…
I've been running my Crystal webapp by building it, and then running the executable. However, it always listens on port 3000.
How do I build/run Crystal webapps listening on 80 and 443?
I'm using Kemal as well. Here is my sample app.
require…
Just discovered Amber...looks nice! How can I deploy a sample App on an Ubuntu Server? Should it be done just like Rails, routing the path to public? Or some other part of the structure?
Thanks for your advice.