Hey all, its been a while.
I apologize for my prolonged vacancy in this community, I mean no harm.
I am forcing myself to learn crystal, as some sort of mental challenge for myself.
Code:
i have written this in crystal.
it does this:
I am trying to optimize this as best as I can, and I don't know if there's much more I can do.
thoughts?
some folk on r/unixporn's discord guild, recommended read buffers and trying other hash algos, but then again, the same people re-wrote this in rust, so go figure.
I apologize for my prolonged vacancy in this community, I mean no harm.
I am forcing myself to learn crystal, as some sort of mental challenge for myself.
Code:
#!/usr/bin/env crystal
# Define a Hash to store the count of each login shell
shellcnt = Hash(String, Int32).new(0)
# Open the passwd file and iterate over each line
File.open("passwd") do |file|
file.each_line do |line|
# Split the line into fields using colon as the delimiter
fields = line.chomp.split(':')
# Extract the login shell from the last field
shell = fields[-1]
# Increment the count of this login shell in the Hash
shellcnt[shell] += 1
end
end
# Iterate over the Hash and print the counts for each login shell
shellcnt.each do |key, value|
printf("%-20s%-8s%-d\n", key, ":", value)
end
i have written this in crystal.
it does this:
- Open a colon delimited unix password file (provided as 'passwd') in the current directory
Read the file and count the instances of each login shell (the last field)
For each login shell, print the number of accounts using each shell
I am trying to optimize this as best as I can, and I don't know if there's much more I can do.
thoughts?
some folk on r/unixporn's discord guild, recommended read buffers and trying other hash algos, but then again, the same people re-wrote this in rust, so go figure.