« Back to channel list

#ruby - 17 November 2018

« Back 1 day Forward 1 day »
[00:00:04] RougeR: has joined #ruby
[00:00:35] cow[moo]: has joined #ruby
[00:02:43] sagax: jayjo: https://github.com/helpyio/helpy/tree/master/db/migrate
[00:03:40] jayjo: does it invoke a particular one, or everything in the directory? how about the db:seed - there's a file called seeds.rb but there's no seed anywhere
[00:04:58] jayjo: or db:setup, I don't see that either
[00:04:59] sagax: seed https://github.com/helpyio/helpy/blob/master/db/seeds.rb
[00:05:39] jayjo: are they defined anywhere? Is there a file or config that says db:seed -> run db/seeds.rb ?
[00:06:15] jayjo: or does it look for files that start with the command?
[00:09:11] thinkpad: has joined #ruby
[00:23:46] bmurt: has joined #ruby
[00:23:59] elphe: has joined #ruby
[00:24:31] impermanence: has joined #ruby
[00:33:56] despai: has joined #ruby
[00:34:06] elphe: has joined #ruby
[00:43:05] cd: has joined #ruby
[00:43:45] queip: has joined #ruby
[00:53:00] za1b1tsu: has joined #ruby
[00:54:52] alicef: has joined #ruby
[01:03:59] nchambers: has joined #ruby
[01:21:05] bmurt: has joined #ruby
[01:24:23] crankharder: has joined #ruby
[01:28:38] jcalla: has joined #ruby
[01:32:49] awkwords: has joined #ruby
[01:34:33] ss_much: has joined #ruby
[01:43:06] crankharder: has joined #ruby
[01:56:08] jetchisel: has joined #ruby
[01:57:50] crankharder: has joined #ruby
[01:59:16] alicef: has joined #ruby
[02:20:53] tdy: has joined #ruby
[02:23:46] bmurt: has joined #ruby
[02:26:06] Iambchop: jayjo: helpy is a rails app, so rails docs may answer some of your questions. the db:migrate task will load all of the migration files in the directory; on subsequent runs it will skip files it has loaded before. the db:seed task runs the seeds.rb file. those are standard rails conventions. https://guides.rubyonrails.org/active_record_migrations.html
[02:33:05] alicef: has joined #ruby
[02:41:10] za1b1tsu: has joined #ruby
[02:47:01] darkhanb: has joined #ruby
[03:15:48] chouhoulis: has joined #ruby
[03:25:57] kapil____: has joined #ruby
[03:35:43] apparition: has joined #ruby
[03:43:23] queip: has joined #ruby
[03:53:45] sgen: has joined #ruby
[04:04:08] white_lilies: has joined #ruby
[04:08:58] alicef: has joined #ruby
[04:09:22] braincrash: has joined #ruby
[04:21:40] moei: has joined #ruby
[04:23:35] eckhardt: has joined #ruby
[04:29:14] za1b1tsu: has joined #ruby
[04:30:37] eckhardt: has joined #ruby
[04:35:10] alicef: has joined #ruby
[04:44:38] NightMonkey: has joined #ruby
[04:45:53] queip: has joined #ruby
[05:07:51] arescorpio: has joined #ruby
[05:12:00] za1b1tsu: has joined #ruby
[05:21:21] vonfry: has joined #ruby
[05:25:36] venmx: has joined #ruby
[05:32:42] elphe: has joined #ruby
[05:34:24] MoritaShinobu: has joined #ruby
[05:43:52] queip: has joined #ruby
[05:45:13] elphe: has joined #ruby
[06:01:35] aspiers: has joined #ruby
[06:05:58] sgen: has joined #ruby
[06:16:02] idiocrash: has joined #ruby
[06:25:40] rippa: has joined #ruby
[06:29:03] idiocrash: has joined #ruby
[06:30:37] Dbugger: has joined #ruby
[06:34:00] idiocrash: has joined #ruby
[06:34:10] kapil____: has joined #ruby
[06:41:22] sauvin: has joined #ruby
[06:43:12] queip: has joined #ruby
[06:43:19] idiocrash: has joined #ruby
[06:45:49] doubledup: has joined #ruby
[06:46:24] idiocrash: has joined #ruby
[06:46:50] baweaver: Started breaking Reducing Enumerable into an illustrated novel of sorts - https://medium.com/@baweaver/reducing-enumerable-part-one-the-journey-begins-ddc1d4108490
[06:47:02] baweaver: It'll take a bit, but should make it easier for everyone to read.
[07:09:01] elphe: has joined #ruby
[07:28:07] Exuma: has joined #ruby
[07:28:29] Exuma: has joined #ruby
[07:28:41] idiocrash: has joined #ruby
[07:37:15] elphe: has joined #ruby
[07:44:45] queip: has joined #ruby
[07:46:53] Fernando-Basso: has joined #ruby
[07:47:07] elphe: has joined #ruby
[07:53:25] reber: has joined #ruby
[08:06:54] elphe: has joined #ruby
[08:10:57] venmx: has joined #ruby
[08:15:19] conta: has joined #ruby
[08:21:55] lomex: has joined #ruby
[08:25:41] rrichardsr3: has joined #ruby
[08:26:04] idiocrash: has joined #ruby
[08:26:32] elphe: has joined #ruby
[08:27:25] venmx: has joined #ruby
[08:32:26] dellavg_: has joined #ruby
[08:43:13] queip: has joined #ruby
[08:45:08] Puffball: has joined #ruby
[08:45:40] marz_d`ghostman: has joined #ruby
[08:47:24] marz_d`ghostman: Tried creating a config.rb on my project root to declare some application wide constants. The constants defined in it doesn't seem to be accessible by other parts of my application, specifically under /lib. https://gist.github.com/marzdgzmn/e59587818b0046c4b8911a58a5b5fce9
[08:55:12] Nicmavr: has joined #ruby
[08:58:12] Fire-Dragon-DoL: has joined #ruby
[08:59:42] marz_d`ghostman: How do I test File.open in rspec?
[09:22:47] whysthatso: has joined #ruby
[09:23:59] rrichardsr3: has joined #ruby
[09:24:41] ShekharReddy: has joined #ruby
[09:44:08] queip: has joined #ruby
[09:48:12] doubledup: has joined #ruby
[09:49:16] elphe: has joined #ruby
[10:04:59] phaul: has joined #ruby
[10:14:18] Mike11: has joined #ruby
[10:43:17] queip: has joined #ruby
[10:57:13] jthomas: has joined #ruby
[11:05:22] elphe: has joined #ruby
[11:06:27] lxsameer: has joined #ruby
[11:27:05] al2o3-cr: has joined #ruby
[11:30:49] DTZUZO: has joined #ruby
[11:43:48] queip: has joined #ruby
[11:56:57] anikras: has joined #ruby
[11:57:24] anikras: has left #ruby: ()
[11:58:10] AJA4350: has joined #ruby
[12:07:54] apparition: has joined #ruby
[12:31:57] jaddison_: has joined #ruby
[12:34:43] LinuxKnight: has joined #ruby
[12:35:22] lomex: has joined #ruby
[12:38:25] KQgt0Cl3: has joined #ruby
[12:38:34] smutnysyn: has joined #ruby
[12:38:43] KQgt0Cl3: Hello all I got a problem it seems I cannot solve :/
[12:41:53] DEac-: has joined #ruby
[12:44:50] KQgt0Cl3: https://hastebin.com/yarakajivi.rb
[12:45:10] KQgt0Cl3: ./prices.rb:5:in `price': undefined method `read' for "https://www.bitstamp.net/api/v2/ticker/btceur":String (NoMethodError) from ./prices.rb:10:in `<main>'
[12:45:22] queip: has joined #ruby
[12:45:27] KQgt0Cl3: before I made this into a method it worked fine.
[12:45:44] KQgt0Cl3: I just want to pass the url as a parameter to the method and use it.
[12:47:14] smutnysyn: because what you're passing is a String and there is no such method as String#read
[12:47:28] KQgt0Cl3: https://dpaste.de/32an
[12:48:10] al2o3-cr: KQgt0Cl3: content = open url, &:read
[12:48:11] KQgt0Cl3: But i want to pass a string
[12:48:14] smutnysyn: I assume you're going to need to crease some sort of URI object first passing the string as param
[12:48:55] al2o3-cr: KQgt0Cl3: ang use JSON to parse it.
[12:48:59] fredmorcos: has joined #ruby
[12:49:13] KQgt0Cl3: Okay, no errors now!!!
[12:49:23] KQgt0Cl3: @al2o3-cr you are awesome!
[12:50:17] KQgt0Cl3: Okay now I have to read and understand what I wrote :P
[12:56:39] KQgt0Cl3: How would I go now and save the output of the method call to a text file?
[12:58:01] KQgt0Cl3: Actually let me try something first ;)
[13:01:25] KQgt0Cl3: Ah I am such a noob :P
[13:01:48] KQgt0Cl3: File.write("temporary.txt, btceur")
[13:01:56] GodFather: has joined #ruby
[13:02:02] KQgt0Cl3: ./prices.rb:13:in `write': wrong number of arguments (given 1, expected 2..3) (ArgumentError) from ./prices.rb:13:in `<main>'
[13:04:36] KQgt0Cl3: I am trying another way, pascal style :D
[13:07:55] KQgt0Cl3: temporary = File.new("temporary.txt", "w")
[13:08:07] KQgt0Cl3: temporary.write(btcusd)
[13:08:09] KQgt0Cl3: temporary.close
[13:12:15] pskosinski: has joined #ruby
[13:31:55] Dbugger: has joined #ruby
[13:32:13] ss_much: has joined #ruby
[13:44:54] queip: has joined #ruby
[13:46:27] KQgt0Cl3: has joined #ruby
[13:46:43] KQgt0Cl3: How can I rename a file to its' hash?
[13:46:49] KQgt0Cl3: I can't find anything about that.
[13:48:32] al2o3-cr: KQgt0Cl3: ?
[13:48:45] KQgt0Cl3: I have a text file named temporary.txt
[13:48:56] KQgt0Cl3: I would like to rename it to it's contents hash
[13:49:28] al2o3-cr: KQgt0Cl3: how are you hashing the file contents?
[13:50:16] KQgt0Cl3: I am thinking of a whatever hashing algorithm
[13:50:27] KQgt0Cl3: is xxHash an option?
[13:50:37] al2o3-cr: KQgt0Cl3: to rename a file use File.rename
[13:50:46] KQgt0Cl3: https://github.com/Cyan4973/xxHash
[13:50:54] KQgt0Cl3: Oh okay! :)
[13:51:29] KQgt0Cl3: So I should hash it, store the hash into a variable and then rename the file from the content of the variable I guess.
[13:51:56] KQgt0Cl3: That's quite awesome for what I am building :D
[13:52:23] al2o3-cr: KQgt0Cl3: yeah, that would work.
[13:52:36] KQgt0Cl3: I want to store those hashes to a blockchain everytime there is a new file in the directory (therefore everytime a price changes).
[13:53:32] al2o3-cr: so the file contents will be a price?
[13:54:21] akem: has joined #ruby
[13:57:27] im0nde: has joined #ruby
[13:59:58] al2o3-cr: KQgt0Cl3: does it matter what hash algorithm?
[14:00:18] KQgt0Cl3: Not really, just something fast.
[14:00:27] KQgt0Cl3: I tried hash = Hash[*File.read(temporary.txt).split("\t")]puts hash
[14:00:46] KQgt0Cl3: Got ./prices.rb:35:in `<main>': undefined method `txt' for #<File:temporary.txt (closed)> (NoMethodError)
[14:01:14] KQgt0Cl3: do I need a require library?
[14:02:15] smutnysyn: has joined #ruby
[14:02:16] al2o3-cr: KQgt0Cl3: File.rename 'bot.rb', Digest::SHA512.file('temporary.txt').to_s ?
[14:02:36] al2o3-cr: that is using sha512 hash
[14:03:01] al2o3-cr: bot.rb lol, i was testing.
[14:03:14] al2o3-cr: obviously replace bot with temporary.txt
[14:05:02] KQgt0Cl3: Awesooooome! :)
[14:06:14] al2o3-cr: KQgt0Cl3: you will need to require openssl though.
[14:08:07] KQgt0Cl3: Why? it seems to work.
[14:08:29] KQgt0Cl3: You mean for the api read?
[14:08:38] KQgt0Cl3: let me paste all my code so far
[14:09:01] KQgt0Cl3: Here you go: https://dpaste.de/84Tw
[14:11:44] al2o3-cr: KQgt0Cl3: just return JSON.parse(open url, &:read)['last'] from price method
[14:12:21] al2o3-cr: don't parse json like that.
[14:14:01] al2o3-cr: KQgt0Cl3: also, that will hash all file contents if that is what you want?
[14:17:26] conta: has joined #ruby
[14:20:20] KQgt0Cl3: It's not exactly json though
[14:25:14] al2o3-cr: KQgt0Cl3: what it is then?
[14:28:07] weird_error: has joined #ruby
[14:32:33] smutnysyn: has joined #ruby
[14:34:17] Exuma: has joined #ruby
[14:35:30] smutnysyn: has joined #ruby
[14:39:55] kapil____: has joined #ruby
[14:43:48] queip: has joined #ruby
[14:43:56] Dbugger: has joined #ruby
[14:46:06] dbugger_: has joined #ruby
[14:48:21] whysthatso_: has joined #ruby
[14:51:25] knight33_: has joined #ruby
[15:05:36] venmx: has joined #ruby
[15:25:08] Exuma: has joined #ruby
[15:28:09] leah2: has joined #ruby
[15:37:53] smutnysyn: has joined #ruby
[15:39:04] Dbugger: has joined #ruby
[15:39:55] Exuma: has joined #ruby
[15:44:25] akaiiro: has joined #ruby
[15:44:58] FastJack: has joined #ruby
[15:46:55] whysthatso_: has joined #ruby
[15:49:19] queip: has joined #ruby
[15:52:32] jrhorn424: has joined #ruby
[16:12:06] gix: has joined #ruby
[16:14:07] c0ncealed4: has joined #ruby
[16:22:12] jetchisel: has joined #ruby
[16:26:44] venmx: has joined #ruby
[16:30:20] knight33_: has joined #ruby
[16:41:34] Inline: has joined #ruby
[16:41:59] bak1an: has joined #ruby
[16:49:31] elphe: has joined #ruby
[16:54:57] queip: has joined #ruby
[16:55:51] RougeR: has joined #ruby
[16:57:59] akem: has joined #ruby
[17:01:16] troulouliou_div2: has joined #ruby
[17:01:37] sgen: has joined #ruby
[17:08:33] akem: has joined #ruby
[17:11:19] cow[moo]: has joined #ruby
[17:15:44] cow[moo]: has joined #ruby
[17:43:06] Exuma: has joined #ruby
[17:47:46] Exuma: has joined #ruby
[17:50:04] queip: has joined #ruby
[18:00:50] conta: has joined #ruby
[18:20:59] jrhorn424: has joined #ruby
[18:34:04] smutnysyn: has joined #ruby
[18:37:08] hiroaki: has joined #ruby
[18:37:45] elphe: has joined #ruby
[18:52:12] queip: has joined #ruby
[18:54:18] Freshnuts: has joined #ruby
[19:01:45] nchambers: has joined #ruby
[19:02:02] dviola: has joined #ruby
[19:02:22] SeepingN: has joined #ruby
[19:03:15] ivanskie: has joined #ruby
[19:21:58] leah2: has joined #ruby
[19:23:53] houhoulis: has joined #ruby
[19:35:26] Nicmavr: has joined #ruby
[19:35:42] teardown: has joined #ruby
[19:51:54] ivanskie: has joined #ruby
[20:01:06] desperek: has joined #ruby
[20:06:08] raulp: has joined #ruby
[20:22:12] hiroaki: has joined #ruby
[20:25:54] elphe: has joined #ruby
[20:29:37] lomex: has joined #ruby
[20:34:19] smutnysyn: has joined #ruby
[20:46:26] knight33_: has joined #ruby
[20:47:21] knight33_: has joined #ruby
[20:49:35] lomex: has joined #ruby
[20:51:28] queip: has joined #ruby
[20:56:55] pskosinski: has joined #ruby
[21:02:09] lomex: has joined #ruby
[21:18:48] elphe: has joined #ruby
[21:26:50] knight33_: has joined #ruby
[21:30:14] elphe: has joined #ruby
[21:33:36] smutnysy1: has joined #ruby
[21:36:14] yxhuvud: has joined #ruby
[21:49:21] ua_: has joined #ruby
[21:54:00] bak1an: has joined #ruby
[22:11:59] nchambers: what does the <=> operator do?
[22:12:46] phaul: it's the 3 way compare returns -1, 0, 1 for less than equal or greater than
[22:13:00] phaul: useful to implement Comparable
[22:13:07] phaul: &ri Comparable
[22:13:07] rubydoc: https://ruby-doc.org/core-2.5.3/Comparable.html
[22:13:24] nchambers: ah that makes sense. thanks
[22:15:54] phaul: sometimes you see this trick: [:equal, :greater, :less][5 <=> 3] # => :greater
[22:16:34] phaul: &>> [:equal, :greater, :less][5 <=> 3]
[22:16:36] rubydoc: # => :greater (https://carc.in/#/r/5jtp)
[22:17:56] phaul: it's abusing the -1 index of the array...
[22:18:18] phaul: I saw it on codewars once..
[22:18:38] nchambers: yeah, i like that trick
[22:19:55] weaksauce: has joined #ruby
[22:27:35] asphyxia: has joined #ruby
[22:35:08] al2o3-cr: &>> [*0..1_000_000].bsearch_index { |i| i <=> 50_000 }
[22:35:13] rubydoc: # => (https://carc.in/#/r/5juw)
[22:35:48] al2o3-cr: now revrese that.
[22:35:53] Guest24308: has joined #ruby
[22:36:06] al2o3-cr: &>> [*0..1_000_000].bsearch_index { |i| 50_000 <=> i }
[22:36:11] rubydoc: # => (https://carc.in/#/r/5jv0)
[22:37:01] al2o3-cr: binary search (left middle right)
[22:40:11] al2o3-cr: left = -1, middle = 0, right = 1
[22:40:41] al2o3-cr: left = <, middle ==, right = >
[22:40:57] elphe: has joined #ruby
[22:42:50] phaul: &>> [*0..1_000_000].last
[22:42:56] rubydoc: # => (https://carc.in/#/r/5jvo)
[22:43:27] phaul: probably that's as slow as with or without the bsearch :)
[22:45:28] al2o3-cr: phaul: not a chance.
[22:45:49] phaul: I was just saying the bot times out for all..
[22:45:59] phaul: and that's not bsearch's fault
[22:46:07] al2o3-cr: phaul: probably ram limited.
[22:46:56] al2o3-cr: &>> [*0..1_000].bsearch_index { |i| 345 <=> i }
[22:46:58] rubydoc: # => 345 (https://carc.in/#/r/5jw2)
[22:47:16] al2o3-cr: &>> [*0..1_000].index 345
[22:47:17] rubydoc: # => 345 (https://carc.in/#/r/5jw4)
[22:47:38] queip: has joined #ruby
[22:47:46] al2o3-cr: i'd say bindex is faster.
[22:47:47] samort7: has joined #ruby
[22:48:03] al2o3-cr: probably not by much.
[22:48:32] phaul: binary chpping is faster, I never disputed that, quite the contrary
[22:49:54] al2o3-cr: phaul: there won't be much.
[22:50:33] al2o3-cr: fuck it, i'm gonna say index is faster.
[22:52:11] phaul: yesterday I failed to predict how Hash behaves in terms of perfomance so I'm already losing this game, btw did you see that? I'm still buffled why Hash behaves like the way it does...
[22:53:28] phaul: why is Hash#first signifacntly slower than ~ 1.5x times than pulling the first elem by key?
[22:54:43] phaul: makes 0 sense. but that's the way it does ( did not confirm myself )
[22:55:29] al2o3-cr: phaul: coz more c is goiing on.
[22:56:03] al2o3-cr: phaul: you got pry?
[22:56:54] phaul: I have pry. why?
[22:57:46] al2o3-cr: phaul: check $ Hash#first and $ Hash#[]
[22:57:56] Puffball: has joined #ruby
[22:58:01] al2o3-cr: phaul: then you will understand.
[23:00:53] al2o3-cr: phaul: install pry-doc
[23:01:03] ruby[bot]: phaul: Pry, the better IRB, provides easy object inspection `ls`, `history`, viewing docs `?`, viewing source `$`, syntax highlighting and other features (see `help` for more). Put `binding.pry` in your source code for easy debugging. Install Pry (https://pryrepl.org/): gem install pry pry-doc
[23:02:12] bmurt: has joined #ruby
[23:03:31] phaul: al2o3-cr: I have been using pry, I know it. I prefer gvim with rbtools when I can use it, by also use pry for a repl..
[23:05:57] phaul: this still doesn't explain why Hash works like that, but I guess one would have to profile MRI to get an actual answer
[23:06:32] phaul: still really counter intuitive to me
[23:08:12] phaul: I know hash has some tricks to make small sizes faster. but the example was like 1000 element Hash. I don't expect 1000 element hash key lookup to beat #first. but still it does.
[23:10:04] phaul: maybe it's just that Enumerable #first is cr*p that Hash is including and creates temporary objects and such
[23:11:03] jaddison: has joined #ruby
[23:16:49] smutnysy1: has joined #ruby
[23:19:40] jrhorn424: has joined #ruby
[23:19:48] leitz: has joined #ruby
[23:24:21] Guest24308: has joined #ruby
[23:27:29] Exuma: has joined #ruby
[23:29:16] |aaron: has joined #ruby
[23:30:01] Exuma: has joined #ruby
[23:30:28] |aaron: Is there any different between `if obj['my_attribute']` and `if obj.attribute?('my_attribute')`? Which should I prefer?
[23:31:39] phaul: as far as ruby goes those are completely different things. One does not mean the other would work
[23:31:56] phaul: what library framework are you using
[23:32:18] |aaron: uhh well im writing chef recipes. sorry really new to ruby
[23:33:25] |aaron: so is it that the first construct tests if its defined AND isnt nil? and the second only tests if it exists (but could be nil)?
[23:34:18] houhoulis: has joined #ruby
[23:34:40] phaul: Ruby the language is much more flexible. I don't know anything about chef. the first invokes [] method on obj and thatcould do anything. The second invokes attribute? method on obj and thatcould do anyting
[23:35:07] |aaron: ahhh i see
[23:35:44] |aaron: yeah attribute ios a helper method provided by this particular Chef object apparently
[23:42:10] bak1an: has joined #ruby
[23:46:26] cajone: has joined #ruby
[23:48:34] cajone: has left #ruby: ()
[23:56:47] queip: has joined #ruby
[23:58:26] ss_much: has joined #ruby