malconis has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
snsei has joined #ruby-lang
Rayford has joined #ruby-lang
Musashi007 has quit [Quit: Musashi007]
waxjar has joined #ruby-lang
snsei has quit [Ping timeout: 255 seconds]
jacecore has quit [Read error: Connection reset by peer]
rubert has joined #ruby-lang
<rubert>
Hi, I have am new to Ruby and in need of advice. I defined some methods and instance variables in a gem using class << self, thinking it would add the instance variables to main's singleton class. When I try to use those methods in a Sinatra Route, or a class, it can't find the methods. I was under the impression that when a class can't find a meth
symm- has joined #ruby-lang
<rubert>
od, it asks its ancestor if it responds to said method. Would that not be main? How can I get the functionality I want?
SylarRuby has quit [Remote host closed the connection]
<jhass>
add them to Kernel
<jhass>
Kernel is the place where "global" methods reside
revath has quit [Ping timeout: 256 seconds]
<jhass>
to make it a bit cleaner include a module with your methods into Kernel
nathanstitt has quit [Quit: I growing sleepy]
<jhass>
though I'd ponder if MyGem.method instead of method is really that much of a pain
<jhass>
also check Moudle#module_function
<rubert>
Ok, thanks! I am considering just using a class, but I was trying to go for a DSL approach just for fun.
snsei has joined #ruby-lang
revath has joined #ruby-lang
<jhass>
DSLs usually are realized via instance_eval
<jhass>
MyGem.fancy do fany_a; fancy_b; end;
jwaldrip has quit [Quit: Be back later ...]
<jhass>
stuff like that
snsei has quit [Remote host closed the connection]
hahuang65 has quit [Ping timeout: 264 seconds]
my0373 has quit []
baweaver has quit [Remote host closed the connection]
<pipework>
mmm instance eval
<pipework>
Parsers are cooler, but blocks are fun.
baweaver has joined #ruby-lang
wallerdev has quit [Quit: wallerdev]
baweaver has quit [Ping timeout: 256 seconds]
snsei has joined #ruby-lang
snsei has quit [Remote host closed the connection]
marr has quit []
sferik has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jo__ has joined #ruby-lang
snsei has joined #ruby-lang
amclain has joined #ruby-lang
Rayford has quit [Quit: Rayford]
sferik has joined #ruby-lang
snsei has quit [Remote host closed the connection]
riotjone_ has joined #ruby-lang
djellemah_ has joined #ruby-lang
wallerdev has joined #ruby-lang
bruno- has quit [Ping timeout: 264 seconds]
snsei has joined #ruby-lang
martinbmadsen has joined #ruby-lang
djellemah__ has quit [Ping timeout: 256 seconds]
riotjone_ has quit [Ping timeout: 252 seconds]
snsei has quit [Remote host closed the connection]
fusillicode1 has quit [Read error: No route to host]
fusillicode1 has joined #ruby-lang
fusillicode has quit [Ping timeout: 255 seconds]
leat has joined #ruby-lang
revath has joined #ruby-lang
martinbmadsen has joined #ruby-lang
SylarRuby has quit [Remote host closed the connection]
leat has quit [Remote host closed the connection]
GBrawl has joined #ruby-lang
martinbmadsen has quit [Ping timeout: 264 seconds]
solars has joined #ruby-lang
anekant has quit [Ping timeout: 252 seconds]
SylarRuby has joined #ruby-lang
sferik_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
leat has joined #ruby-lang
the_real_intinig has joined #ruby-lang
leat has quit [Ping timeout: 252 seconds]
iamninja has quit [Read error: Connection reset by peer]
iamninja has joined #ruby-lang
fusillicode1 has quit [Quit: Leaving.]
fusillicode has joined #ruby-lang
the_real_intinig has quit [Remote host closed the connection]
leat has joined #ruby-lang
revath has quit [Read error: Connection reset by peer]
fusillicode1 has joined #ruby-lang
bruno- has joined #ruby-lang
fusillicode has quit [Ping timeout: 264 seconds]
leat has quit [Ping timeout: 250 seconds]
the_real_intinig has joined #ruby-lang
bruno- has quit [Ping timeout: 255 seconds]
leat has joined #ruby-lang
SylarRuby has quit [Remote host closed the connection]
the_real_intinig has quit [Remote host closed the connection]
caseypatrickdris has quit [Remote host closed the connection]
caseypatrickdris has joined #ruby-lang
SylarRuby has joined #ruby-lang
riotjone_ has joined #ruby-lang
SylarRuby has quit [Ping timeout: 244 seconds]
revath has joined #ruby-lang
riotjone_ has quit [Ping timeout: 264 seconds]
ledestin has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
atmosfeer has joined #ruby-lang
Versality has joined #ruby-lang
nofxx has quit [Ping timeout: 250 seconds]
<atmosfeer>
Hey everyone, I'm in my second week of coding Ruby and I'm trying to code a little program that will fetch recipes online with nokogiri, but I can't get it to work. Here's the code that won't do what I want it to: https://gist.github.com/atmosfeer/21704db6ea09e35c4115
relix_ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
the_real_intinig has joined #ruby-lang
<atmosfeer>
Why do I get an error message using that code? It says "No such file or directory @ rb_sysopen" at the URL I want to parse...
the_real_intinig has quit [Remote host closed the connection]
<Versality>
I think it's due to this: Nokogiri::HTML(File.open("http:
<Versality>
you're trying to open up URI with File.open
<atmosfeer>
Versality: Thank you! I copy pasted some earlier code where I was opening a local html file just to test it out. Thank you so much
mikecmpbll has joined #ruby-lang
Mon_Ouie has quit [Quit: WeeChat 1.1.1]
relix has joined #ruby-lang
caseypatrickdris has quit [Ping timeout: 265 seconds]
sferik has joined #ruby-lang
yfeldblu_ has quit [Quit: Leaving...]
bruno- has joined #ruby-lang
leat has quit [Read error: Connection reset by peer]
nofxx has joined #ruby-lang
nofxx has joined #ruby-lang
bruno- has quit [Ping timeout: 264 seconds]
the_real_intinig has joined #ruby-lang
revath has quit [Ping timeout: 252 seconds]
CatMartyn has joined #ruby-lang
sferik has quit [Read error: Connection reset by peer]
the_real_intinig has quit [Remote host closed the connection]
sferik has joined #ruby-lang
leat has joined #ruby-lang
anekant has joined #ruby-lang
symm- has joined #ruby-lang
the_real_intinig has joined #ruby-lang
bruno- has joined #ruby-lang
<atmosfeer>
I have another problem with Nokogiri. I need to iterate over each content tagged with the css class "m_contenu_resultat" but sometimes that content doesn't include the css content I'm actually after, which is nested inside it. How do I skip those cases in my iteration? https://gist.github.com/atmosfeer/ae5e3861a04984045194
cornerma1 has joined #ruby-lang
sankaber has joined #ruby-lang
leat has quit [Ping timeout: 250 seconds]
<atmosfeer>
It gives me an undefined method error when it doesn't find "m_titre_resultat" class content inside the "m_contenu_resultat"
leat has joined #ruby-lang
marr has joined #ruby-lang
cornerman has quit [Ping timeout: 252 seconds]
cornerma1 is now known as cornerman
SylarRuby has joined #ruby-lang
ghostpl_ has joined #ruby-lang
the_real_intinig has quit [Remote host closed the connection]
<atmosfeer>
jhass: undefined method `[]' for nil:NilClass. Basically it's trying to push something that doesn't exist into my array recipe_parameters
<jhass>
so that's line 31?
<jhass>
er 33
<atmosfeer>
yes 33
<jhass>
so your regex doesn't match in these cases
<atmosfeer>
exactly
<jhass>
String#match returns nil if there's no match
<jhass>
so you just need to fix the regexp to match these cases or skip (like you already do on 26) if match_data is nil
<jhass>
or maybe those cases have something in common and you can improve your selector to not include them
caseypatrickdris has joined #ruby-lang
<atmosfeer>
jhass: well the cases are, that with my "m_contenu_resultat" there is none of the subcategories I'm after. But I spent an hour looking through the Nokogiri doc and I can't figure it out
anekant has quit [Ping timeout: 252 seconds]
<atmosfeer>
jhass: I find the Nokogiri syntax very confusing still...
waxjar has quit [Ping timeout: 265 seconds]
<jhass>
well, it takes plain css or xpath selectors
apt-get_ has joined #ruby-lang
<jhass>
all you know about these you can apply
<atmosfeer>
But how can I just include a css class that includes another css class, and none of the others?
leat has quit [Ping timeout: 256 seconds]
sarkyniin has quit [Ping timeout: 245 seconds]
leat has joined #ruby-lang
<atmosfeer>
jhass can I use xpath on an html document or only on an xml document?
<jhass>
you can use xpath on an html document and css on an xml document
havenwood has quit [Remote host closed the connection]
<jhass>
looks like CSS4 will have :has(), but it's nowhere implemented yet
<jhass>
with xpath you can do something like "//*[@class='m_titre_resultat']/a/.."
<jhass>
it gets tricky if you have multiple classes on an element though
<jhass>
since xpath only matches the whole attribute content
the_real_intinig has joined #ruby-lang
<atmosfeer>
jhass: Hmmm okay. how do I make my next if work in the iteration then? As it is in the code I uploaded it just skips through the whole thing. I tried calling .empty? and .nil? on element.search('.m_titre_resultat > a') to no avail...
<jhass>
.empty? should work
<jhass>
atmosfeer: do you know pry?
<atmosfeer>
jhass: no what is that?
sankaber has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
<hakunin>
the_other_benn: if you put a magic method "module_function" at the top of module, all methods in it can be used directly Foo.some_metohd
revath has quit [Ping timeout: 256 seconds]
<hakunin>
this is not a very good programming practice in general, and if you're dealing with state in multithreaded environment - it only gets worse
<the_other_benn>
OK, so why would adding a mutex to the module ("Helper Class") be complex?
<hakunin>
the_other_benn: it sounds complex, but you haven't really explained what you're doing
<the_other_benn>
I'm creating a small lib for short url generation
<hakunin>
sounds simple enough
<the_other_benn>
the short url is an active record (model).
<the_other_benn>
and I'm creating a module named Shorty, which helps me generate the ShortUrl instances
<hakunin>
not sure where the need for mutex comes in
ur5us has quit [Ping timeout: 272 seconds]
<the_other_benn>
the short url consists of an hash and a long url. the hash is generated from a unique number (in my case the ShortUrl db size or ShortUrl.count)
<hakunin>
why not generate hash from long url
<the_other_benn>
Since I would like this to be able to handle many requests, I would like the ShortUrl.count (for hash generation) & the ShortUrl.save to be synchronized
leat has quit [Ping timeout: 252 seconds]
<the_other_benn>
since hash would not be necceserly unique
<the_other_benn>
the url_hash is actually a conversion of the Integer to Base51
<the_other_benn>
which promises uniqueness (might grow with time, but still unique)
leat has joined #ruby-lang
<hakunin>
that seems highly inefficient, you would only be able to shorten 1 url at a time, if you run 2 apps in parallel - you're still colliding
vipaca has joined #ruby-lang
<hakunin>
.count is very heavy and unreliable approach
<the_other_benn>
I would not be colliding of the ShortUrl.count and ShortUrl.save would happen in a single transaction which is protected by mutex
<the_other_benn>
of = if
<hakunin>
not if you run 2 servers, or 2 forked apps
<hakunin>
sharing a database
<the_other_benn>
ahh, it is intended to be a single process
<hakunin>
count can also go up and down
<hakunin>
so with count you get more headaches than it's worth
<the_other_benn>
it could, but lets assume it wouldn't
<the_other_benn>
OK
<the_other_benn>
how would you go about this problem?
<the_other_benn>
without hash that is.
<hakunin>
there are many ways to create unique numbers or strings
<hakunin>
SecureRandom.hex is one of them
<hakunin>
built into ruby
<hakunin>
that's what gist.github.com uses for their urls
<hakunin>
it has a chance of collision, but you can create a db constraint for hash uniqueness, and it would raise an error on collision, which you can rescue and retry (would probably never happen though)
<the_other_benn>
don't see it takes a string as an input
hhatch has quit [Ping timeout: 264 seconds]
<hakunin>
it's not a hashing function
<hakunin>
it generates unique random strings
<hakunin>
out of nothing
<the_other_benn>
ok
<the_other_benn>
fair enough
<the_other_benn>
I'll go with that approach
<the_other_benn>
Thanks for the help/guidence
<the_other_benn>
:>
<hakunin>
np
ur5us has joined #ruby-lang
ur5us_ has joined #ruby-lang
havenwood has quit [Remote host closed the connection]
micmus has quit [Ping timeout: 246 seconds]
ledestin has joined #ruby-lang
<yorickpeterse>
brrrrr, Windows
<yorickpeterse>
granted, if I can get AppVeyor to run my stuff that would be pretty neat
ur5us has quit [Ping timeout: 264 seconds]
<hakunin>
ruby's Struct is written in C, which makes it officially bad idea to inherit from
<hakunin>
i guess
<centrx>
huh?
<yorickpeterse>
anybody here on windows _and_ has the 7zip CLI utility installed?
<yorickpeterse>
derp my engrish
<centrx>
How about a Windows VM with the 7zip GUI installed?
<yorickpeterse>
Hm, I need the CLI since apparently I'm doing it wrong
<yorickpeterse>
trying to get appveyor to run but it gives me this helpful error "Incorrect commandline"
vipaca has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<yorickpeterse>
which is either the download command, or the 7zip command
<yorickpeterse>
(the latter being "7z e C:\ragel.7z -o C:\ragel -y")
caseypatrickdris has quit [Remote host closed the connection]
jamo__ has quit [Quit: leaving]
<centrx>
I get the same output
<centrx>
Incorrect commandline
micmus has joined #ruby-lang
<yorickpeterse>
wtf
<centrx>
ok got it
caseypatrickdris has joined #ruby-lang
<centrx>
yorickpeterse, yorickpeterse, The directory after the -o has to be right next to the -o no space
<yorickpeterse>
srsly
<yorickpeterse>
well, lets see what appveyor has to say about that
sankaber has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
<yorickpeterse>
centrx: sweet, that worked
<yorickpeterse>
now onto the next problem
<centrx>
sweet
<yorickpeterse>
centrx: also, is there an option to supress output?
* yorickpeterse
is crowdsourcing 7z --help
<yorickpeterse>
"Everything is Ok" ha don't lie 7zip
<centrx>
Doesn't look like it
<centrx>
There is -bd for "Disable percentage indicator"
<centrx>
and -so for "write data to stdout", which would presumably disable other output
<yorickpeterse>
hm
<yorickpeterse>
also bah, seems this archive it downloads is a directory in a directory
malconis has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
malconis has joined #ruby-lang
centrx has quit [Remote host closed the connection]
centrx has joined #ruby-lang
JamesDH has joined #ruby-lang
Forgetful_Lion has joined #ruby-lang
sankaber has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
wprice has quit [Quit: wprice]
oshosurya has quit [Quit: Page closed]
martinbmadsen has joined #ruby-lang
dellavg_ has quit [Ping timeout: 264 seconds]
ffmegaman has joined #ruby-lang
guillaume-rb has quit [Quit: guillaume-rb]
fumduq has quit [Ping timeout: 252 seconds]
fumduq has joined #ruby-lang
hiFriends has joined #ruby-lang
JamesDH has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
arooni-mobile has quit [Ping timeout: 246 seconds]
<hiFriends>
Hi, Im trying to have the outcome be a .pdf file that I can print or email. Does anyone know of any good pdf generating libraries? I see 3 ways of doing this. 1. create my own pdf and have the program fill it out and save it, 2. have the output of a saved form be a pdf, or 3. fill out a pre existing pdf and save. Im not too sure on the best way to do this. any ideas?