<RickHull>
(my previous example was mutating memo, which is bad form)
blackwind_123 has joined #ruby
voldemar has quit [Ping timeout: 240 seconds]
<kapil___>
thanks, now i want result in form of object a.
<RickHull>
the fun part is figuring it out!
konsolebox has quit [Ping timeout: 260 seconds]
<kapil___>
ok thanks
<RickHull>
you probably won't be using flatten
xlegoman has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
voldemar has joined #ruby
<kapil___>
i am not expart can you write it?
kinbiko has joined #ruby
<kapil___>
looking cool.. learned new methods..
yeticry has joined #ruby
konsolebox has joined #ruby
voldemar has quit [Ping timeout: 260 seconds]
yeticry_ has quit [Ping timeout: 248 seconds]
kinbiko has quit [Ping timeout: 255 seconds]
kinbiko has joined #ruby
<RickHull>
def c(a, b); result = []; a.each { |ary| result << []; ary.each { |i| b_idx = (result.length - 1) * ary.length + result.last.length; result.last << { b[b_idx] => i } } }; result
cschneid has joined #ruby
<RickHull>
something like that is a way to step through it. play around with it
<kapil___>
ok
<kapil___>
thanks
mfb2 has joined #ruby
kinbiko has quit [Ping timeout: 248 seconds]
<kapil___>
thanks a lot its working...
voldemar has joined #ruby
<kapil___>
can you explain it?
cschneid has quit [Ping timeout: 255 seconds]
<RickHull>
a.each { |ary| -- we will iterate over the contents of a -- which is 2 arrays
<kapil___>
then
<RickHull>
ary.each { |i| -- iterate over each array
cdg has joined #ruby
<RickHull>
so the first time this runs, i will be 1, then 2, then 3
mfb2 has quit [Ping timeout: 255 seconds]
<RickHull>
then we calculate how to get the b value
<RickHull>
we figure out the b_idx
cschneid has joined #ruby
<RickHull>
then we make a hash with a single key -- the b value based on b_idx
<RickHull>
with a value of i
<RickHull>
(which came from a)
<RickHull>
and we accumulate those in result, which will match the structure of a
voldemar has quit [Ping timeout: 240 seconds]
<kapil___>
understanding it. thanks a lot..
k3rn31 has quit [Ping timeout: 255 seconds]
cdg has quit [Ping timeout: 255 seconds]
cschneid has quit [Ping timeout: 255 seconds]
kinbiko has joined #ruby
voldemar has joined #ruby
mim1k has joined #ruby
nofxx has joined #ruby
kinbiko has quit [Ping timeout: 240 seconds]
voldemar has quit [Ping timeout: 248 seconds]
kinbiko has joined #ruby
mim1k has quit [Ping timeout: 255 seconds]
cschneid has joined #ruby
bkxd has quit [Ping timeout: 260 seconds]
voldemar has joined #ruby
ur5us has quit []
bkxd has joined #ruby
kinbiko has quit [Ping timeout: 260 seconds]
rabajaj has joined #ruby
voldemar has quit [Ping timeout: 248 seconds]
kinbiko has joined #ruby
bkxd has quit [Ping timeout: 248 seconds]
voldemar has joined #ruby
odinsbane has joined #ruby
kinbiko has quit [Ping timeout: 276 seconds]
guille-moe has joined #ruby
voldemar has quit [Ping timeout: 248 seconds]
kinbiko has joined #ruby
pdcawley has joined #ruby
pdcawley has left #ruby [#ruby]
minimalism has quit [Quit: minimalism]
voldemar has joined #ruby
kinbiko has quit [Ping timeout: 255 seconds]
yabbes has joined #ruby
kinbiko has joined #ruby
voldemar has quit [Ping timeout: 260 seconds]
Xano__ has joined #ruby
<odinsbane>
darix: I have a 3.22 rails app, and if I want to upgrade to 4.2, it is recommended that I go through 4.0 first. 4.0 doesn't work with ruby 2.4 though. So, it is a bit of a catch 22.
konsolebox has quit [Ping timeout: 248 seconds]
kinbiko has quit [Ping timeout: 260 seconds]
bkxd has joined #ruby
konsolebox has joined #ruby
voldemar has joined #ruby
kinbiko has joined #ruby
uZiel has quit [Ping timeout: 248 seconds]
voldemar has quit [Ping timeout: 250 seconds]
voldemar has joined #ruby
kinbiko has quit [Ping timeout: 260 seconds]
rippa has joined #ruby
konsolebox has quit [Ping timeout: 255 seconds]
<kapil___>
RickHull: can you explain ? b_idx = (result.length - 1) * ary.length + result.last.length;
kinbiko has joined #ruby
konsolebox has joined #ruby
voldemar has quit [Ping timeout: 240 seconds]
bkxd has quit [Ping timeout: 255 seconds]
Cohedrin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<RickHull>
b_idx needs to go 0..5
voldemar has joined #ruby
<RickHull>
but since we choose a's structure, we have two loops, nested
<RickHull>
the outer loop, if we had an idx, would be 0 then 1
<RickHull>
the inner loop, the idx would go 0..2
<RickHull>
how can we get 0..5 from 0..1 and 0..2
<kapil___>
i understand it.
<RickHull>
0..1 * 3 + 0..2 yields 0..5
Dimik has quit [Ping timeout: 248 seconds]
guille-moe has quit [Ping timeout: 260 seconds]
kinbiko has quit [Ping timeout: 255 seconds]
<RickHull>
I am calculating the outer and inner idx from result's length
<kapil___>
so we not need an index
<baweaver>
Is that the real data?
<RickHull>
but it could be provided directly by e.g. a.each.with_index { |ary, outer_idx| ary.each.with_index { i, inner_idx|
<baweaver>
there may well be a simpler way depending on what you're actually doing here.
InfinityFye has joined #ruby
<RickHull>
I believe it :)
<baweaver>
especially if it involves ActiveRecord somehow
<kapil___>
the real data is very big
<kapil___>
B is active record
<baweaver>
What's the shape of the data or the code that gets it?
<kapil___>
columns
<baweaver>
Note that it will make it a lot easier for us to help you if you open with what the actual code is
voldemar has quit [Ping timeout: 248 seconds]
<kapil___>
I want to loop through all active record column. and add extra columns between it i defined it in yaml file array
kinbiko has joined #ruby
<baweaver>
why?
reber has joined #ruby
<baweaver>
what's the end game on this one?
<kapil___>
because that fields are calculated columns. i want generator to generate fields for it
<baweaver>
and why do you want the calculated fields generated?
<baweaver>
what are you attempting to do with them>
<baweaver>
I'm only asking questions to try and get to what your problem is
<kapil___>
I want to arrange columns in grid.
<kapil___>
so i defined a grind in yaml file
dionysus70 has joined #ruby
<baweaver>
you ask us very specific questions related to why you did something when there may be a much simpler way about 5-10 decisions before you got to that point
<kapil___>
i want to take each row from yaml file .
<baweaver>
Why a YAML file? Are you doing this for your views?
alveric has quit [Quit: WeeChat 1.9.1]
<baweaver>
and is this done for each row?
<kapil___>
I made a generator to generate view. i need to define grid row and how many columns in each row in yaml file
uZiel has joined #ruby
kinbiko has quit [Ping timeout: 240 seconds]
<baweaver>
chances are you don't need that
<baweaver>
Can you show us the code you use to generate this in a gist?
<kapil___>
1. I want to add some columns to active record columns.
n13z has joined #ruby
<kapil___>
2. I want to add grid like data for them
voldemar has joined #ruby
christiandsg has quit [Ping timeout: 248 seconds]
ShekharReddy has joined #ruby
<baweaver>
It seems like you're conflating about 3-4 different techs and doing things very very oddly
<baweaver>
honestly it would take a very long time to understand everything you're doing here and why you're likely doing it
TomyLobo2 has joined #ruby
kinbiko has quit [Ping timeout: 268 seconds]
cdg has joined #ruby
<baweaver>
The best idea is to take a few steps back. You're making this exceptionally more complicated than it needs to be
voldemar has quit [Ping timeout: 248 seconds]
<kapil___>
ok. you are right.
<baweaver>
Rails supplies data as JSON. React consumes the data as JSON. React then makes the table and the virtual attributes (totals)
cdg_ has joined #ruby
<kapil___>
I made it complex but can u understand above. is it not good
kinbiko has joined #ruby
<kapil___>
but i want to add columns between
<baweaver>
that would be a virtual attribute
<kapil___>
virtual columns
<baweaver>
one that is not in the database, but is generated from its data
<kapil___>
yes
<kapil___>
i want to write somewhere in generator to generate fieds for it
<baweaver>
How are the fields calculated?
bkxd has joined #ruby
<baweaver>
What is the simplest way you can express it?
<baweaver>
I'm going to leave you with that because you really do need to go through some of this on your own
<kapil___>
suppose i have qty and pcs . i want a virtual column after pcs, called weight
<kapil___>
sorry total pcs = qty * pcs
cdg has quit [Ping timeout: 255 seconds]
cdg has joined #ruby
marr has joined #ruby
cdg_ has quit [Ping timeout: 255 seconds]
kinbiko has quit [Ping timeout: 260 seconds]
bkxd has quit [Ping timeout: 260 seconds]
kinbiko has joined #ruby
voldemar has joined #ruby
cdg has quit [Ping timeout: 255 seconds]
kinbiko has quit [Ping timeout: 248 seconds]
voldemar has quit [Ping timeout: 260 seconds]
bkxd has joined #ruby
mtkd has quit [Ping timeout: 248 seconds]
kinbiko has joined #ruby
mtkd has joined #ruby
iamarun has joined #ruby
bkxd has quit [Ping timeout: 260 seconds]
muelleme has joined #ruby
kinbiko has quit [Ping timeout: 240 seconds]
voldemar has joined #ruby
kinbiko has joined #ruby
voldemar has quit [Ping timeout: 260 seconds]
voldemar has joined #ruby
kinbiko has quit [Ping timeout: 248 seconds]
kinbiko has joined #ruby
voldemar has quit [Ping timeout: 260 seconds]
pdcawley has joined #ruby
d^sh has quit [Ping timeout: 260 seconds]
d^sh has joined #ruby
voldemar has joined #ruby
kinbiko has quit [Ping timeout: 255 seconds]
bkxd has joined #ruby
kinbiko has joined #ruby
voldemar has quit [Ping timeout: 255 seconds]
bkxd has quit [Ping timeout: 248 seconds]
Emmanuel_Chanel has quit [Ping timeout: 240 seconds]
i32inf has joined #ruby
kinbiko has quit [Ping timeout: 255 seconds]
voldemar has joined #ruby
claudiuinberlin has joined #ruby
<TomyLobo2>
I wanna generate spreadsheet column names (A..Z, then AA and so on). Apparently 'A'..'ZZZZ' is adequate for that. Now, how do I pluck an item from the middle of that?
kinbiko has joined #ruby
<TomyLobo2>
i mean without generating the entire thing until that point
<TomyLobo>
hmm, enumerators dont seem to have a "last" method
safetypin has joined #ruby
<TomyLobo>
i guess they can only be enumerated in order
Asher has quit [Ping timeout: 248 seconds]
lexruee has quit [Ping timeout: 248 seconds]
truenito has joined #ruby
xlegoman has joined #ruby
safetypin has quit [Client Quit]
lexruee has joined #ruby
truenito has quit [Ping timeout: 240 seconds]
despai has joined #ruby
isec has joined #ruby
Lyubo1 has quit [Read error: Connection reset by peer]
mfb2 has joined #ruby
mfb2 has quit [Remote host closed the connection]
Lyubo1 has joined #ruby
voldemar has joined #ruby
christiandsg has joined #ruby
safetypin has joined #ruby
meadmoon has joined #ruby
uZiel has quit [Ping timeout: 248 seconds]
truenito has joined #ruby
uZiel has joined #ruby
meadmoon has quit [Client Quit]
herbmillerjr has quit [Quit: Konversation terminated!]
chocoelho has joined #ruby
<dminuoso>
havenwood: 1.step should have an awesome syntax like (1..)
<dminuoso>
or more generally (1, 2..)
<dminuoso>
[1, 2..] would work too, wouldnt mind having lazy arrays
<jhass>
somehow I never needed .step in the real world though
marr has joined #ruby
truenito has quit [Ping timeout: 255 seconds]
<jhass>
was only handy in challenges so far
hello_dave has joined #ruby
safetypin has quit [Quit: ZZZzzz…]
<dminuoso>
jhass: It's actually a quite powerful abstraction
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<dminuoso>
1.step(by: 2) is amazing for generating odd numbers
<dminuoso>
or 2.step(by: 2) for even ones
NL3limin4t0r has joined #ruby
alex`` has quit [Quit: WeeChat 1.9.1]
hello_dave has quit [Quit: Page closed]
ShalokShalom has quit [Ping timeout: 248 seconds]
<TomyLobo>
is anyone aware of a way to efficiently dump a 38 MB json string into an mssql TEXT column using tiny_tds?
<TomyLobo>
remote database, or i would use openrowset or something
<TomyLobo>
usually i'd use a prepared statement, but TinyTds::Client has no "prepare" method
bmurt has joined #ruby
guille-moe has quit [Ping timeout: 248 seconds]
<dminuoso>
TomyLobo: What would a prepared statement help you with?
<dminuoso>
All a prepared statement does is safe you re-parsing the query and generating a query plan.
<dminuoso>
Would this 38 MiB string go into a single tuple?
uZiel has quit [Remote host closed the connection]
isec has quit [Ping timeout: 248 seconds]
<TomyLobo>
it goes straight into the openjson() function, whose result then gets saved into a table
despai has quit [Ping timeout: 260 seconds]
<TomyLobo>
dminuoso, are you sure that's what a prepared statement does? that sounds a little inefficient
<TomyLobo>
if it gets escaped and interpolated into the query and such
minimalism has joined #ruby
<TomyLobo>
client.prepare('SELECT [key], value as value_json into savegame from OPENJSON(?)').execute(json) # basically what i'd do if prepared statements were available
isec has joined #ruby
<dminuoso>
TomyLobo: You can usually create templated prepared statements that have placeholders (which incidentally can lead to inefficient query plans because the optimizer does not have all the information available)
oetjenj has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<dminuoso>
TomyLobo: But that is somewhat orthogonal to your problem.
isec is now known as macpith
<dminuoso>
TomyLobo: Does the data go into a single row or not?
<TomyLobo>
no, but that is not what you want to know :)
<TomyLobo>
openjson turns that one parameter into n rows
<TomyLobo>
it parses the top-level object basically
<TomyLobo>
but what goes in is a single value
<TomyLobo>
i could move the openjson to a separate statement, so that in the first statement, everything does go into a single row
<TomyLobo>
if that changes anything
csk157 has joined #ruby
<TomyLobo>
client.prepare('SELECT ? as json into savegame_json').execute(json) # like that, or something similar
chocoelho has quit [Ping timeout: 240 seconds]
<dminuoso>
TomyLobo: What would a prepared statement help you with exactly?
<dminuoso>
Preparing a statement and immediately executing it is relatively pointless on its own.
<dminuoso>
The whole idea of prepared statements is for queries that can't afford to re-parse or rebuild a new query plan.
<TomyLobo>
well i would be more than happy if regular statements had support for placeholders and now that you mention it, i never checked whether they do
<dminuoso>
(Say because you are hammering the database with the same query with a high frequency, or perhaps building the query plan is expensive (high degrees of join will do that)
Asher has joined #ruby
<dminuoso>
I know it's sometimes abused for interpolation and sql escaping because the libraries suck and don't support it themselves.
csk157 has quit [Ping timeout: 248 seconds]
<TomyLobo>
./savetodb.rb:14:in `execute': wrong number of arguments (given 2, expected 1) (ArgumentError)
<TomyLobo>
client.execute("SELECT [key], value as value_json into savegame from OPENJSON(?)", json)
<TomyLobo>
my point is kinda that parameters dont really get inserted into some kind of string, but that parser makes a note of the placeholder and takes data from the corresponding parameter instead of parsing it from the sql query string
<TomyLobo>
the parser*
uZiel has joined #ruby
mtkd has quit [Ping timeout: 255 seconds]
<TomyLobo>
and with a 38 MB string, escaping and parsing the string can already be significantly slower than not doing it
mjolnird has quit [Ping timeout: 255 seconds]
chocoelho has joined #ruby
<dminuoso>
TomyLobo: Is the performance of this relevant? Is losing a few hundred milliseconds make you lose any sleep?
christiandsg has quit [Remote host closed the connection]
<TomyLobo>
also, using placeholders is doing it properly
<dminuoso>
Because loading 38MiB from JSON into the database does not sound like something you would do frequently anyway. And if this is so performance critical, well go native and dont do this with some bizarre and badly written database adapter.
<dminuoso>
TomyLobo: If the database forces you to use jdbc in order to gain access to sensible features, I'd say the database is a problem.
<TomyLobo>
(also, why microsoft uses their own, horrible doc generator for java is beyond me)
<TomyLobo>
dminuoso, the odbc driver is probably fine too
<TomyLobo>
actually, why dont i use that... let me try
despai has joined #ruby
<TomyLobo>
i even remember doing that once on a rubyinstaller ruby... so long ago ^^
i32inf has quit [Ping timeout: 260 seconds]
macpith has quit [Ping timeout: 260 seconds]
<TomyLobo>
i can only get to the source of that thing tomorrow... for now, escapes \o/
i32inf has joined #ruby
<TomyLobo>
takes a good chunk of time...
<TomyLobo>
yeah this takes more than a minute at least, so it's not usable. Since I've never tried it with prepared statements, I dont know if they'd improve the situation, though :)
i32inf has quit [Ping timeout: 260 seconds]
<TomyLobo>
might just be that the azure db is slow
podman is now known as podman[USC]
dn`_ has joined #ruby
Blaze_Boy has left #ruby ["ERC (IRC client for Emacs 25.3.1)"]
dn` has quit [Ping timeout: 258 seconds]
dn`_ is now known as dn`
techn1cs has joined #ruby
techn1cs has quit [Changing host]
techn1cs has joined #ruby
despai has quit [Read error: Connection reset by peer]
tomphp has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
JaccoP has quit [Remote host closed the connection]
reber has quit [Remote host closed the connection]
JaccoP has joined #ruby
yabbes has joined #ruby
safetypin has joined #ruby
chocoelho has joined #ruby
ogres has quit [Quit: Connection closed for inactivity]
<TomyLobo>
DBI.connect("DBI:ODBC:#{datasource}", "#{usr}","#{pwd}") gives me DBI::InterfaceError: Unable to load driver 'ODBC' (underlying error: uninitialized constant DBI::DBD::ODBC). I did "gem install dbi" and "gem install dbd-odbc"
JaccoP has quit [Quit: Leaving]
<TomyLobo>
I can only assume I am doing something wrong
<TomyLobo>
i was missing "gem install ruby-odbc", apparently
goyox86_ has quit [Quit: goyox86_]
goyox86_ has joined #ruby
npgm has joined #ruby
goyox86_ has quit [Client Quit]
voldemar has joined #ruby
thyRootest has joined #ruby
yabbes has quit [Quit: lu]
quobo has quit [Quit: Connection closed for inactivity]
<mikecmpbll>
pretty dumb question but it's late and i'm tired :D if i have an each loop inside a while loop, what's the easiest way to move onto the next iteration of the while loop from in the each iteration
thyRootest has quit [Client Quit]
<tobiasvl>
mikecmpbll: that's not really possible, but maybe you're looking for "break"? that'll break out of the "each" loop
<mikecmpbll>
yeah, doh. means i have to complicate the code more than i'd like
safetypin has quit [Quit: ZZZzzz…]
Exagone313 has quit [Quit: see ya!]
<mikecmpbll>
the break makes the iterator return nil so i need to check for that case then `next` the external loop
csk157 has quit [Ping timeout: 248 seconds]
sepp2k1 has joined #ruby
sepp2k has quit [Ping timeout: 248 seconds]
Exagone313 has joined #ruby
safetypin has joined #ruby
guille-moe has quit [Ping timeout: 255 seconds]
gbaptista has joined #ruby
skweek has joined #ruby
gbaptista has quit [Client Quit]
safetypin has quit [Client Quit]
<dminuoso>
mikecmpbll: You can use catch/throw as a clutch for breaking out of deeply nested constrol structures.
<dminuoso>
It's equivalent to goto, so use appropriately careful.
sundhell has joined #ruby
safetypin has joined #ruby
<dminuoso>
I'd probably prefer this over some some; do_abort = true; break;