Activity Graph

Page 1 of 13 | Next »


[04:19:18] elomatreb: 1xx - Do something else


[22:10:36] elomatreb: be nice to the bot :(


[08:52:01] elomatreb: Quit: mep mep
[08:52:32] elomatreb: has joined #ruby-offtopic
[08:52:32] elomatreb: has joined #ruby


[01:35:10] elomatreb: Quit: mep mep
[01:36:34] elomatreb: has joined #ruby-offtopic
[01:36:34] elomatreb: has joined #ruby
[01:36:50] elomatreb: Client Quit
[01:47:38] elomatreb: has joined #ruby-offtopic
[01:47:38] elomatreb: has joined #ruby
[02:12:15] elomatreb: Quit: mep mep
[02:13:08] elomatreb: has joined #ruby-offtopic
[02:13:08] elomatreb: has joined #ruby
[05:54:15] elomatreb: Quit: mep mep
[05:59:18] elomatreb: has joined #ruby-offtopic
[05:59:18] elomatreb: has joined #ruby
[06:11:02] elomatreb: Quit: mep mep
[06:11:57] elomatreb: has joined #ruby-offtopic
[06:11:57] elomatreb: has joined #ruby


[17:52:13] elomatreb: You need to share the full gist URL
[17:56:35] elomatreb: Turning the array of words you got by split'ing back into a cohesive string
[17:57:45] elomatreb: Your ifs are executed, the result is just discarded immediately because you're assigning the result of a call to #each
[17:58:16] elomatreb: #each always returns the collection it was called on, not what you do with that in the iterations
[17:59:17] elomatreb: No, you are assigning to the "correct" variable, but when all the words are done, the assignment in line 2 overrides what you changed
[18:00:19] elomatreb: https://eval.in/1072074 for a reduced demo


[13:03:17] elomatreb: Quit: mep mep
[13:03:50] elomatreb: has joined #ruby
[13:03:51] elomatreb: has joined #ruby-offtopic


[09:25:26] elomatreb: *.net *.split


[08:01:40] elomatreb: Chaining? Hashes are ordered, if that's what you mean
[08:02:44] elomatreb: You can use #uniq to get O(n) deduplication, FWIW
[08:03:31] elomatreb: Yes, but you don't have to implement it yourself
[08:04:28] elomatreb: Ruby hashes are not as straightforward as the classical hash table you might find in a textbook (i.e. they also contain a linked list to satisfy the order property), but for the most part they work like you'd expect


[21:11:44] elomatreb: Probably, yes. It's not considered particularly bad style
[21:44:33] elomatreb: You have variables named player_1 in the play method, and variables named player_one in the initialize


[14:05:36] elomatreb: Pretty sure that hasn't been the case in a *long* time, when I did Wordpress I used something gettext based


[14:45:13] elomatreb: Ping timeout: 260 seconds
[14:45:37] elomatreb: has joined #ruby
[14:45:38] elomatreb: has joined #ruby-offtopic


[13:20:09] elomatreb: A deadlock is an error condition, blocking is perfectly normal
[13:21:02] elomatreb: And not necessarily your computing, threading was a thing long before multiprocessors were available for 99% of systems
[22:14:22] elomatreb: If you have a file that is guaranteed to be required first you can just require it once in there and set Y = X, it should carry over to other files
[22:15:37] elomatreb: Not really, since ruby doesn't have a proper module system, sadly


[10:42:14] elomatreb: clorisu: Nothing in line 16 can prevent the expression in the lower lines from running, are you getting output that you don't expect?
[10:49:12] elomatreb: You're not outputting the age of the tree anywhere, only the height
[10:54:23] elomatreb: In line 18 you're adding one to it, and in line 19 you're outputting @height


[20:19:28] elomatreb: *.net *.split


[00:33:29] elomatreb: Quit: ZNC - https://znc.in
[00:34:41] elomatreb: has joined #ruby-offtopic
[00:34:41] elomatreb: has joined #ruby
[01:39:54] elomatreb: ! as well, btw
[01:42:49] elomatreb: Not necessarily just that, e.g. Array#pop is destructive but doesn't have a bang
[01:47:08] elomatreb: Some styleguides tell you to use it to indicate "dangerous (in some form, e.g. self-modifying or may raise) alternative to the method without the bang"


[16:33:02] elomatreb: d1rewolf: match only gets you the first match (if any) by design, you probably want String#scan
[19:36:41] elomatreb: One difference to Python might be that bundler and friends don't do the "environment changing" that virtualenv does, you need to prefix commands or use explicit stubs to *force* it to use your specified versions
[19:38:51] elomatreb: Does it actually apply bundler constraints or is it just a side effect of isolating the installed gems?
[19:41:00] elomatreb: The fallback behavior from what I remember if you don't prefix bundle exec is to use the latest installed version of a gem
[19:44:02] elomatreb: In short, Rubygems: Gemfile goes in -> *magic* -> something is executed
[22:20:41] elomatreb: RedNifre: What do you mean? There is Float for machine floating point numbers, or Rational if you need precision
[22:23:29] elomatreb: Or anything else for that matter :)
[22:27:12] elomatreb: Floats are often the source of bugs or weird behaviors in games, e.g. if you use them for coordinates your points become more spaced out if you go far from the center
[22:27:47] elomatreb: It depends on the numbers
[22:27:52] elomatreb: >> 0.1 + 0.1 + 0.1
[22:28:05] elomatreb: #=> 0.30000000000000004
[22:31:42] elomatreb: Hash.new(0.0)
[22:32:24] elomatreb: There is a caveat with this if you want to use it with "complicated" objects instead of the "primitives" like numbers, reading the docs of Hash#new is worthwhile
[22:45:56] elomatreb: RedNifre: Enumerable#
[22:46:20] elomatreb: ignore that, sorry
[22:46:51] elomatreb: Enumerable#sort_by will help you and was what I meant to say
[22:50:17] elomatreb: Hashes are ordered and implement Enumerable, so the to_a step is not necesssary fwiw


[22:04:33] elomatreb: #RubyOnRails, but you need to authenticate with nickserv to talk
[22:07:11] elomatreb: Those spammers still at it?


[15:09:09] elomatreb: Can you use the non-blocking operations for this?
[15:12:11] elomatreb: Mmh, isn't there a way to just give the subprocess your own stdout in the Open3 call?
[16:28:00] elomatreb: The answer would have been to collect/#to_a the enumerators in the block :s
[19:17:51] elomatreb: Two aspects: 1) Legally, obey the restrictions of the source license 2) socially, if it's just a minor change or something like that and/or the gem is still maintained, a pull request may be better
[19:19:31] elomatreb: If you've written the code, opening a pull request can't hurt. Although the owner doesn't appear too active
[19:22:23] elomatreb: The problem is more that if this project now becomes active again and adds a new feature, your two implementations have diverged and people who want to use the gem will have to choose.
[19:22:41] elomatreb: Esp. if you use the same toplevel namespace this is really annoying to deal with
[19:32:32] elomatreb: What would wrapping that get you over SecureRandom.uuid, if I may ask?
[20:17:28] elomatreb: baweaver: ^ heresy


[10:32:25] elomatreb: alex-kid: Generally you approach this kind of thing in Ruby by using default values for arguments, and selecting these so that all different behaviors are special cases of one general behavior
[10:33:49] elomatreb: This sadly is the downside of non-strict typing, as there is no consistent concept of signature in Ruby
[10:36:07] elomatreb: There are keyword arguments that work basically like named parameters, not sure what you mean by inner/outer
[10:38:28] elomatreb: No, Ruby does not have this
[10:41:05] elomatreb: You can't differentiate between named parameters and positionals (and optional vs. required) at runtime, you need to look at the source
[10:42:38] elomatreb: For methods that are defined in Ruby (i.e. not a native extension) you can look at Method#source to get their source code, and interpret that. But don't.


[07:33:41] elomatreb: ri is your friend, at least for pretty much anything in the standard library
[07:37:24] elomatreb: Did you build your Ruby without documentation by accident?
[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
[07:44:12] elomatreb: Syntax highlighting and a whole bunch of convenience features


[08:32:35] elomatreb: That's certainly a unique task, what's it for if you don't mind me asking?
[08:33:47] elomatreb: You could probably superficially ruby-ize it by using ranges/upto instead of the loops, but that's largely a cosmetic change


[18:56:28] elomatreb: Modify seems to be a lambda, [] is a way of calling the lambda with the passed parameter


[21:42:48] elomatreb: stevefink: Depends on what a_complex_object is, if it's a variable you will get an array that contains the same object multiple times
[21:42:59] elomatreb: But if it's a method that creates a new instance you will get new instances
[21:44:37] elomatreb: It should, but e.g. if you modify one element you will also modify all the others (since there's only one)
[21:49:52] elomatreb: No, that creates new strings :)


[19:41:12] elomatreb: They get put into a shared directory in your home dir somewhere, usually
[19:41:45] elomatreb: `gem uninstall gemname` uninstalls a gem, bundle install will then install it again
[19:45:10] elomatreb: What are you doing that's raising that error?
[19:45:46] elomatreb: If it's a bundle gem you may need to prefix with `bundle exec ` to get it to load your environment correctly
[19:49:18] elomatreb: You may have a look through the bundler docs (https://bundler.io/docs.html), but I don't know if there is a comprehensive article like that, sorry
[19:49:50] elomatreb: In short it basically forces the command after the exec to actually and only use the gems defined in the gemfile, as opposed to mixing and matching with other gems that just happen to also be installed on the machine
[19:53:28] elomatreb: havenwood: lol nice
[20:18:38] elomatreb: README: README.md
[20:22:19] elomatreb: two letters are always ccTLDs, yeah
[20:22:41] elomatreb: Except it's not actually the region that is getting the money, it's some shell corporation


[14:02:55] elomatreb: If you say so
[19:34:32] elomatreb: If it's refinement-based it's fine though? Use it if you want to


[00:07:00] elomatreb: *.net *.split
[00:15:40] elomatreb: has joined #ruby


[12:42:00] elomatreb: Although these are API docs mostly. They have examples usually, but it's not a coordinated overview of the language
[14:27:24] elomatreb: Isn't this like a dynamic programming version of knapsack?
[14:31:18] elomatreb: Is there some criterion by which you want the bottles to be selected?
[23:13:01] elomatreb: Why shouldn't it? send is a public method, after all
[23:13:56] elomatreb: public_send isn't private?
[23:14:42] elomatreb: >> "it's not".public_send :length
[23:19:53] elomatreb: Which probably isn't entirely uncommon, it's a convenient pattern e.g. for implementing a command-like system


[15:30:31] elomatreb: You could also look into something like pstore to get transactional security
[16:22:13] elomatreb: I feel like we should report this as a crime against *something*
[16:23:11] elomatreb: Honest advice: A preprocessor is most certainly not the solution you're looking for
[16:23:42] elomatreb: Post the actual problem you want to solve, and we can help (now it seems like you decided on a solution and want to know how to realize it)
[16:23:56] elomatreb: Alec: In the context of Ruby, I meant
[16:30:01] elomatreb: If we're talking code generation a proper, safe macro system is the way to go IMO, e.g. like Rust has


[10:45:47] elomatreb: The only *proper* way to do this is using a tool that doesn't allow this to happen, i.e. avoid shelling out with string interpolation
[10:50:01] elomatreb: If you just want to substitute characters something simple like String#tr is worth a look
[10:51:25] elomatreb: A blacklist of "dangerous" files will not work out in the long run, your OS protects the files
[10:56:42] elomatreb: I'm not quite sure what the problem you're worried about is btw. Are you creating files?
[11:03:44] elomatreb: And 0-bytes. And a bunch more depending on filesystem and/or platform (e.g. NTFS has an infinite number of illegal filenames)
[11:04:01] elomatreb: Or rather, NTFS as used by Windows
[11:05:01] elomatreb: Uh could you not throw slurs around like that please?
[11:08:44] elomatreb: leitz: Looking at your code, the worst that could happen is the user accidentally overwriting a file, but only if they have write access in the first place
[11:09:34] elomatreb: Usually in a case like this the best way to proceed is to print a warning and ask for confirmation, but you can't e.g. end up borking /etc/passwd because a regular user can't do that anyway
[11:11:12] elomatreb: Depending on the data you're storing you're often much better off with a database instead of files, also solves this problem
[11:12:41] elomatreb: But if you do need to store files the usual approach is to both sandbox your application as much as possible, and/or to store files in an "abstract" manner that doesn't directly translate to real-fs paths
[11:15:04] elomatreb: You also need to reject/remove slashes, otherwise you still end up accidentally references directories. E.g. your example will try to reference a directory called "Now_isnt_a_good_time_to_write_"
[11:18:03] elomatreb: Oh I missed the gsub, lol. That should cover most cases, but you could still end up with weird directories (e.g. `...` is a perfectly valid name, but looks really awkward and hides in ls output)
[11:19:55] elomatreb: Uh, yeah. Sorry, I've been up all night
[11:20:28] elomatreb: The more you escape/remove though, the more you need to worry about collisions
[11:25:58] elomatreb: Ruby is object-oriented in all aspects, but you see a lot of patterns that are often described as functional
[11:30:37] elomatreb: You technically can for sure, but defs outside of classes are no less object-oriented than with classes. They define methods on the implicit "main" object
[11:31:52] elomatreb: Your code will quickly become really spaghetti-y probably, but there's nothing stopping your from trying
[11:32:04] elomatreb: Not really no.
[11:33:02] elomatreb: 1. Any data structure is also a class, including the primitives like string and integers 2. Major difference to functional languages is that nothing prevents you from causing side effects
[11:38:04] elomatreb: Certainly, but don't be surprised when people mix and match approaches
[20:31:34] elomatreb: FernandoBasso: Yes, everything external needs a method, and attr_accessor will not work with class variables. Generally they're not want you want anyway though
[20:33:29] elomatreb: Yep, and `def foo=(value)` for the setter
[20:35:15] elomatreb: Beware of the slightly weird behavior of class variables when combined with inheritance btw


[03:13:29] elomatreb: JJonah: You could abuse Array#flatten, that gets you a relatively simple solution
[03:14:36] elomatreb: Something like https://eval.in/1036353
[03:20:46] elomatreb: Complexity should be something like O(n*m) where n is the totally flattened array size and m is the nesting depth
[03:37:46] elomatreb: Oh that's even better
[03:50:45] elomatreb: evdubs: That gets very difficult. You could instead try a metaprogramming-based solution, e.g. with the method_added hook


[02:43:50] elomatreb: evdubs_: You can write a log method that runs a block, and based on the log level decides not to run the block
[02:44:45] elomatreb: That just controls printing though, if you do `Log.debug expensive_method_call` it will still run the method even if it won't print the output
[02:46:08] elomatreb: Oh, logger actually supports the technique I mentioned: https://ruby-doc.org/stdlib-2.4.0/libdoc/logger/rdoc/Logger.html#class-Logger-label-How+to+log+a+message
[02:46:32] elomatreb: The block form is what you want
[02:46:50] elomatreb: It won't do as much optimization as in Java, but it'll still save you the method call
[04:29:06] elomatreb: memo1: You can access the environment variables with the ENV global (e.g. `ENV["HOME"]`)
[23:38:22] elomatreb: But for playing around a local repl is probably more useful
[23:39:06] elomatreb: It wraps your input, click the link to see how
[23:41:55] elomatreb: Not sure, sorry. There are some other books linked in the topic, but I don't know if they check that box
[23:42:51] elomatreb: I doubt that exists, rubys grammar is notoriously horrifying
[23:44:37] elomatreb: If you want to play around check out https://github.com/pry/pry


[21:19:35] elomatreb: Feels like a weird special case for how rarely they're used
[21:22:17] elomatreb: You'd probably have to restrict it to literals (i.e. no variables/expressions) in order to keep it at least a little unambigous


[09:50:16] elomatreb: Ping timeout: 256 seconds
[10:20:52] elomatreb: has joined #ruby


[01:58:57] elomatreb: You can break across lines and indent, if it helps readability go for it
[16:56:43] elomatreb: Generally finalizers are a very fragile way to deal with resources, Ruby prefers you use explicit management (e.g. blocks) where applicable
[19:03:27] elomatreb: cthulchu: About the ordering part? Unless you have parallel code that is breaking assumptions the ordering guarantee is reliable


[14:10:47] elomatreb: Making a name uppercase gives it constant-like treatment in Ruby, you can assign anything to local variables (lowercase names) too but it's kind of useless
[14:23:14] elomatreb: Because Ruby ifs don't work like preprocessor ifs.
[14:23:50] elomatreb: If you want to achieve what you can assign like `h["modifiers"] = ...` in an if after the hash initialization
[14:25:18] elomatreb: modified yours: https://hastebin.com/toyaxezeve.rb
[14:25:47] elomatreb: It doesn't add it if the condition isn't met, yeah
[14:26:38] elomatreb: In general this seems like a kind of dirty approach though, is there a good reason you can't just always have the key and just set it to the value, and ignore it later if it is nil?
[14:27:31] elomatreb: Ruby will automatically remove null fields
[14:27:39] elomatreb: The JSON serializer, that is
[14:28:23] elomatreb: Yeah I misread, sorry
[14:28:39] elomatreb: And you have a schema to conform to?
[15:33:56] elomatreb: You can, but in order to specify to_modifiers you also have to provide some value for from_mandatory_modifiers
[15:34:11] elomatreb: Alternatively you can use keyword arguments if you want specifying one but not the other to be convenient


[16:23:53] elomatreb: Esp. the very recent versions are very worthwhile for server use because of their performance gains
[16:25:23] elomatreb: And ruby maintenance is very genereous compared to other projects, e.g. 1.8.7 was supported for like 5 years?
[16:26:50] elomatreb: Aren't you paying Redhat for backport support? People here are here on their free time
[16:32:57] elomatreb: Arguably the problem here isn't ruby, but the promises that OSes make about stability that really don't hold true
[16:33:17] elomatreb: Because even if you backport ruby fixes, the library you may depend on probably won't receive this treatment


[14:01:21] elomatreb: Doesn't #text do that?
[14:24:20] elomatreb: The standard library contains a pretty good CSV library
[14:29:44] elomatreb: Web site crimes
[14:41:19] elomatreb: Quit: ZNC - https://znc.in
[14:42:11] elomatreb: has joined #ruby
[17:18:26] elomatreb: canurabus: Still relevant?
[17:52:00] elomatreb: On the other hand, IPAddr can also deal correctly with IPv6 addresses
[17:58:12] elomatreb: And the difference between the hex number and the dotted-decimal notation is really just notational convention, they all just represent a 32-bit integer
[17:59:14] elomatreb: dotted-decimal used to be more relevant when we had subnet classes, but CIDR subnets don't have to stick to the "boundaries" it shows
[18:02:52] elomatreb: Ruby syntax allows you to leave the parentheses off method calls, '55'.hex is equivalent to '55'.hex(), which may be a little more familiar if you're coming from other languages
[20:05:13] elomatreb: Ruby itself does not offer any async features beyond bare threads, you'll want to check out a gem like concurrent-ruby that offers e.g. a Promise implementation
[20:15:45] elomatreb: Or too many records :P
[22:45:02] elomatreb: If you want a Ruby-like syntax that compiles to what I think you mean you might check out Crystal
[22:48:52] elomatreb: I can't really help with that, sorry
[22:52:45] elomatreb: Lisp used up the Strategic Parentheses Reserve


[16:31:50] elomatreb: Line 1 is where pretty much all the magic happens in this specific example
[16:32:34] elomatreb: Right, the block (the part between { and }) is run once for each value from books
[16:33:28] elomatreb: That depends on the setting of your example. You're effectively counting how often each value in books occurs
[16:34:22] elomatreb: (Where rate is the current value from books for which the block is run)
[16:35:12] elomatreb: You don't need to put it into the Hash as you defined a default value in line one
[16:35:38] elomatreb: The default value gets used when you try to access a key that doesn't exist, and since += assigns it will create the key
[16:36:38] elomatreb: Yep. More correctly, it runs the block (the curly braces) each time you access an undefined key and uses its return value, you can do anything in it
[16:37:29] elomatreb: For an exhaustive overview of what Hash.new can do: https://ruby-doc.org/core-2.5.1/Hash.html#method-c-new
[16:38:36] elomatreb: It is iterating through the list, that's the .each part of line 3
[16:40:08] elomatreb: You are iterating over books.values, which is a plain Array
[16:40:31] elomatreb: Try inserting `p books.values` to see the data you're dealing with
[16:43:53] elomatreb: I assume books is given by the example? It's probably a hash, which means it's a collection of key-value pairs where the keys are unique
[16:44:19] elomatreb: Calling .values on it goes through it and gives you all the values (without the keys) in a big list
[16:45:12] elomatreb: You said you know Python? Hashes are the Ruby equivalent of dictionaries
[16:48:51] elomatreb: Pretty much, yeah
[16:49:10] elomatreb: You can use any type of object as keys and values, e.g. strings and symbols are commonly used
[16:51:08] elomatreb: Just assigning different values to a single key overwrites, so to actually store multiple values you'd need to use an array as the value
[16:51:34] elomatreb: You can also nest Hashes, but at a certain point it makes more sense to construct a proper class for your objects


[13:17:42] elomatreb: Not exactly true, iterator blocks get yielded an array of two elements, it just gets destructured when you put two parameters on the block
[13:35:02] elomatreb: You can use this anywhere btw, e.g. `a, b = [1, 2]` assigns 1 to a and 2 to b
[14:11:53] elomatreb: Alternatively there is File.ftype
[16:37:16] elomatreb: bsamorim: The scope in which a block is executed is lexical to where the block is located, from where you do block.call does not change it
[16:38:02] elomatreb: You can change the receiver object (self) through things like instance_eval, but it's kind of a bad idea because it's not apparent at the call site
[16:44:09] elomatreb: You're probably making some assumption about scope somewhere. If you could show actual code instead of a reduced example it's usually much easier to help
[16:48:34] elomatreb: My gut feeling would be the code inside the actual block
[16:59:35] elomatreb: Try inserting `p self` to see where your methods are going, if there's confusion about that
[17:02:05] elomatreb: Oh you can't create anonymous gists anymore?
[17:03:07] elomatreb: Might be worth considering to recommend another service in that case, requiring people to have a github account does seem inappropriate
[17:03:58] elomatreb: I would if I could :/
[17:05:55] elomatreb: And the request in print_request is what's being messed up?
[17:07:02] elomatreb: In that case it gets class_evald apparently
[17:07:28] elomatreb: What happens if you change `def print_request` to `def self.print_request`?
[17:08:27] elomatreb: This feels more like a strange behavior from Sinatra, I can't really help with that, sorry
[17:13:24] elomatreb: It changes the self in the block
[17:13:48] elomatreb: So all the methods you call end up being called on the object you want, instead of the the lexical default from the blocks location
[17:15:12] elomatreb: Which makes building things like DSLs convenient, but you also can't see that it's happening just from looking at the block itself, so it can be very confusing if you e.g. get NoMethodErrors for methods that you defined just above (similar to the confusion you got)


[22:34:53] elomatreb: You'll exhaust the Strategic Newline Reserve
[22:47:59] elomatreb: Give each issue a UUID