* leitz
wonders what havenwood is doing up this late.
<havenwood>
leitz: Can shorten line 4 a bit now that there's __dir__: $LOAD_PATH << File.expand_path('../lib/', __dir__)
kyrylo has quit [Read error: Connection reset by peer]
<havenwood>
leitz: Not that it matters here, since the process ending closes the file descriptor, but the block form of File.open auto-closes on end.
kyrylo has joined #ruby
<havenwood>
leitz: it's faster to parse Array literal `[]` instead of Array.new.
<havenwood>
jobs = []
<leitz>
havenwood, I've used the block for now and again. This is proof of concept for me, I've been stumped on how to parse the file for a long time. And it seems having a current resume is good. :)
<havenwood>
leitz: Normally I'd suggest extracting your Regexp to a constant. Creating it in a method causes object churn.
<leitz>
I tend to use "Array.new" or Hash.new so I can search for it in the files. Unix grep often chokes on special character strings like []
kyrylo has quit [Read error: Connection reset by peer]
kyrylo has joined #ruby
aupadhye has quit [Remote host closed the connection]
deepredsky has joined #ruby
snapcase has joined #ruby
suukim has joined #ruby
<leitz>
havenwood, have you had too many energy drinks?
<havenwood>
leitz: that reminds me... coffee time!
code_zombie has joined #ruby
<adam12>
lol
<leitz>
havenwood, when you get back, I'll go back to the "Lines 86-88" question. If there was an answer I missed it in the reboot. I did add your comments so I can track them.
<havenwood>
leitz: What's the issue you're running into?
<leitz>
Yup. Lines 66-68 seem klugy. They previous block triggers an object build on the *next* new section, which means the last section in the file doesn't get created.
<leitz>
Now lines 84-86.
<leitz>
I added notes. :)
kyrylo has quit [Read error: Connection reset by peer]
kyrylo has joined #ruby
jenrzzz has joined #ruby
<havenwood>
leitz: An alternative to using a block with #open is to just: File.foreach(filename) do |line|
<leitz>
havenwood, symbols should work. The end state is either a JSON or text file that can get loaded, and then use whatever "format" the particular resume needs to be in. The lines starting at L88 are the basis of what a format would be.
<leitz>
Symbols work. Implementing some other things.
<leitz>
:w
deepredsky has joined #ruby
deepredsky has quit [Ping timeout: 245 seconds]
ellcs has quit [Ping timeout: 245 seconds]
ellcs has joined #ruby
SeepingN has joined #ruby
jenrzzz has quit [Ping timeout: 245 seconds]
AJA4350 has joined #ruby
salerace has joined #ruby
sytherax has joined #ruby
wallace_mu has quit []
sytherax has quit [Ping timeout: 245 seconds]
basic has quit [Ping timeout: 258 seconds]
ellcs has quit [Ping timeout: 268 seconds]
tdy has quit [Ping timeout: 248 seconds]
Ryctolagus has joined #ruby
bruce_lee has quit [Ping timeout: 268 seconds]
matheusmoreira has joined #ruby
jenrzzz has joined #ruby
bruce_lee has joined #ruby
bruce_lee has quit [Changing host]
bruce_lee has joined #ruby
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
frem has joined #ruby
kyrylo has quit [Read error: Connection reset by peer]
kyrylo has joined #ruby
TomyWork has quit [Ping timeout: 246 seconds]
Swyper has quit [Remote host closed the connection]
Swyper has joined #ruby
mikecmpbll has quit [Quit: inabit. zz.]
ukd1 has joined #ruby
Ryctolagus has quit [Read error: Connection reset by peer]
eddof13 has joined #ruby
salerace has quit [Quit: salerace]
jenrzzz has quit [Ping timeout: 258 seconds]
AJA4350 has quit [Ping timeout: 245 seconds]
kyrylo has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
bruce_lee has quit [Ping timeout: 246 seconds]
bruce_lee has joined #ruby
sytherax has joined #ruby
sytherax has quit [Client Quit]
duderonomy has joined #ruby
cow[moo] has quit [Read error: Connection reset by peer]
<jokke>
hey there
<havenwood>
jokke: hi
<jokke>
i'm trying to figure out how to write c bindings for ruby
<jokke>
i'm struggling a bit with methods
<jokke>
so from the docs i gathered that the function i pass to the rb_define_method function will be called with the ruby instance of the object the method was called on
<jokke>
the question is, how can i get the initializer to store a pointer to the instance on c level.
<jokke>
and how can i access that pointer from the function i pass to rb_define_method
<jokke>
what i'm actually trying to do is write something in crystal and use it from ruby
<jokke>
crystal too is object oriented so i'd need to call methods on an instance of the corresponding crystal class
<jokke>
what i'm struggling with is how to associate the crystal instance with the ruby instance
<havenwood>
jokke: You can create a gem with a Crystal extension then embed MRuby in your Crystal code.
SeepingN has quit [Quit: The system is going down for reboot NOW!]
wildtrees has joined #ruby
wildtrees has quit [Remote host closed the connection]
wildtrees has joined #ruby
Swyper has quit [Remote host closed the connection]
wildtrees has quit [Remote host closed the connection]
wildtrees has joined #ruby
ukd1 has quit [Ping timeout: 245 seconds]
wildtrees has quit [Remote host closed the connection]
fphilipe_ has quit [Ping timeout: 272 seconds]
_Joes_ has joined #ruby
ukd1 has joined #ruby
_Joes_ has quit [Ping timeout: 245 seconds]
ukd1 has quit [Ping timeout: 246 seconds]
SuperL4g is now known as SuperLag
Nicmavr has quit [Read error: Connection reset by peer]
ukd1 has joined #ruby
Nicmavr has joined #ruby
ramfjord has joined #ruby
suukim has quit [Quit: Konversation terminated!]
bmurt has joined #ruby
Xiti` has joined #ruby
Xiti has quit [Ping timeout: 268 seconds]
poontangmessiah has quit [Remote host closed the connection]
Xiti` is now known as Xiti
jenrzzz has quit [Ping timeout: 244 seconds]
bmurt has quit [Ping timeout: 276 seconds]
fphilipe_ has joined #ruby
gix has joined #ruby
s2013 has joined #ruby
kyrylo has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
eddof13 has quit [Quit: eddof13]
Huck777 has quit [Ping timeout: 245 seconds]
jenrzzz has joined #ruby
tdy has joined #ruby
tdy1 has joined #ruby
eddof13 has joined #ruby
tdy has quit [Ping timeout: 268 seconds]
teardown has joined #ruby
SuperLag has quit [Quit: reboot]
frem has quit [Quit: Connection closed for inactivity]
GodFather_ has joined #ruby
GodFather has joined #ruby
SuperLag has joined #ruby
jenrzzz has quit [Ping timeout: 268 seconds]
<jidar>
Can somebody tell me what exception catch I can write to catch only things found in net/smtp? I'm using the following code: https://gist.github.com/227c23a3cc478c65ce1af50a1f8eeb62 but it's catching errors further up the stack and causing the application to bomb abnormally
<jidar>
it looks like there's a few Net::SMTP<something>Errors to catch?
morenoh149 has joined #ruby
fphilipe_ has quit [Ping timeout: 276 seconds]
jenrzzz has joined #ruby
eddof13 has quit [Quit: eddof13]
<havenwood>
jidar: Net::SMTPError is mixed into all the other SMTP error classes, so you can just rescue it.
<havenwood>
jidar: It's almost always a bad idea to: rescue Exception
<havenwood>
jidar: A plain `rescue` is implicitly `rescue StandardError`.
<havenwood>
jidar: rescue Net::SMTPError
<havenwood>
jidar: You can omit `=> e` if you're not using `e`.
fphilipe_ has joined #ruby
jcalla has quit [Ping timeout: 245 seconds]
<jidar>
groovy thanks havenwood
tdy1 has quit [Ping timeout: 246 seconds]
AJA4350 has joined #ruby
jenrzzz has quit [Ping timeout: 245 seconds]
s2013 has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
bmurt has joined #ruby
<Retr0Punk>
hey all, i am looking into adding templating to my program, that is, not HTML templating, but a template for the command line. for example, i'd like to have a config file where someone can input something like #{track} - #{title} - #{artist} and have the program output the correct data to the terminal. where could i start to look into doing this?
<darix>
Retr0Punk: for that kind of stuff you dont even need a templating library
<Retr0Punk>
havenwood: that is HTML templating though, could i use ERB in the same fashion for templating on the command line?
<Norrin>
Nice
<havenwood>
Retr0Punk: I don't think "templating" is really what you want, after reading what you've said.
<havenwood>
Retr0Punk: Folk often use a serialization format, like YAML, for config files.
jenrzzz has joined #ruby
<Retr0Punk>
yeah i was thinking YAML, ok i will look into including that in my project, maybe read from a file or user input on the command line with YAML
<Retr0Punk>
thank you :)
eddof13 has joined #ruby
<leftylink>
so. would it work if you just made them enter a string like '%<title>s' and then you just use % to format it?
<leftylink>
if you're really set on not making them remember the exact format of %<title>s, maybe they think the angle brackets and the s are TOO BURDENSOME or something, then maybe you can just make them do <title> and you insert the % and s yourself
<Retr0Punk>
leftylink: that is exactly what i need
<Retr0Punk>
right now, i made a config file in my home directory including: output: "%TRACK%. %TITLE% (%LENGTH)"
<leftylink>
also in case you ever came across a suggestion `eval ?" + template + ?"`, I highly recommend against :) since someone will set `template = '"; puts :pwned; "'`
<Retr0Punk>
i then use YAML.load to load this into Ruby, but i am wondering if what you did with %<title> is some built in Ruby thing?
SeepingN has joined #ruby
<leftylink>
please see the documentation for String#%
<Retr0Punk>
i don't see any angle brackets on this page :/ it's ok though, i can look into it more if it's really basic lol
tpanarch1st_ has quit [Ping timeout: 272 seconds]
matheusmoreira has quit [Quit: leaving]
<leftylink>
although it is surely the case that the snippet of code `'%<title>s' % {title: :arghhh}` was indeed using String#%, there is no question about that. so the logical place to start looking at documentation is String#%
<leftylink>
if it is so the case that the documentation for String#% asks one to look at other documentation, so too should that documentation be looked at.
ur5us has joined #ruby
<Retr0Punk>
yes, i don't want to be a bother, i will look into it more. thank you
<leftylink>
I can also add as a general point. sometimes it can be hard to tell whether a question would be a bother or not. it would be a shame if a person became too afraid to ask questions. but that is usually okay. people probably notice what I do. there are certain questions to which my answers take the form of "here are general rules that will help a person to know where to find the answer for oneself"
galaxie has joined #ruby
<leftylink>
and it is that way because 1. (hopefully) it is helpful whether the asker was a vampire or not, and if they were a vampire I need to give that kind of answer for my own sake anyway. and 2. if I just tell them the answer they learn nothing
<leftylink>
my general philosophy is nothing is magic though, so I hope to help allow people to see that it is not magic
<Retr0Punk>
no i understand that, i am aware that what i am asking is pretty rudimentary stuff, and honestly i am not proud to need to ask these questions, as a professional developer, it just feels like Ruby is a completely new ecosystem to me and things aren't clicking in my brain as easy as i'd like them to. but i do not fault you for pointing me in the right direction, you have been very helpful
poontangmessiah has joined #ruby
morenoh149 has quit [Ping timeout: 245 seconds]
queip has quit [Ping timeout: 272 seconds]
s2013 has joined #ruby
Ryctolagus has quit [Quit: Leaving]
tdy1 has joined #ruby
queip has joined #ruby
lxsameer has quit [Ping timeout: 246 seconds]
chalkmonster has quit [Quit: WeeChat 2.5]
ukd1 has quit [Ping timeout: 246 seconds]
ukd1 has joined #ruby
elated has quit [Ping timeout: 245 seconds]
ellcs has quit [Ping timeout: 248 seconds]
mynameisdebian has joined #ruby
<mynameisdebian>
I have an Apache script serving a CGI script that responds to Slack events. Apache always takes several seconds to respond with "200 OK", and because of it Slack is throwing a message. How do I respond with 200 and send it right away with Ruby?
<bougyman>
make it faster
<bougyman>
This is a vague question, I can only give a vague answer.
gix has quit [Remote host closed the connection]
gix has joined #ruby
AJA4351 has joined #ruby
poontangmessiah_ has joined #ruby
AJA4350 has quit [Ping timeout: 246 seconds]
AJA4351 is now known as AJA4350
poontangmessiah has quit [Ping timeout: 245 seconds]
<baweaver>
bougyman: be nice.
<baweaver>
Instead, ask mynameisdebian for more details that help clarify the question
<baweaver>
Such as what the script is, what code it has, if they've tested where the bottleneck is..
morenoh149 has joined #ruby
<mynameisdebian>
I have an Apache server running a Ruby CGI script. The CGI script receives a message from Slack, responds to Slack with "HTTP OK", then does a bunch of other stuff. It seems like the Apache server does not send 200 until the CGI script completes. Is there any way to make Apache return 200 without waiting for the script to complete?
beanie__ has quit [Ping timeout: 272 seconds]
tpanarch1st_ has joined #ruby
drincruz has quit [Ping timeout: 268 seconds]
<SeepingN>
yes. Fork the meat of your app in a 2nd script.
<SeepingN>
then return 200 and either wait for child to finish or just let it go unattached
phenom has joined #ruby
<mynameisdebian>
SeepingN: Thank you for the reply. Is that a common solution, and this a common problem? Can you elaborate on "wait for child to finish or just let it go unattached"? What do you mean by those two options there?
<mynameisdebian>
If I call the child script from the parent, won't the parent still take a long time to finish, and I'll still get the timeout error?
<SeepingN>
not if you fire in the background. non-blocking.
wildtrees has joined #ruby
<SeepingN>
system “#{RAILS_ROOT}/script/runner Project.my_method >/dev/null 2>&1
<SeepingN>
&”
<rubydoc>
parser error at position 0 around `”'
<havenwood>
SeepingN: smart quotes?
rippa has quit [Quit: {#`%${%&`+'${`%&NO CARRIER]
s2013 has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
<mynameisdebian>
SleepingN, I just want to make sure because I am almost sleeping myself, is there any reason this solution would not work on Ruby without Rails?
akem-hp_ has joined #ruby
akem-hp has quit [Ping timeout: 245 seconds]
<havenwood>
mynameisdebian: Forking from the CGI process to do the background work should suffice.
<havenwood>
mynameisdebian: It's certainly popular to use Rack for such things.
<havenwood>
mynameisdebian: Rails is one of many Rack frameworks, but you don't need to use a framework with Rack at all.
<SeepingN>
never knew what you wanted could get some complicated, eh
<havenwood>
or just fork :P
ukd1 has quit [Ping timeout: 244 seconds]
ukd1 has joined #ruby
<mynameisdebian>
havenwood, I just need a way to send the 200 response and still run some code. Having a second script seems ok, but I'm trying to understand rack. Do you have a second to kind of explain those short examples on that page for me?
<havenwood>
mynameisdebian: In CGI, by forking from your process or sending a task to a worker queue you can let the CGI script spin down so Apache sends the response.
<havenwood>
mynameisdebian: Rack is an alternative, where you run a more sophisticated Ruby webserver that stays up between requests, unlike GCI which spins up a fresh Ruby process for each request.
<havenwood>
mynameisdebian: By convention, you launch a Rack app from a config.ru file.
<havenwood>
mynameisdebian: This line, for example, creates a simple Rack app in a single config.ru file:
<havenwood>
mynameisdebian: You can then run that ^ app with the command: rackup
<havenwood>
mynameisdebian: Just install Rack, and usually you'll also want to install a Rack webserver like Puma too, rather than using the default.
<havenwood>
mynameisdebian: gem install rack puma
<havenwood>
mynameisdebian: Try creating that ^ config.ru, and running it with: rack
<havenwood>
mynameisdebian: The `200` is the response code.
<havenwood>
mynameisdebian: The empty Hash `{}` is for any Headers you want to set.
<havenwood>
mynameisdebian: And the third argument is the body of the response.
<havenwood>
mynameisdebian: You could spin up a thread, fork, use a worker queue, etc. to do some background work.
<havenwood>
mynameisdebian: Does that make any sense? I'd suggest just playing with Rack a bit to get a feel for a simple Rack app.
<mynameisdebian>
Does the Rack app contain the other code I want to run?
<havenwood>
mynameisdebian: Yes, you can trigger that other code running from your Rack app. If you find you want to respond to more than one verb, routes, etc, consider using Roda on top of Rack: http://roda.jeremyevans.net/
<havenwood>
mynameisdebian: It add a routing tree, for easy routing, and optional plugins.
<mynameisdebian>
so, all I'm doing here is receiving a JSON message from Slack and responding with 200 OK, then taking information from that message and using it to place a call to another API. That API returns some data that is used to generate a Slack-formatted message, and then that message is posted back to a Slack endpoint
<havenwood>
mynameisdebian: Here's an example of a Rack app that responds to all requests with 200 immediately, then five seconds laters logs "did work!":
<havenwood>
mynameisdebian: Run ^ that config.ru file with: rackup
<havenwood>
mynameisdebian: Try it in the browser at: localhost:9292
<havenwood>
mynameisdebian: You'll see an immediate response, then five seconds later a log entry.
<havenwood>
mynameisdebian: Try doing the same with Roda.
<havenwood>
mynameisdebian: gem install roda
<havenwood>
mynameisdebian: It'll handle a ton more requests than CGI, fwiw.
<havenwood>
mynameisdebian: If you see a config.ru file, you've spotted a Rack app.
<havenwood>
mynameisdebian: Rails, Sinatra, Hanami, Roda, etc will all have a config.ru (Rack Up) file.
ukd1 has quit [Ping timeout: 272 seconds]
<havenwood>
The default Rack webserver for Rails is Puma.
<havenwood>
I
<mynameisdebian>
havenwood, I'm confusing myself a little bit here. In this scenario is my Apache server still running on the server, serving the config.ru file?
<havenwood>
I'd recommend Puma as a solid choice for whatever Rack app you're using.
<havenwood>
mynameisdebian: You could serve Puma straight up on port 80, or 443, or you could reverse proxy from Apache to the port or socket that Puma is running on.
<havenwood>
mynameisdebian: It's a very common setup to reverse proxy from Apache to Puma.
<havenwood>
mynameisdebian: Puma is a more mainstream webserver.
<havenwood>
mynameisdebian: You can swap a Rack app's webserver very easily between Puma, Passenger, Unicorn, Falcon, etc.
<mynameisdebian>
It's a company webserver and I have to go through some admins to get anything done. I'm thinking it might be less complex in this case to have first script return 200 and make a system call to the other
<havenwood>
mynameisdebian: There are a bunch of battle tested, high quality web server options.
<mynameisdebian>
havenwood, I appreciate your time
<mynameisdebian>
I'm going to re-read what you said and try to get a better grasp of it later on
<havenwood>
mynameisdebian: please come back and inquire further if things come up
<havenwood>
mynameisdebian: good luck!
<mynameisdebian>
havenwood, thank you
phenom has quit [Ping timeout: 248 seconds]
morenoh149 has quit [Ping timeout: 258 seconds]
mynameisdebian has quit [Ping timeout: 248 seconds]
morenoh149 has joined #ruby
lucasb has quit [Quit: Connection closed for inactivity]
sylario has quit [Quit: Connection closed for inactivity]
cyclonis has joined #ruby
phenom has joined #ruby
duderonomy has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]