Questions tagged [crystal-lang]

Crystal is a programming language with a Ruby inspired syntax but statically type checked and compiled to native and efficient code.

Links

Projects

660 questions
0
votes
2 answers

How to remove a specific element from an array in Crystal Lang?

I have an array of multiple types ( Int32 | Char | String ) and need to remove a specific element. Is there a simple way to do that?
dkimot
  • 2,239
  • 4
  • 17
  • 25
0
votes
1 answer

How to check if a string is contained in a substring in Crystal Lang?

I don't see a String#contains method or a String#search method in the Crystal API.
dkimot
  • 2,239
  • 4
  • 17
  • 25
0
votes
1 answer

How can an unprepared statement be sent to Postgres in Crystal?

Is it possible to send an unprepared statement to a Postgres Connection (using the crystal-db and crystal-pg shards)? I've tried running the following statements using the .query methods, but they failed because they use a prepared statement, which…
dgo.a
  • 2,634
  • 23
  • 35
0
votes
1 answer

Computing a (Non-MD5) 128 bit hash with salt

So for a piece of code I am writing, I want to create a 128 bit hash - like the one in the MurmurHash3 library (https://pypi.python.org/pypi/mmh3/2.5.1) Note: I also want to add a salt to the hash which I already have as a string I was looking…
madcrazydrumma
  • 1,847
  • 3
  • 20
  • 38
0
votes
1 answer

Merge hash with varying key-value pairs in Crystal

So I have various hashes which do not always have the same key/value pairs in them. What I want to do is to be able to merge the hashes, but to add an empty key/value pairs if they don't already exist in that hash, but do in others. It's hard to…
Anton Maminov
  • 463
  • 1
  • 6
  • 11
0
votes
1 answer

Threading HTTP requests in Crystal

I have code that needs to run in "parallel" (not real, I know Crystal does not support parallelism). require "http/client" thread_count = 4 resps = [] of HTTP::Client::Response mutex = Thread::Mutex.new urls = [] of String (1..10).each { |i| urls…
Anton Maminov
  • 463
  • 1
  • 6
  • 11
0
votes
1 answer

EOF error requiring file when compiling

So I currently have the current directory structure: - project - lib - struct - external - external.cr - src - project - version.cr - project.cr - ... - shard.yml I am currently compiling my code using the…
madcrazydrumma
  • 1,847
  • 3
  • 20
  • 38
0
votes
1 answer

Crystal - How to recursively change Hash values and save each change to new Hash

using this Hash object {"foo" => {"bar" => 1, "baz" => 2}, "bla" => [1,2,3]} I want to produce this array of Hash objects [ {"foo" => "*", "bla" => [1,2,3]}, {"foo" => {"bar" => "*", "baz" => 2}, "bla" => [1,2,3]}, {"foo" => {"bar" => "1",…
Ba7a7chy
  • 1,471
  • 4
  • 14
  • 29
0
votes
1 answer

Null Type filtering on nested Crystal object

I get an undefined method 'start_time' for Nil (compile-time type is (Reservation | Nil)) for the code if game.reservation && other_game.reservation if(game.reservation.start_time == other_game.reservation.start_time) …
user3331142
  • 1,222
  • 1
  • 11
  • 22
0
votes
1 answer

How to set a variable by its symbolized name

I'm learning crystal (just for fun) and trying to implement kind of []= method for a struct. Here is the first attempt: struct Foo @str : String | Int32 # Have to share all the types, NOT OK @int : Int32 | String # Have to share all the types,…
WPeN2Ic850EU
  • 995
  • 4
  • 8
0
votes
1 answer

How to convert to Crystal ruby's multiple assignments of Array

I have a small (formerly) ruby blockchain script I'm trying to convert over into Crystal, that looks like this so far: # build your own blockchain from scratch in crystal! # # to run use: # $ crystal ./blockchain_with_proof_of_work.cr require…
Kelsey Hannan
  • 2,857
  • 2
  • 30
  • 46
0
votes
2 answers

How to store Bytes/Slice(UInt8) as a string in Crystal?

I'm encoding an Object into Bytes (ie Slice(UInt8)) via MessagePack. How would I store this in a datastore client (eg Crystal-Redis) that only accepts Strings?
dgo.a
  • 2,634
  • 23
  • 35
0
votes
1 answer

How do I replicate this specific pack example in crystal?

Ruby code sample: "\u0000\u0000\u0000\u0002".unpack('N')[0] #=> 2 How can I do this with crystal language?
qpi
  • 209
  • 3
  • 7
0
votes
1 answer

Undefined references on run, SSL

Trying out Kemal in a VM, fresh install of Arch-Linux with gc, openssl, crystal, and shard packages. Ran through steps on Kemal guide for simple web app, but errors upon crystal run src/test_app.cr: _main.o: In function '__crystal_main': …
Aaron Thomas
  • 5,054
  • 8
  • 43
  • 89
0
votes
3 answers

Call code from module and execute it since a chosing option in menu

I don't understand why when I execute my code and I chose the first option he left without doing anything. You will find below the code of my crystal script. require "colorize" class Application def initialize mainMenu end def mainMenu …
Oliver
  • 21
  • 2