#ruby - 01 August 2018
« Back 1 day Forward 1 day »
[00:09:12]
havenwood:
graft: There's an Enumerable#count_by proposed by Nobu I believe for Ruby 2.6.
[00:22:19]
baweaver:
havenwood havenwood havenwood!!! https://bugs.ruby-lang.org/issues/14869 && https://bugs.ruby-lang.org/issues/14916
[00:52:45]
ule:
Hey guys, what would you use to paginate a hash? Lets say I have a list with 100 items and want to paginate this into 5 groups
[00:57:25]
leitz:
Looking at the dry-core gem. In lib/ there's directory dry and file dry-core.rb that just has require 'lib/dry/core'. In lib/dry/core there's a dry directory and 'core.rb' that just has Module Core inside module Dry, with no other real code. There are ruby files in lib/dry/core that have Module Core defined inside Module Dry. Is the "require 'lib/dry/core'
[00:58:57]
ali_g:
Hello, everyone! can somebody help me with this one? https://gist.github.com/ponentesincausa/fc3e94bd48392f1b213e862d74dadec1
[01:01:12]
ali_g:
if I h["amount"] it throws "700", why would the result be ["amount", "700"]["amount"]?
[01:08:50]
havenwood:
ali_g: When you #map over a Hash the |a| in your block argument is indeed an Array of two elements, the key and value.
[01:10:17]
havenwood:
ali_g: `a` is an Array, not a Hash, so you can't use #[] with "amount" since Array#[] expects an Integer.
[01:11:49]
ali_g:
@havenwood I am seeing my mistake now, I thought I was grabbing a value from the key but I wasn't, I ended up with two array of 2 values. I can't use .first because the h in the example will be changing sometimes including more than one "amount" value, but I conclude from what you are saying that map is the wrong tool for this
[01:19:48]
havenwood:
ali_g: If you show what you really have, I'm sure we can show you an efficient solution.
[07:33:02]
badeball:
gosh, I dislike it when I search for a method and docs.ruby-lang.org comes before ruby-doc.org
[07:33:31]
badeball:
I can't be the only one who finds it a bit hard to read green text on a white background, can I?
[07:36:49]
badeball:
cli documentation you say? installed it, but I get $ ri Array.sort # => Nothing known about Array
[07:37:59]
badeball:
I'm running arch, so it's packaged, but it wouødn't surprise me if that was the case
[07:42:46]
elomatreb:
It's really nice yeah. If you use pry as your REPL it also has built-in ri commands, so you don't have to leave
[09:15:01]
dionysus69:
this format("%.#{18}f", BigDecimal("0.000000000000000001")) returns correctly >> "0.000000000000000001"
[09:15:29]
dionysus69:
this is weird: format("%.#{18}f", BigDecimal("0.100000000000000001")) => "0.100000000000000006"
[09:15:57]
dionysus69:
this is extra weird: format("%.#{18}f", BigDecimal("1.000000000000000001")).to_s => "1.000000000000000000"
[09:19:00]
Bish:
(the r prefixes, makes 3 a rational number... when 1 gets divided by a rational the result gets rational)
[09:32:57]
dionysus69:
so i have this big decimal in database saved correctly, I just want to represent it in a float correctly
[09:33:33]
dionysus69:
I just want to show the user 1.1000000000000000001 instead of 0.1000000000000000001e1
[09:36:51]
badeball:
dionysus69: my guess would be that Kernel#format converts it to a float and you lose the resolution again. can you try the builtin BigDecminal#to_s with 'F', IE. BigDecimal.new('123').to_s('F')
[09:38:32]
tbuehlmann:
dionysus69: are you looking for BigDecimal.new('0.1000000000000000001e1').to_s('F')?
[09:40:17]
snickers:
Hi, someone know why active record on oracle return 0.28522e5 for integer 28522
[09:42:19]
Bish:
but if you want it to have losless, creating your own type / saving it as an array is your only choice
[09:42:35]
dionysus69:
yea I think so too ^.^ but where I come from, everyone uses either mysql oracle or mssql
[09:44:14]
badeball:
Bish: you have a binary format in psql, so if you can serialize / deserialize your preferred float type in you language then you're good to go
[09:48:41]
badeball:
unless you can represent integers of arbritary length, then a rational suffers from the same presicion problems
[09:50:02]
badeball:
a rational and a floating point are just two different ways of representing numbers, but constrained by the same reality
[09:51:02]
Bish:
but when in doubt, store the number as a string, write a integer lib(does that exist in ruby?)
[09:51:27]
dionysus69:
Bish tbuehlmann as I wanted to format the number I found that include ActionView::Helpers::NumberHelper includes number_with_precision(any_number, precision: 18)
[09:53:35]
badeball:
rationals can help you avoid accumulating floating errors over multiple arithmic operations
[09:55:12]
dionysus69:
so I decided to use floats for all so I am converting everything to bigdecimal
[09:56:10]
dionysus69:
I could convert it to integer but , then I would have to convert it back to float to show to user
[09:57:18]
dionysus69:
only glitch so far was with format("%.#{precision}f", number) as I just found out
[09:58:31]
Bish:
but i wouldn't do it, simply becuase.. i don't know in future you, or someone working with your software
[10:01:46]
dionysus69:
big decimal is convenient cause postgres supports it, I don't see a problem with proper testing before deployment
[10:01:50]
Bish:
juggling around with it would be more work than writing your own format for a integer number
[10:02:41]
Bish:
the amount of satoshis is fukin known, you don't need a floating POINT because there is not point, like literally
[10:03:57]
dionysus69:
oh well, if any funny thing happens, I can reconvert everything to ints in day or two
[10:10:33]
dionysus69:
well, I inherited this software and bigdecimals were already there, I never bothered to change because they work
[10:18:11]
dionysus69:
dunno, no one probably has enough bitcoin to cause a software error while transacting
[10:33:36]
Bish:
i even remember installing the bitcoin client as a kid (<18) being being like "wats dis lul, i mine a bit, what does this mean"
[15:18:40]
arup_r:
I have some guids from twitter feed. I would like to compare the guid like which one is bigger. Those values are like "1024009734402256896" and "999729751781724165". If I do compare them by converting them to integer using `.to_i` like "1024009734402256896".to_i > "999729751781724165".to_i will there be a problem? As the numbers are keep growing.
[15:27:52]
Demos[m]:
newer ones will tend to be larger (because many guids are generated via time based methods, or hwid based methods)
[15:28:32]
Demos[m]:
for hwids the ids tend to grow with time (although there's no cosmic reason for this), for time based ones time moves forward
[15:31:02]
arup_r:
well. say in future "1024009734402256896" becomes "102400973440225689684848484848484444", and if I do call .to_i on it, I hope it will not break .
[15:34:11]
arup_r:
this is where I do the comparisons https://gist.github.com/aruprakshit/db9715720e1ca5554bf131967e33701a#file-tweet-rb-L38
[15:35:28]
z64:
a twitter ID would not be bigger than 18446744073709551615, though maybe one day it will be uint128
[15:36:50]
ciro:
irb(main):001:0> puts 372873827329873298732983729837298372983729837298372983729837298372983729837293872.to_i
[15:37:46]
z64:
the function i displayed above ^ prints the embedded timestamp of whenever that resource was created
[15:38:04]
ciro:
no problem with big numbers, they will be converted to the needed class by the comparison methods
[16:10:44]
ciro:
btw what are the beneficts of making the code more complex? a,b=c,d instead of a=c; b=d ?
[16:12:54]
ciro:
it's like saying: "Mary and Luoise are my sister and my mother respectivelly" instead of "Mary is my sister, Louise is my mother"
[16:13:19]
maryo:
while starting the dashing, I get an error. Some pointers would be helpful. Here is the error --> https://dpaste.de/dOti/raw
[16:14:17]
sonOfRa:
And will probably confuse others as well; two lines is very likely the best, and most obvious path
[16:27:23]
Sylario:
And I bet it's the same in Italian than in French or spanish, so no problems here
[16:31:00]
ciro:
it was my first task, my boss commanded me to to it because the first programmers they hired did not speak english very well, and the class names, variable names, etc, had spanglish names or names in english that did not make any sense at all
[16:32:46]
Sylario:
Rails was my first framework with pluralization, quickly learned the ie/y english rules
[17:01:54]
jrich523:
hey guys, does this seem right style wise? https://gist.github.com/jrich523/f09db4d657eca565d82a974b28abf1df
[17:15:18]
havenwood:
jrich523: You can just use the truthiness with `||` instead of explicit nil? checks.
[17:19:54]
havenwood:
jrich523: There's more than one way to do it! You could also assign an intermediary local variable, or map/find, etc.
[17:22:43]
havenwood:
jrich523: return cpu_count if cpu_count = @forman_host.cpus || @puppet_guest.cpus
[17:25:25]
jrich523:
thats what this is, its from the Guest class, so its to populat the guest with the 'best' info
[17:26:36]
havenwood:
jrich523: Maybe worried someone is going to pull a core out at any moment. ;-P
[17:27:49]
jrich523:
but yeah, not sure if my msgs made it, but its a Guest class and they pass in the puppet/foreman data on init
[17:28:05]
jrich523:
so i find it odd that they do the work in the method, and not in the init (once vs everytime)
[17:28:49]
havenwood:
jrich523: it does make sense to set an instance variable on init if you have what you need to calculate it and it doesn't change.
[17:30:49]
jrich523:
yeah i feel like i could just createa a bunch of attr_reader and sort it all out on init, or maybe its to only trigger errors if its actually looked at, vs load?
[17:31:55]
jrich523:
hmm it doesnt like 2 ||, the raise at the end is angry about the string being there?
[17:49:40]
ModusPwnens:
style question: I have a block of code that I need to share within two different scopes in the same method. This shared block of code does NOT need to be shared outside of that method. Is it bad practice to use a proc/lambda for that to reflect that it doesn't need to be shared outside of the method?
[18:11:52]
mensvaga:
I'm trying to build an RPM out of a ruby gem. But the resulting RPM doesn't install any ruby files, and it tries to install stuff by default into my home directory.
[18:12:23]
mensvaga:
Is there an example spec file that I can use to modify the spec file that gem2rpm creates so I can make RPMs out of gems that are similar to what gets installed when I do something like:
[19:16:38]
alaing:
i'm trying to exclude some folder from rspec but the exclude pattern does not seem to be working
[19:18:50]
havenwood:
alaing: Can you gist an example of the directory/file that it's not properly excluding?
[19:21:40]
alaing:
I also tried profiling it and thats when i notice there were still specs in spec/features being run
[19:24:27]
alaing:
havenwood: I specifically followed this example https://relishapp.com/rspec/rspec-core/docs/configuration/exclude-pattern#the-%60--exclude-pattern%60-flag-makes-rspec-skip-matching-files
[19:25:12]
havenwood:
alaing: Can you show examples of the path of one that isn't properly excluded?
[19:27:23]
havenwood:
alaing: Right now we know the exclusion glob you used, but without an example path you expected to be exlcuded there's nothing for us to go on.
[19:27:27]
alaing:
one sec i might need to test it on another folder. features is rather long and slow running
[19:29:27]
havenwood:
alaing: Yup, what's a file you expected to be matched by that glob that wasn't.
[19:31:46]
tj-:
alaing: could the shell be expanding those wildcards first. And difference if you use single-quotes not double?
[19:33:32]
SeepingN:
"**/spec/features/*_spec.rb" will never match spec/features/admin/cases/business_units_spec.rb
[19:36:05]
alaing:
thank you so much for your help. i knew it had to be something stupid i was doing
[21:00:12]
cthu|:
so tests look like v(args).go_there().do_that().now_go_there().and_finally_do_that()
[21:00:39]
cthu|:
I made a new method in that v. My new method is called byebug and it runs byebug and returns the view