<ruby-lang438>
im not sure what im supposed to do with the .each and puts in the second part
<enders>
You are supposed to add a new choice, "display", and in that, iterate over all the key (film name), values (rating) and puts a string made of that film name and rating.
<enders>
The iterate over can be done with .each on the hash of movies
<ruby-lang438>
thats what i dont understand, how do i .each on the hash of movies
<ruby-lang438>
and add a new choice "display" is that creating a new case?
<enders>
hash.each do |key, value| ...do something with key, value or both... end
<ruby-lang438>
i am a beginner so if i am asking the question wrong i apologize
<enders>
Yes
<ruby-lang438>
movies.each ?
<ruby-lang438>
also the |key, value| how do i know what they are?
riotjones has joined #ruby-lang
yfeldblum has quit [Read error: Connection reset by peer]
yfeldblum has joined #ruby-lang
<enders>
.each is a method that can be used on any Enumerable object, so here, a Hash, it'll iterate over each 'element' in the Enumerable. In the case of a Hash, like 'movies', each element is composed of a key and a value, the block that you give to each will receive those two parameters, in that order, that's just part of how Hash are working.
<enders>
You could call them just k,v, it doesn't matter, those are just parameter names of the 'function' you give to the .each (the function to perform for every element in the hash)
<enders>
.each will make sure to call your block with the correct values put in 'key' and 'value', so for instance, in your code, it'll call your block 3 times, the first time key == "pulp_fiction" and value == 3
<enders>
So to make it clearer, you can do movies.each do |movie, rating| .... do something with movie/rating ... end
sarkyniin has quit [Remote host closed the connection]
<ruby-lang438>
ok so movies.each repeats through all 3 values in my hash? and the |key,value| are dependent on what input is given?
<enders>
I'm not sure what you mean by 'what input is given'
<ruby-lang438>
input given would be the movie names and the ratings they are given ?
<ruby-lang438>
where do i put the new code? movies.each im always unsure where to place it
<enders>
That'd be within your new case statement, for 'display' command
riotjones has quit [Ping timeout: 250 seconds]
<ruby-lang438>
when "display"
<ruby-lang438>
movies.each |key,value|
<ruby-lang438>
in the instructions what is the format it wants me to use? "The format should be "#{movie}: #{rating}. Make sure to test it out!"
<ruby-lang438>
am i creating a second hash for the rating?
<enders>
No, the rating is already in the movies hash
tcopeland has joined #ruby-lang
<enders>
movies is a Hash, which for each key (the movie name), contain a value (the rating), it's not an Array (which would be a simple list of movies)
micmus has quit [Ping timeout: 255 seconds]
<enders>
By "format" they just mean that in your console output, you should see pulp_fiction: 3
<ruby-lang438>
so after movies.each |key,value| I need a "puts" |key,value| ?
ur5us has joined #ruby-lang
<enders>
Yes, you need to do something with key and value, those are two variables, |key,value| is just a special syntax for parameters of a block 'function'
<ruby-lang438>
would i just "puts" movies.each ?
<enders>
No, puts take a string to display in the console for the user to see, movies.each doesn't generate a string, it just iterates over the element of the hash.
<ruby-lang438>
"puts" key ?
<ruby-lang438>
"puts" value ?
<enders>
That'd display two lines, one with the movie title, one with the rating, that's not what they want. They want one line per movie, showing both the name and the rating.
<ruby-lang438>
"puts" key, value ?
apeiros__ is now known as apeiros_
<enders>
That is the same, it'd still display two lines. Try it in irb, type puts 1,2 and it'll show them on two lines.
<ruby-lang438>
irb?
<Senjai>
Interactive ruby
<Senjai>
>> puts 1,2
<enders>
Ruby Interactive Shell, you can start it from a command line if you installed ruby correctly on your machine, it allows you to just type in some ruby and it'll get executed right away.
<Senjai>
>> puts "Executing stuff from IRC to answer questions helps sometimes."
<eval-in>
Senjai => Executing stuff from IRC to answer questions helps sometimes. ... (https://eval.in/292072)
fujimura has joined #ruby-lang
<enders>
Hey Senjai, do you happen to have any idea how I could profile some C++ gem? I have made progress on my graph things from Friday, and now I have a big mess of steamy C++ that performs 1.3x slower than Ruby. I think that's some sort of achievement.
<ruby-lang438>
puts #{movies} #{ratings} ?
<Senjai>
You need to prefix it with >> for the bot to catch it. But you would probably want to practice in irb, unless your showing us something
<Senjai>
enders: :P
<Senjai>
enders: indeed
<enders>
That'd be closer, if you put quotes around your string and change the variable names to what they should be based (movies here would be like the whole hash with all the movies and all the ratings, not something you want in a string)
<Senjai>
enders: Also could consider getting code review from ##c++
<enders>
Yeah, I have tried Valgrind with callgrind, but unfortunately, MRI seems to hiding all the of the C++ goodness somewhere and Valgrind just output an empty call graph, it's weird. Same thing with seg fault, MRI seems to catch them all before Valgrind can do its magic.
fujimura has quit [Ping timeout: 264 seconds]
<Senjai>
MRI isn't written in C++
<Senjai>
You can also compile MRI for debugging
<darix>
rubinius is c++
jbeeze has quit [Remote host closed the connection]
<enders>
I'm not sure how the language of the interpreter would affect the profiling of a gem anyway
<enders>
I guess the easiest would be to just set up a standalone c++ program that use the same code and then from there, it's smooth sail
<weaksauce>
enders you can gist it and i'll take a look
hendranata_ has quit [Remote host closed the connection]
<weaksauce>
is there anyway you can do the processing asynchronously in a background queue?
saramic has quit [Remote host closed the connection]
<enders>
It may have to come to this someday, but currently, we aren't ready for that massive rewrite. The computation result will change everyday, at least, and everytime one of the many settings is updated.
<weaksauce>
I haven't done a thorough analysis but one thing I could imagine helping is having an object pool that you use instead of creating and destroying objects all the time.
<weaksauce>
not the easiest thing to build reliably though
deol has joined #ruby-lang
<enders>
Are you talking about all the temporary dates?
fujimura has joined #ruby-lang
<enders>
I must be missing something obvious tho, this code (the part that I pasted) is slower than its ruby counterpart, and it's not even doing everything the ruby version is doing yet.
ghostpl_ has joined #ruby-lang
<weaksauce>
put some print statements inside the destructor of checkpoint and see how many times that's being called
<weaksauce>
seems like that's an expensive object to create
<weaksauce>
btw. you can add files to the gist so you don't have to have one long file there
pwnz0r has joined #ruby-lang
fujimura has quit [Ping timeout: 264 seconds]
ur5us has quit [Ping timeout: 256 seconds]
ghostpl_ has quit [Ping timeout: 240 seconds]
<enders>
Cool, I have updated the gist. For Checkpoint, it's heavy, but the array of Checkpoints (the workflow) is only created l102 of process.cpp and deleted once l111 of the same file. The only 'heavy' objects that I keep creating on the stacks are the boost::gregorian::date. Many of those could be memoized, but it's sad considering that I didn't even need to do it in ruby!
elia has quit [Quit: Computer has gone to sleep.]
hendranata_ has joined #ruby-lang
meschi has quit [Ping timeout: 252 seconds]
fuhgeddaboudit has joined #ruby-lang
ur5us has joined #ruby-lang
duderonomy has joined #ruby-lang
marr has quit []
Senjai has quit [Changing host]
Senjai has joined #ruby-lang
seank__ has quit [Read error: Connection reset by peer]
<Senjai>
weaksauce: <3
<weaksauce>
:)
seank_ has joined #ruby-lang
<weaksauce>
enders I don't know but I suspect that the boost library for dates is heavy
<enders>
My guess as well, currently writing a standalone full C++ version so I can use the normal profiling tools on C++ and I'll get to the bottom of this. Thanks for the help and ideas! I'll report back for posterity if I find anything interesting.
<Senjai>
weaksauce: That quote is almost bash.org worthy :P
pwnz0r has quit [Remote host closed the connection]
pwnz0r has joined #ruby-lang
duderonomy has joined #ruby-lang
pancho has joined #ruby-lang
<pancho>
Hi!
pwnz0r has quit [Ping timeout: 265 seconds]
shinnya has quit [Ping timeout: 240 seconds]
sideshowcoder has quit [Ping timeout: 246 seconds]
fujimura has quit [Remote host closed the connection]
sideshowcoder has joined #ruby-lang
pancho has quit [Ping timeout: 246 seconds]
tvon has quit [Quit: leaving]
michael_mbp has quit [Excess Flood]
allomov has quit [Remote host closed the connection]
michael_mbp has joined #ruby-lang
allomov has joined #ruby-lang
sankaber has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
ledestin has quit [Quit: ledestin]
allomov has quit [Ping timeout: 240 seconds]
chouhoulis has joined #ruby-lang
apeiros_ has quit [Remote host closed the connection]
apeiros_ has joined #ruby-lang
allomov has joined #ruby-lang
djbkd_ has joined #ruby-lang
Miphix has joined #ruby-lang
djbkd_ has quit [Ping timeout: 250 seconds]
j4cknewt has quit [Remote host closed the connection]
slawrence00 has joined #ruby-lang
saramic_ has joined #ruby-lang
saramic has quit [Read error: Connection reset by peer]
red_menace has quit [Quit: leaving...]
ghostpl_ has joined #ruby-lang
ghostpl_ has quit [Ping timeout: 246 seconds]
oliver___ has joined #ruby-lang
oliver___ has quit [Ping timeout: 252 seconds]
arooni-mobile has quit [Ping timeout: 244 seconds]
chouhoulis has quit [Remote host closed the connection]
michael_mbp has quit [Excess Flood]
michael_mbp has joined #ruby-lang
fujimura has joined #ruby-lang
saramic has joined #ruby-lang
ur5us_ has joined #ruby-lang
saramic_ has quit [Ping timeout: 252 seconds]
fujimura has quit [Ping timeout: 256 seconds]
ur5us has quit [Ping timeout: 264 seconds]
caseydriscoll has quit [Remote host closed the connection]
tunaCanBruh has joined #ruby-lang
kapil___ has joined #ruby-lang
pwnz0r has joined #ruby-lang
michael_mbp has quit [Excess Flood]
tunaCanBruh has quit [Ping timeout: 265 seconds]
michael_mbp has joined #ruby-lang
ur5us_ has quit [Ping timeout: 240 seconds]
allomov has quit [Remote host closed the connection]
arooni-mobile has joined #ruby-lang
ur5us has joined #ruby-lang
pepperbreath has joined #ruby-lang
tkuchiki_ has joined #ruby-lang
tkuchiki has quit [Ping timeout: 245 seconds]
saramic has quit [Ping timeout: 240 seconds]
havenn has quit []
gix has quit [Ping timeout: 245 seconds]
mattyohe has quit [Quit: Connection closed for inactivity]
riotjones has joined #ruby-lang
JoshuaPaling has joined #ruby-lang
gix has joined #ruby-lang
arooni-mobile has quit [Ping timeout: 246 seconds]
riotjones has quit [Ping timeout: 245 seconds]
mcclurmc has joined #ruby-lang
<enders>
For those who were there earlier, I have solved the performances issue, most of it was due to a single rb_funcall in a loop from C-land, at the end of the processing, to copy back the result of the processing. I replaced it by a new ruby array built in C that I return to ruby land, and then I do the loop from there, and just like magic, I went from a C++ code being 1.3x slower than ruby to a C++ code being 35x time faster (the
<enders>
time include the time in ruby land to process the array, obviously).
yfeldblum has quit [Remote host closed the connection]
pepperbreath has quit [Quit: Leaving.]
nathanstitt has quit [Quit: I growing sleepy]
pepperbreath has joined #ruby-lang
kyb3r_ has joined #ruby-lang
Respek has quit [Quit: gone to sleep. ZZZzzz…]
chouhoulis has joined #ruby-lang
caseydriscoll has joined #ruby-lang
Respek has joined #ruby-lang
chouhoulis has quit [Ping timeout: 256 seconds]
fuhgeddaboudit has quit [Ping timeout: 252 seconds]
caseydriscoll has quit [Ping timeout: 265 seconds]
tdy has quit [Ping timeout: 246 seconds]
enders has quit [Read error: Connection reset by peer]
tkuchiki has joined #ruby-lang
Bwild has joined #ruby-lang
tkuchiki_ has quit [Ping timeout: 244 seconds]
<weaksauce>
jesus. congrats enkristoffer
<weaksauce>
er. enders :(
ghostpl_ has joined #ruby-lang
micmus has joined #ruby-lang
ghostpl_ has quit [Ping timeout: 250 seconds]
micmus has quit [Quit: Leaving]
Manj-811-Xfce has joined #ruby-lang
Manj-811-Xfce is now known as redneo
redneo has quit [Client Quit]
AKASkip has joined #ruby-lang
yfeldblum has joined #ruby-lang
ur5us has quit [Ping timeout: 244 seconds]
pwnz0r has quit [Remote host closed the connection]
pwnz0r has joined #ruby-lang
pwnz0r has quit [Ping timeout: 265 seconds]
toretore has quit [Ping timeout: 245 seconds]
ur5us has joined #ruby-lang
yfeldblu_ has joined #ruby-lang
yfeldblum has quit [Ping timeout: 264 seconds]
tunaCanBruh has joined #ruby-lang
tunaCanBruh has quit [Ping timeout: 255 seconds]
mcclurmc has quit [Remote host closed the connection]
michael_mbp has quit [Excess Flood]
michael_mbp has joined #ruby-lang
ur5us has quit [Ping timeout: 256 seconds]
djbkd_ has joined #ruby-lang
slawrence00 has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
riotjones has joined #ruby-lang
maso has joined #ruby-lang
riotjones has quit [Ping timeout: 250 seconds]
j4cknewt has joined #ruby-lang
Miphix has quit [Quit: Leaving]
tvon has joined #ruby-lang
ghostpl_ has joined #ruby-lang
j4cknewt has quit [Remote host closed the connection]
mnilsson has joined #ruby-lang
michael_mbp has quit [Excess Flood]
ghostpl_ has quit [Ping timeout: 256 seconds]
michael_mbp has joined #ruby-lang
mnilsson has quit [Read error: Connection reset by peer]
mnilsson has joined #ruby-lang
djbkd_ has quit [Remote host closed the connection]
jo__ has quit [Quit: Connection closed for inactivity]
postmodern has joined #ruby-lang
igalic has quit [Ping timeout: 255 seconds]
ruby-lang438 has quit [Quit: Page closed]
Respek has quit [Quit: gone to sleep. ZZZzzz…]
riotjones has joined #ruby-lang
rippa has joined #ruby-lang
Mon_Ouie has quit [Ping timeout: 245 seconds]
riotjones has quit [Ping timeout: 250 seconds]
j4cknewt has joined #ruby-lang
tunaCanBruh has joined #ruby-lang
tunaCanBruh has quit [Ping timeout: 255 seconds]
icharlie has quit []
riotjones has joined #ruby-lang
lytol has joined #ruby-lang
ottlikg has joined #ruby-lang
lytol has quit [Ping timeout: 265 seconds]
toretore has joined #ruby-lang
Averna has quit [Quit: Leaving.]
vondruch has quit [Ping timeout: 256 seconds]
djbkd_ has joined #ruby-lang
allomov has joined #ruby-lang
mnilsson has quit [Read error: Connection reset by peer]
djbkd_ has quit [Remote host closed the connection]
allomov has quit [Ping timeout: 264 seconds]
mkaesz has joined #ruby-lang
vondruch has joined #ruby-lang
solars has joined #ruby-lang
martinbmadsen has joined #ruby-lang
ghostpl_ has joined #ruby-lang
martinbmadsen has quit [Quit: leaving]
martinbmadsen has joined #ruby-lang
charliesome has quit [Quit: zzz]
ghostpl_ has quit [Ping timeout: 245 seconds]
martinbmadsen is now known as fapper
maso has quit [Remote host closed the connection]
JoshuaPaling has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
ta_ has quit [Remote host closed the connection]
kyb3r_ has quit [Read error: Connection reset by peer]
<Eising>
For some reason I failed my encodings on the old version of my app
<Eising>
so now I have one table in my db where encoding is iso-8859-1'ish
<Eising>
where the rest is wtf-8
<jhass>
wtf-8, mmh, I have to try that one out some time
<Eising>
you know what I mean :)
fujimura has joined #ruby-lang
<jhass>
anyway, CHANGE ENCODING 'UTF-8' and be happy!
<jhass>
okay, I actually have no idea whether that converts :P
terabytest has joined #ruby-lang
<Eising>
sheesh, I can't win, I think
intinig has quit [Remote host closed the connection]
<Eising>
nobody is winning when it comes to character encodings
intinig has joined #ruby-lang
<jhass>
especially when you're using MySQL
<Eising>
mhmm
<jhass>
they managed to name the UTF-8 one utf8mb4
<jhass>
utf8 is something else
intinig has quit [Remote host closed the connection]
<Eising>
it's not that important to fix the table. The key thing is to convert it in the small migration module I'm doing in the new version of the app
intinig has joined #ruby-lang
terabytest has left #ruby-lang [#ruby-lang]
<apeiros>
ah, their utf-8 is the one which can't really use all sequences?
<jhass>
yeah, only supports 3 bytes
<apeiros>
that's so mysql…
<jhass>
so things like the unicode 7 emojis fall out
j4cknewt has joined #ruby-lang
<jhass>
want to know my suspicion as to why they did that?
arBmind has quit [Quit: Leaving.]
<apeiros>
sure
tcopeland has joined #ruby-lang
<jhass>
MyISAM and (even InnoDB default) maximum index key size is 767 bytes
Miphix has joined #ruby-lang
kr3ssh has joined #ruby-lang
<jhass>
VARCHAR default length is 255 characters
j4cknewt has quit [Ping timeout: 256 seconds]
sgambino has joined #ruby-lang
<Eising>
jeez, I shouldn't have touched my code today.
<apeiros>
you mean they wanted to ensure that a varchar could fit completely into the index?
<apeiros>
are you sure it's 255 chars and not 255 bytes?
<apeiros>
I know with oracle you can specify the size as either
<jhass>
yeah it's chars
<jhass>
and yeah, that's my suspicion
HANJIN has quit [Quit: HANJIN]
mnilsson has quit [Read error: Connection reset by peer]
<Eising>
what the actual... My app actually just decided to throw up on me
<Eising>
Things that have been stable, just faulting, without me even touching the code
arBmind has joined #ruby-lang
Miphix has quit [Ping timeout: 264 seconds]
<Eising>
not even a previous good commit works :/
<Eising>
must be my environment
mnilsson has joined #ruby-lang
<apeiros>
or the data in your db
<Eising>
undefined method `extension' for #<Sequel::Mysql2::Database:
shinnya has joined #ruby-lang
<Eising>
that doesn't seem data related
<Eising>
I compared the gem versions with my development docker, and they match
sarkyniin has joined #ruby-lang
<jhass>
using bundler?
<Eising>
yup
anekos has quit [Quit: Tiarra 0.1+svn-39036: SIGTERM received; exit]
<jhass>
and having the .lock in the repo?
<Eising>
yeah
<jhass>
and using bundle exec or ensured require "bundler/setup" is the first thing your app does?
<Eising>
require "bundler" is the second require (after rubygems), and Bundler.require runs before any other code
arBmind has quit [Quit: Leaving.]
anekos has joined #ruby-lang
<jhass>
require "rubygems" is implicitly done since Ruby 1.9, so you can drop it
<jhass>
try making require "bundler/setup" the first one
<Eising>
I also fear a sequel version mismatch, since debian apparently has a sequel installed also
<Eising>
bingo
<Eising>
that was the case
<Eising>
yeah, problem solved
<Eising>
*phew*
<Eising>
now back to the original UTF-8 problem...
<Eising>
I ought to deploy with docker also, and not only develop with it
skade has quit [Quit: Computer has gone to sleep.]
lapide_viridi has joined #ruby-lang
lapide_viridi has quit [Remote host closed the connection]
skade has joined #ruby-lang
Miphix has joined #ruby-lang
Xzanron has joined #ruby-lang
skade has quit [Client Quit]
Xzanron has quit [Client Quit]
Xzanron has joined #ruby-lang
momomomomo has joined #ruby-lang
enebo has joined #ruby-lang
sarkyniin has quit [Ping timeout: 246 seconds]
tkuchiki has joined #ruby-lang
ta has quit [Remote host closed the connection]
chouhoulis has joined #ruby-lang
chouhoulis has quit [Remote host closed the connection]
<Eising>
hmm, so the problem isn't that the encoding is wrong, it's apparently stored wrong
chouhoulis has joined #ruby-lang
<Eising>
as in "MÃ… IKKE TESTES!!!"
<Eising>
which is an invalid encoding Å
<Eising>
it's not iso8859-1. It's just utf-8 stored wrong
malconis has joined #ruby-lang
<jhass>
maybe it's utf-8 interpreted as iso8859-1 or the other way around?
<Eising>
I saw someone online calling it a multi-byte utf-8 charecter interpreted as a single-byte encoding
<momomomomo>
Eising: csv?
<Eising>
momomomomo: no, bad code, I think
<momomomomo>
that character is in the code?
<Eising>
no
<Eising>
that code came from a user input
<Eising>
err code = charecter
<Eising>
*character
<momomomomo>
well you should always normalize user input
<momomomomo>
i.e. force encoding: ‘iso-8859-1:UTF-8’
<Eising>
I do, but it's my code that didn't force the correct encoding in the old version of my app
<momomomomo>
:|
sankaber has joined #ruby-lang
<Eising>
in the new version, it's not possible
<momomomomo>
I’m scared to ask how you’re actually running the code
<Eising>
it's just because the old version of the mysql adapter didn't maintain the correct character encoding to the db
<Eising>
mysql2 allows me to do that
tunaCanBruh has joined #ruby-lang
<Eising>
so it's a case of the mysql adapter running latin1, where the app is actually utf-8
<momomomomo>
i see
arBmind has joined #ruby-lang
<Eising>
I'm looking for a way to convert it back to non-garbled utf-8
<Eising>
so far, my different variations of String#force_encoding and String#encode don't seem to bear fruit
intinig has quit [Remote host closed the connection]
tkuchiki has quit [Remote host closed the connection]
arBmind has quit [Client Quit]
intinig has joined #ruby-lang
tkuchiki has joined #ruby-lang
<jhass>
so your database connection is utf-8 now?
<Eising>
yeah
intinig has quit [Remote host closed the connection]
intinig has joined #ruby-lang
<Eising>
somehow it correctly converts everything in the old version of the app
<jhass>
so your DB thinks the column holds iso-8859-1, we assume it's actually utf-8 bytes in there. Then the db would do iso-8859-1 -> utf-8 on the utf-8 and give it to you, your string is marked as utf-8
davispuh has joined #ruby-lang
<jhass>
if those assumptions are correct you would do utf-8 -> iso-8859-1 and force to utf-8
<Eising>
as in str.force_encoding("iso-8859-1").encode("utf-8")
<Eising>
or?
<jhass>
no, that's doing iso-8859-1 -> utf-8 again
<jhass>
.encode('iso-8859-1').force_encoding("utf-8") is what I would try
<jhass>
but maybe if you can put up the bytes somewhere to experiment...
<Eising>
Encoding::UndefinedConversionError: U+2026 from UTF-8 to ISO-8859-1
<Eising>
I would do that if I knew how to do that without messing up the encodings even more...