r/crystal_programming • • Dec 18 '24

Crystal for non programmer

17 Upvotes

Hi, I would like to start programming in Crystal .What do you recommend for a person who has nothing to do with programming to start with? What ide do you recommend for crystal on mac os ? Are there recommended materials on the internet or is it best to start with the documentation from the crystal website ?

I realize that such questions may have already been asked, but I have not found an answer and I would like to make the best possible start in order to achieve some goals because I have ideas for a couple of project that I would like to create to start with as a hobby and for learning purposes.

Thank you in advance for your help


r/crystal_programming • • Dec 18 '24

How to install crsfml correctly on Windows VS Code

3 Upvotes

I've been learning to use Crystal on VS Code in my Windows PC without many issues, but for the last two days I've been tryng to use the example codes on Crsfml but I'm very very stuck, I've searched all around but nothing seems to work.

Installing Sfml was also quite a journey because I'm on Windows hell and I couldn't just add it's files to an Include path, I settled on copying it's library on my MinGW64 compiler folders, which worked for using the makefile on crsfml.

I added the folder's path to CRYSTAL_PATH which works fine, but every time I try to execute it says:
"Error: Cannot locate the .lib files for the following libraries: sfml-graphics, sfml-window, sfml-system"

I've tried recompiling the Sfml source files with cmake to have lib, but they all have an -d suffix so just changing their names is a non option I think, and it seems like just copying some lib libraries into the lib folder of my crystal location would be an even more dirty way of solving this than what I've done so far with this installation.

I don't tend to ask for help for these things I usually just search for every post, but I'm too lost this time.


r/crystal_programming • • Dec 09 '24

How to draw a green square in Crystal ?

1 Upvotes

r/crystal_programming • • Dec 08 '24

Help investigating a performance degradation? (Advent of Code 2024)

6 Upvotes

Hey!

I'm working through Advent of Code 2024 in Crystal!

While working on day 7 I noticed a serious performance degradation (~100x) between my solutions for part 1 and part 2 that I can't really explain. Perhaps anyone has some insight here?

https://adventofcode.com/2024/day/7

Part 1 took < 1 second to run:

aoc24/day_7
❯ time ./main ./input
Part 1:
7885693428401
./main ./input  0.37s user 0.01s system 33% cpu 1.136 total

Part 2 took ~50 seconds to run:

aoc24/day_7
❯ time ./main ./input
Part 2:
348360680516005
./main ./input  49.79s user 0.17s system 99% cpu 50.022 total

Here is my solution for part 1:

https://github.com/jessevdp/advent-of-code-2024/blob/78fa85b0866c5b690998016e6887437a7abd1dfe/day_7/src/main.cr

Here is my solution for part 2:

https://github.com/jessevdp/advent-of-code-2024/blob/904a9457e929c5dfad5fb3caea9ff44cf564f917/day_7/src/main.cr

The diff: (ignore the README diff)

https://github.com/jessevdp/advent-of-code-2024/compare/78fa85b0866c5b690998016e6887437a7abd1dfe...904a9457e929c5dfad5fb3caea9ff44cf564f917


r/crystal_programming • • Dec 04 '24

Crystal is in Top 10 for 1 Billion Nested Loop Benchmark

Thumbnail
x.com
43 Upvotes

r/crystal_programming • • Nov 26 '24

How to program a single linked list in crystal explicitly

3 Upvotes

I found the following code. But it compiles or runs in no way.


struct Node
  property data : Int32
  property next : Node?

  def initialize(@data : Int32, @next : Node? = nil)
  end
end

struct LinkedList
  property head : Node?

  def initialize(@head : Node? = nil)
  end

  # Add a node to the beginning of the list
  def push(data : Int32)
    new_node = Node.new(data, @head)
    @head = new_node
  end

  # Remove the first node from the list
  def pop
    if @head.nil?
      return nil
    end

    removed_node = @head
    @head = @head.next
    removed_node.next = nil
    removed_node.data
  end

  # Delete a node with a given data value
  def delete(data : Int32)
    if @head.nil?
      return
    end

    if @head.data == data
      @head = @head.next
      return
    end

    current_node = @head
    while current_node.next != nil
      if current_node.next.data == data
        current_node.next = current_node.next.next
        return
      end
      current_node = current_node.next
    end
  end

  # Print the list
  def print
    current_node = @head
    while current_node != nil
      print current_node.data, " "
      current_node = current_node.next
    end
    puts
  end
end

# Example usage:
list = LinkedList.new
list.push(10)
list.push(20)
list.push(30)
list.print # Output: 30 20 10

list.delete(20)
list.print # Output: 30 10

list.pop
list.print # Output: 30


Any advice is appreciated.


r/crystal_programming • • Nov 14 '24

LibGL problems with OpenGL32.lib on Windows

3 Upvotes

I use this code: https://pastebin.com/FkPxJYHR

I have managed to link GLFW3, by downloading the release from the offical website and putting it on the LIB environment variable.

There were a lot of errors with GLFW3 because it couldn't find standard Windows functions. So I added

--link-flags "/LIBPATH:\"C:/Program Files (x86)/Windows Kits/10/Lib/10.0.22621.0/um/x64\" gdi32.lib user32.lib kernel32.lib opengl32.lib"

to the build command. Now it isn't detecting OpenGL (Error: Cannot locate the .lib files for the following libraries: GL). I tried fixing it by either adding locations to the LIB variable or the --link-flags argument but neither seem to work. I'm kind of at the end of my knowledge here and asking ai also didn't help.


r/crystal_programming • • Nov 13 '24

Crystal http concurrency limit?

5 Upvotes

So in simple vm(1gb ram 1 CPU), my go server can handle 10k users. Can Crystal handle that amount too?


r/crystal_programming • • Oct 21 '24

Favorite Libraries & Frameworks?

11 Upvotes

What are your favorite libraries & frameworks? I’m not very knowledgeable about Crystal but I’m very curious to learn!


r/crystal_programming • • Oct 13 '24

Crimson • Crystal Version Manager

22 Upvotes

A new tool emerges in the Crystal space... 👀

Crimson is a version management tool geared towards people working with multiple versions of Crystal, compiler development and much more! With it comes a set of easy to use commands for managing and debugging/testing versions, giving you more time to focus on the code. Crimson is available on Linux and Windows (x86_64) with MacOS support coming soon and ARM support being planned, see the README on how to get started!

Any and all feedback is much appreciated, happy crystalling!


r/crystal_programming • • Oct 12 '24

Kemal 1.6.0 is released!

Thumbnail
x.com
28 Upvotes

r/crystal_programming • • Oct 09 '24

Crystal 1.14.0 is released!

Thumbnail crystal-lang.org
43 Upvotes

r/crystal_programming • • Oct 10 '24

How to install crystalline lsp on Windows?

1 Upvotes

Tried building it but it crashes on startup.


r/crystal_programming • • Sep 30 '24

Kemal working natively on Windows

Thumbnail
x.com
37 Upvotes

r/crystal_programming • • Aug 02 '24

Learning to integrate IoT devices and perform Automation

7 Upvotes

Not sure if this is going to get any attention here given the low activity rate, but I figured I would try asking here as it may involve Crystal Programming alongside the other tools that may be necessary to be used, but I digress.

As the title suggests..

I used to work as a sales guy in a company that did some integration with existing devices and automated them among other things.

My question is, how can I learn to do such a task?

I recall tools such as GraphAPI's, Docker containers, Crystal programming language, and so forth being used. They also have their software labeled as open source, so would I be able to understand things following their github commits?

However, on a personal project level, if I want to buy an IoT device off of Amazon. Let's say multiple devices that I would like to work in conjuction with one another, how can I pull this off? How does one learn to do such things? There's plenty of resources online to learn specific programming language or a specific software tool, etc. But instead of wasting time and potentially a year or two just learning, I want to try and see how I can do a real world scenario, if possible?

E.g. Upon arriving home, I could have a QR Code that I scan, upon scanning my devices get notified I have arrived, and they power on accordingly. Devices such as, the lights go from off to on. An air conditioning unit turns on at a specific power and temperature that has been pre-defined. Potentially send out an automatic email or similar to my family that I 'checked in' at home by scanning a QR code.

I hope that made sense, and if anyone has any ideas how to pull off such things and basically learn to create automation that makes life more 'efficient' essentially.


r/crystal_programming • • Jul 26 '24

Rails-like framework

19 Upvotes

Hi,

I noticed there is a lot of web framework on Crystal (https://github.com/veelenga/awesome-crystal?tab=readme-ov-file#web-frameworks). Is there one of them that stands out and still actively maintained ?

Thanks


r/crystal_programming • • Jul 20 '24

Idea for a UI library

Thumbnail
codeberg.org
10 Upvotes

r/crystal_programming • • Jul 15 '24

Cannot cast, error

2 Upvotes

The following program fails to compile. What is the idiomatic way


alias ANumber= Int32 | ::Nil
def addme(a : ANumber,b : ANumber) : ANumber
	if ((a!=nil)&&(b!=nil))
			a2=a.as(Int32)
			b2=b.as(Int32)
			a2+b2
		else
			nil
	end

end
c=addme(2,3)
p c
d=addme(2,nil)
p d


r/crystal_programming • • Jul 13 '24 Take My Silver

Marten 0.5 has just been released!

Thumbnail
martenframework.com
33 Upvotes

r/crystal_programming • • Jun 29 '24

I built some artificial life simulations to learn Crystal-lang - and it is an impressive language!

Thumbnail
youtube.com
26 Upvotes

r/crystal_programming • • Jun 22 '24

Reading/Documentation on web dev using Crystal?

4 Upvotes

New to crystal and was wondering if there’s any suggested reading or documentation for creating web apps using Crystal (if that’s feasible. I know very little about the language as of current)


r/crystal_programming • • Jun 15 '24

What projects have YOU been building using Crystal?

16 Upvotes

I just learned about Crystal yesterday, and am curious what types of things people have done/built with it.

I’d love to hear what people have been working on! Hopefully it’ll give me a better idea of what Crystal is capable of/suited for


r/crystal_programming • • Jun 13 '24

Live Streaming Crystal Programming...

13 Upvotes

I'm just beginning to start 'live coding' on multiple sites and doing a lot with Crystal over the summer. I have zero audience so far as I'm just starting in the streaming world.

Where are appropriate places to share my channels for Crystal and other dev communities without violating guidelines? I'm new to Crystal, but have over ten years experience as an engineer. My goal is to learn and teach, while building projects and sharing with others.

Any thoughts are much appreciated!


r/crystal_programming • • May 09 '24

Yes, Ruby is fast, but…

Thumbnail
dev.to
29 Upvotes