<hightower4>
Asked a couple days ago with no particular answer: how can I change the uid/gid from within the program? I'm looking for equivalent of Ruby's Process::UID.change_privilege
vivus has quit [Quit: Leaving]
<FromGitter>
<MrSorcus> > **<hightower4>** Asked a couple days ago with no particular answer: how can I change the uid/gid from within the program? I'm looking for equivalent of Ruby's Process::UID.change_privilege ⏎ I think that crystal has no builtin function/method for changing uid/gid...
<FromGitter>
<MrSorcus> > **<hightower4>** Asked a couple days ago with no particular answer: how can I change the uid/gid from within the program? I'm looking for equivalent of Ruby's Process::UID.change_privilege ⏎ ⏎ I think that crystal has no builtin function/method for changing uid/gid...
<FromGitter>
<MrSorcus> > **<hightower4>** Asked a couple days ago with no particular answer: how can I change the uid/gid from within the program? I'm looking for equivalent of Ruby's Process::UID.change_privilege ⏎ ⏎ https://github.com/jhass/carc.in/blob/master/src/carcin/core_ext/process.cr - Here something with changing uid. Maybe you can use it for writing your own shard...
snsei has quit [Remote host closed the connection]
astronav_ has quit [Remote host closed the connection]
faustinoaq has joined #crystal-lang
astronav_ has joined #crystal-lang
aroaminggeek has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has joined #crystal-lang
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
<FromGitter>
<drosehn> hightower4: I have a crystal program which does that. I keep thinking I should clean it up a bit and submit it somewhere.
<FromGitter>
<drosehn> most likely, as an issue in crystal's github.
<FromGitter>
<drosehn> Well, I don't have `Process::UID.change_privilege`, but I do have `Process.egid=`, `Process.gid=`, `Process.euid=`, and `Process.uid=`.
<FromGitter>
<drosehn> (Oops, I see they're already gone. Unfortunately I've been busy all weekend replacing/rebuilding an SSD disk which had gone into read-only mode, so I think this the first I've been on gitter since Friday).
<FromGitter>
<drosehn> ... and really, I'm about ready to head to bed anyway. it's been a long weekend!
<FromGitter>
<drosehn> (and not in a good way)
astronav_ has quit [Remote host closed the connection]
<DissonantGuile>
I'm getting "'self' was used before initializing instance variable"
aroaminggeek has joined #crystal-lang
aroaminggeek has quit [Client Quit]
hightower4 has quit [Ping timeout: 268 seconds]
<FromGitter>
<picatz> @extremety1989 I learned a lot about C bindings when building https://github.com/picatz/packetz -- let me know if you have any questions!
snsei has quit [Remote host closed the connection]
<FromGitter>
<picatz> I should make a blog post for people to show how I went about figuring out ( with the help of the people in this chat ❤️ ) I also need to update `packetz`. 🙈
<RX14>
DissonantGuile, you call interface_class.new(self)
<RX14>
so the constructor of interface_class has a reference to self
<RX14>
if the interface_class constructor calls a method on self, that's be unsafe because the constructor hasn't finished yet and @interface isn't set
<RX14>
which means it's garbage and will crash
<RX14>
so it can't compile
<RX14>
typically in this situation you have to late-initialize one or the other of the two
<RX14>
here i'd suggest storing interface_class in @interface_class then having a `getter interface { @interface_class.new(self) }`
<DissonantGuile>
That's what I was getting at, so I basically have to make either @application or @interface nilable?
<DissonantGuile>
Oh that's a good idea
<RX14>
yes, here you make @interface nillable
<RX14>
but it's getter will always lazy-init
<RX14>
the downside being that you can get an infinite loop at runtime
<DissonantGuile>
Dang I'm just trying to decouple interfaces from app logic without nil checking everywhere
<RX14>
or you could do it the other way around
<FromGitter>
<extremety1989> @picatz oh, thank you to much, for newcommer, it is so hard to find good exemple tutorials of Crystal lang
<RX14>
make @application late-set
<RX14>
for example have property! application
<RX14>
and then do @interface = interface_class.new
<RX14>
then @interface.application = self
<RX14>
which is more safe actually
<RX14>
since it'll raise instead of loop
<RX14>
hmm
<FromGitter>
<picatz> @extremety1989 I will be making that blog post as soon as I can. 👍
<RX14>
yeah thats better
<DissonantGuile>
But then I would have to change the "if @application.not_nil! && @application.verbose" everywhere right? In my real app I have many more app wide attributes
snsei has joined #crystal-lang
<RX14>
no
<RX14>
because you can use getter!
<RX14>
getter! defines a nillable instance variable but a raise-on-nil getter
gtramontina has joined #crystal-lang
<RX14>
so you always use the getther method which encapsulates the raise on nil behaviour
<RX14>
besides - what you said wouldn't work
<DissonantGuile>
Ah that bit in the docs were a bit confusing but it have me a better error when I used the bang getter so I stuck with it without fully understanding it
<RX14>
you'd need to set application = @application first
<FromGitter>
<extremety1989> @picatz would be great to make some tutorials, for exeple crud operations with channels using postgres, Crystal-lang website lacks of new turorialss...
<RX14>
to make it thread safe for the type checker
<RX14>
because the type checker only allows thread-safe type checks, and accessing @application isn't thread-safe
<DissonantGuile>
That makes sense
<RX14>
i mean accessing 'application twice isn't thread safe
<RX14>
plus not_nil! is the wrong method
<faustinoaq>
Hey. there is 2486 crystal repos on https://crystalshards.org/, How many would be true shards? I mean projects created using `crystal init lib`
<RX14>
not_nil! just raises
<RX14>
you want nil? instead
<RX14>
but most people use truthiness
<RX14>
instead of nil?
<RX14>
if foo to check foo isn't nil and unless foo to check that it is
<RX14>
so the only thing it makes not nil is it's return type
<DissonantGuile>
Right that's very ruby like
<faustinoaq>
<@RX14> by truthiness you mean `if something = something_that_would_be_nil; something; end` ?
gtramontina has quit [Ping timeout: 240 seconds]
<RX14>
it's not useful for type restrictions in any other way
<RX14>
DissonantGuile, it doesn't even use if, we just define def not_nil!; self; end on Object then define struct Nil; def not_nil!; raise; end; end :)
<RX14>
faustinoaq, yes
<FromGitter>
<picatz> @extremety1989 Any other things you'd like to have examples of? :D
<RX14>
i never use nil? and friends
<RX14>
truthiness is much cleaner
<RX14>
well nil? actually doesn't have friends
<Papierkorb>
Note that `#nil?` is an actual language construct, not a normal method
<RX14>
^
<RX14>
it acts like one though
<RX14>
so you can think of it as one
<RX14>
except it's that way so it can be used by the type checker
<RX14>
(otherwise you could override nil? to always be false and boom segfault)
<FromGitter>
<Hates> I'm trying to cross compile a small app from OSX to Ubuntu. I'm following the cross compile instructions but the `cc` command that gets outputted has paths that reference my local machine, for example, the `-lpthread` argument. So this doesn't work when I try and run it on the target machine. Any ideas?
<FromGitter>
<Hates> ```code paste, see link```
<Papierkorb>
Translate the paths yourself?
<FromGitter>
<Hates> Is there any other way if I don't have Crystal installed on the target machine?
<Papierkorb>
You don't, except for the libraries of course.
<FromGitter>
<johnjansen> @Papierkorb can you give me a wee reminder on something … since i know you will know the answer, and ive been lost in another project for a few months … ;-)
<FromGitter>
<Hates> Ok, I'll try and get crystal installed. Thanks :)
<FromGitter>
<bew> @johnjansen your last example is not a bug
<FromGitter>
<johnjansen> yeah i figured
<FromGitter>
<bew> I know there's an issue about that, with explanation somewhere
<FromGitter>
<johnjansen> just trying to understand what the correct way to achieve this is though
<FromGitter>
<johnjansen> even using option parser sensibly without this type of assignment is tricky
<Papierkorb>
There are plenty OptionParser replacement shards
<FromGitter>
<johnjansen> its not really about that per-se, but that is where i discovered the issue (well its an issue for me)
<FromGitter>
<johnjansen> at least till i discover the intended approach
<Papierkorb>
it's more useful used imperatively outside an object
<Papierkorb>
But eh
<FromGitter>
<johnjansen> how about if the object is a singleton
<Papierkorb>
I'd not use it outside of script-y helper programs
<FromGitter>
<johnjansen> option parser aside, i think i simply have the wrong approach to what im trying to achieve, so ill persevere and see what i come up with … thanks for all the comments
gtramontina has joined #crystal-lang
<Papierkorb>
I avoid running code inside class/module bodies in general. So, I guess that kinda "saves" me from funky behaviour and bugs lul
<Papierkorb>
johnjansen, if you insist on using optparser, you can use it to fill an object, just not from inside the objects class. technically, from inside any method would be fine too. or just from outside, in your main .cr file, where it can be easily found. Should be fine if you don't have too many options
<FromGitter>
<johnjansen> optparser works fine … the issue is elsewhere honestly
gtramontina has quit [Ping timeout: 248 seconds]
rohitpaulk has joined #crystal-lang
gtramontina has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
gtramontina has quit [Ping timeout: 240 seconds]
Liothen has joined #crystal-lang
Liothen has quit [Changing host]
Liothen has joined #crystal-lang
Hates_ has quit [Quit: Connection closed for inactivity]
gtramontina has joined #crystal-lang
gtramontina has quit [Ping timeout: 248 seconds]
ShalokShalom has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
gtramontina has joined #crystal-lang
gtramontina has quit [Client Quit]
raz has quit [Ping timeout: 252 seconds]
raz has joined #crystal-lang
raz has quit [Changing host]
raz has joined #crystal-lang
faustinoaq has quit [Remote host closed the connection]
faustinoaq has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 260 seconds]
faustinoaq has quit [Ping timeout: 248 seconds]
faustinoaq has joined #crystal-lang
faustinoaq has quit [Client Quit]
faustinoaq has joined #crystal-lang
faustinoaq has quit [Ping timeout: 248 seconds]
p0p0pr37 has quit [Remote host closed the connection]
faustinoaq has joined #crystal-lang
<FromGitter>
<elorest> Potentially useful tool for easily running code in a console like fashion. Check it out and let me know what you think. ⏎ https://github.com/elorest/cry
<FromGitter>
<elorest> Based some of it off of pry.
<Papierkorb>
what makes it different from icr?
<oprypin>
it runs only one line, i dunno
<oprypin>
and you can't require aor make a class or anything
<oprypin>
i was like, how did he solve the 'eval' problem
<oprypin>
and then i see `"puts (#{args.code}).inspect"` mkay
<oprypin>
crystal eval really should do this out of the box tho
<FromGitter>
<elorest> <Papierkorb> It’s different than icr because it doesn’t pretend to be a console. ⏎ Rather it puts code in a tmp file and runs it. You can get back to a previous run with `cry -b #`
<FromGitter>
<elorest> <oprypin> Yeah it is similar to carc.in but uses vim and isn’t web based. Also keeps a log of code run and results. It’s similar to pry edit, without the rest of pry. For me pry edit is one of my favorite tools though in ruby.
p0p0pr37 has joined #crystal-lang
<FromGitter>
<elorest> carc.in is fantatic and I use it all the time but it’s limited because you can’t control dependencies and you have to use the web editor. It obviously has the added benifit of being sharable though. :)