kke

Activity Graph

Page 1 of 3 | Next »

2019-08-22

[00:56:35] kke: *.net *.split
[01:13:38] kke: has joined #ruby

2019-05-08

[07:29:48] kke: String#add_prefix that would be the inverse of delete_prefix would be nice sometimes. 'foo'.add_prefix('/') => '/foo'.add_prefix('/') => '/foo'
[07:34:27] kke: depesz: yes, but not as pretty
[07:43:48] kke: al2o3-cr: yes, but '/foo'.prepend(?/) => '//foo'
[07:44:12] kke: i was looking for adding it if it's not there without "unless str.start_with"
[07:46:43] kke: anyway, prepend is better than the `str.start_with?('/') ? "/#{str}" : str` that the method has now
[07:52:53] kke: yes, but still not as elegant as "foo bar".delete_prefix('foo ') ==> 'bar'.delete_prefix('foo ') ==> 'bar'
[08:02:33] kke: not to cause any battles, but i wasn't even asking for a solution, i was just thinking there could be add_prefix that would do the opposite of what delete_prefix does. (and _suffix)
[08:14:25] kke: yes, i know there is. that is where this thread started. "would be handy if there was add_prefix like there is delete_prefix", i don't know why the conversation went south from there.
[08:17:57] kke: https://dpaste.de/3hBa
[08:42:23] kke: could be, but it returns what was expected. in any case, when dealing with leading/trailing '/', you can just do File.join('/', *parts, '/'), it will add any missing leading and trailing slashes.
[08:43:29] kke: i suppose that will blow up if File::SEPARATOR is different
[08:44:19] kke: docs seem to suggest otherwise: "Returns a new string formed by joining the strings using "/".
[08:47:55] kke: i specifically want / so plain File.join is good

2019-03-30

[11:23:58] kke: has joined #ruby

2019-03-26

[11:32:59] kke: Thread.pass until threads.none?(&:alive?) <-- eats all the cpu. sleep 0.1 until threads.none?(&:alive?) <-- does not eat the cpu.
[11:39:15] kke: 0.1 of course is a long time in this time of technology

2019-03-15

[13:58:14] kke: is there some neat way to "cyclically" (rolling?) get an item from an array? like let's say i have KEY = [1, 2, 3, 4, 5]. something clever to make something like KEY.cyclical(5) point to KEY[0], KEY.cyclical(6) to KEY[1], KEY.cyclical(11) to KEY[0]
[13:58:47] kke: well that method shouldn't be that difficult. i'm just thinking there's probably some trick i can't think of how this could be done with science.
[14:03:02] kke: phaul: ah, that's the trick i was looking for :)

2019-03-13

[11:31:45] kke: today i learned: def foo(*args, **options) when called like foo(Bar.new) without options, calls respond_to?(:to_hash) && .to_hash on the Bar.new and if it can become a hash, it does, and ends up in options instead of args.
[11:32:07] kke: when can that be useful?
[11:32:50] kke: can it be avoided without sending an empty hash?
[11:43:52] kke: maybe it can be useful if you have something like `HashWithIndifferentAccess` or such. mostly i think it's more bad than good.
[11:59:34] kke: or you mostly expect it not to do that and it gives you headache, the times you want it to do that are probably like 1 in 1000 and you could just as well handle that in your method.
[13:43:10] kke: does not require **options either. this does the same: def display(*items, color: false) if you call that with something like display(item_that_has_to_hash) you will get ArgumentError unknown keyword arguments: x, y, z
[13:46:24] kke: Bish: there are lots of those, the short versions are explicit, and long versions are implicit. (to_h, to_hash, to_a, to_ary, to_s, to_str, to_i, to_int). the long version is supposed to be implemented in objects that can be converted back and forth i suppose.

2019-03-08

[12:27:03] kke: solarized dark for everything

2019-03-06

[11:30:34] kke: does someone use ThreadGroup for something and why?
[11:46:14] kke: c-c: compared to a regular array, it only seems to give threads `Thread.current.group` accessor. group = []; group << Thread.new(group) { |group| Thread.current[:group] = group; # do stuff };
[11:47:26] kke: it could somehow interface with ThreadsWait but it doesn't.
[12:12:21] kke: ok that makes sense
[12:13:14] kke: i would still expect the group to have some methods like group.alive? instead of having to do group.list.any?(&:alive?)

2019-02-20

[08:39:00] kke: with frozen string literals, i don't get why `key = "foo"; "#{key}".frozen?` ==> true
[08:39:30] kke: even "#{key.reverse}".frozen? == true

2019-02-07

[07:40:42] kke: best way to make a singleton method that won't be inherited?
[07:49:51] kke: yeah maybe i'll just move the method somewhere else from the superclass

2019-02-01

[11:51:01] kke: ["abc.def", "ghi.jkl"].map(&:split['.']) i wonder why this returns an enumerator? (i know it doesn't work, i just got curious if the proc[] thing could be used to pass an argument for symbol to proc)
[11:52:29] kke: (would be handy.)
[12:01:57] kke: why does symbol even have []
[12:09:42] kke: yeah it does, sym also has .downcase, .match and whatever
[12:10:20] kke: so i suppose &:split['.'] did some sort of &nil

2018-09-03

[19:10:26] kke: *.net *.split

2018-08-29

[06:43:32] kke: very annoying that when you google for some stdlib class it always links you to some antique version, usually 1.9.3.
[06:45:15] kke: heh, and the same happens if you search for something like "tempfile" in ruby-doc.com. the first result is 1.9.3
[06:45:38] kke: oh, it's using google for searches too.
[06:52:22] kke: yeah, just requires retraining the muscle memory
[06:52:59] kke: devdocs doesn't have 2.5 at all yet
[06:54:15] kke: you added it? :D
[06:55:35] kke: i haven't been there for months or maybe years
[06:55:43] kke: stupid cache.
[06:56:19] kke: well i suppose they should change the etag for the category list when it is updated

2018-08-21

[07:09:50] kke: klass1 = Class.new { FOO = :bar }; klass2 = Class.new { FOO = :bar } <-- this gives "warning: already initialized constant FOO". can't anonymous classes have private constants?
[07:12:38] kke: and by "private" i mean "their own"
[08:03:42] kke: radar: dynamic loading of stuff with a light DSL, something like `Addon.describe "addon_name" { def execute { } }`. I think i need to do something fancier than `Class.new(AddonBase, &block)` to allow them to have their own constants :(
[08:10:15] kke: maybe: `klass = Class.new(AddonBase); Addons.const_set(klassify(name), klass); klass.class_exec(&block)`
[08:11:32] kke: hey i think it worked
[08:14:45] kke: no it did not.
[08:23:33] kke: maybe i can trick the block binding
[08:52:11] kke: rindolf: when using bundle, you can't use any gems that are not listed in the gemfile. so if you `gem install bigdecimal` and then do `bundle exec bin/validate`, it doesn't see the bigdecimal because it's not listed in the gemfile.
[08:57:29] kke: Bish: yes, config.ru and ball sucking are things that constantly appear together. "rackup" joins in occasionally.
[10:00:42] kke: hmm do i have to use some sort of ruby2ruby thing then. or somehow try to snatch the source using block.source_location and class_eval that as a string
[10:00:49] kke: no, can't use the block at all

2018-07-26

[08:40:14] kke: has joined #ruby
[08:40:14] kke: Changing host

2018-07-20

[00:07:25] kke: *.net *.split
[00:15:50] kke: has joined #ruby

2018-05-29

[02:47:12] kke: *.net *.split
[02:48:04] kke: has joined #ruby
[11:06:32] kke: class Foo < BasicObject; def Kernel(*_); nil; end; end; Foo.new.instance_exec { Kernel.puts(Kernel.send(:`, "ls")) } i wonder why this doesn't work as expected. (just thinking if i could make a somewhat secure variable container to be sent to template rendering)
[11:07:57] kke: i would expect it to say NoMethodError no method `puts` for NilClass but it puts the output of `ls`.
[11:08:26] kke: oh. is there something that does?
[11:10:05] kke: i also tried const_set :Kernel, nil
[11:10:16] kke: but of course even then you could do ::Kernel
[11:11:25] kke: for the lulz mostly
[11:14:22] kke: i would be using it for a cli thing that processes ERB locally, it would be nice if i could sandbox it
[11:14:45] kke: because the erb can come from somewhere online

2018-05-23

[12:03:48] kke: why no YAML.safe_load_stream?
[12:21:56] kke: everything worth asking has been asked and you can find your answer quickly using google because of the amount of available material
[12:28:49] kke: there's no answer to my earlier question either.
[12:30:36] kke: there's YAML.parse_stream which returns stuff like Psych::Nodes::Document, which each have .to_ruby and .to_yaml. i thought i maybe could have done something like YAML.safe_load(doc.to_yaml) but the .to_yaml raises RuntimeError (expected STREAM-START)
[12:35:47] kke: i guess i need to split the yaml myself
[12:36:09] kke: or be unsafe, i guess that's an option, as my app also processes .erb

2018-05-14

[09:04:01] kke: Ping timeout: 248 seconds
[09:05:49] kke: has joined #ruby

2018-05-09

[09:03:18] kke: any trick to find out source location when subclassing? (somethin in self.iherited maybe)
[09:13:21] kke: well caller.first and split(/(?<=\.rb):/) maybe
[09:16:58] kke: the source_location of the known methods is the parent_class.rb
[09:19:12] kke: use case is some sort of "addon system", something like "$DIR/addons/xyz-xyz/addon.rb" that goes like "class FooAddon < Addon" but the superclass needs to know the source location so that it can do something like "def resource_files { Dir.glob(File.join(__dir__, 'resources', '*.yml')) }"
[09:20:33] kke: i couldn't figure out a way to use Method.source_location unless there is a method that has to be defined in the child class
[09:21:48] kke: yep, that's why i thought it could be determined when the inheriting happens
[09:22:21] kke: yep, seems dirty.
[09:24:26] kke: better ideas?
[09:25:26] kke: at that point it could inject the location
[09:28:33] kke: but then it would also have to know the class name

2018-05-04

[08:52:08] kke: lately i've run a couple of times into a situation where bundler happily installs incompatible dependencies and everything seems to work fine, but then doing gem build + gem install for the thing fails because of unresolvable deps. seems weird to me that bundler does not complain.

2018-04-26

[02:12:54] kke: Ping timeout: 256 seconds

2018-04-25

[12:25:57] kke: *.net *.split
[12:27:25] kke: has joined #ruby
[15:01:28] kke: *.net *.split
[15:03:10] kke: has joined #ruby

2018-04-23

[08:36:04] kke: it's me
[08:36:35] kke: nothing intereting about me, wonder what was up with him
[09:02:59] kke: has joined #ruby
[09:02:59] kke: Changing host
[10:53:12] kke: (that also happens with 1234[nil] or "foo"[nil])
[11:58:53] kke: i think your ri seems to work fine
[12:00:30] kke: saTchymoto: probably something like 'ri puts' works. upscale is probably a method in some module/gem you're using and you need to do something like 'ri Foofoo.upscale'
[12:01:52] kke: i've used ruby since something like 2001 and never touched ri.
[12:06:03] kke: looks like someone had the same problem on stackoverflow but nobody answered
[12:06:22] kke: you could switch to ruby 2.3
[12:07:55] kke: saTchymoto: did you try https://stackoverflow.com/a/45741781/681520 ?
[12:09:37] kke: some answer said that windows ruby installer includes windows help chm files of the stdlib
[12:15:22] kke: i think you can just double click .chm's and you get some strange user interface for searching and browsing, but of course it's not the same experience.
[12:17:18] kke: saTchymoto: that link does not tell you to copy anything to your ruby dir. it tells you to download a ruby source code .zip from github, extract it somewhere, go into that directory and type "rdoc --all --ri" after which you can remove that directory + zip.
[12:17:51] kke: and you will just download one file, not a ton of files.

2018-04-20

[10:11:08] kke: hmm, bundle goes through ok, so does gem build, but gem install complains about unresolved specs

2018-04-06

[08:01:36] kke: if i have an instance of Bar::Foo, is there some pretty way to do something like `foo.is_a?(Bar::*)` that is not `.to_s.split('::').first == 'Bar' `

2018-04-05

[09:10:38] kke: weird. Pathname.new('/tmp').glob('*') says undefined method glob for #<Pathname..> on 2.4.2 but not on 2.5.1. from the docs it looks like it was already there at least in 2.1.0.
[09:14:12] kke: ah, yeah, right
[09:14:17] kke: so it is a 2.5 addition then after all
[09:16:37] kke: looks like Pathname.glob('/tmp/*') does pretty much the same thing so that will have to do.
[12:29:52] kke: Logger.new($stdout).instance_variable_get(:@logdev).dev.isatty <-- must be a prettier way
[12:31:31] kke: but i can't find any accessor for the log device in logger
[12:35:05] kke: probably better yeah
[12:36:22] kke: also it could just be some "logger-compatible" object which does not have the same internals, so .instance_variable_get is going to break

2018-03-28

[08:09:19] kke: hmm. bundler fails to fetch gems due to timeout, the url it displays downloads just fine on the same machine using browser. anyone else having problems with it?
[08:09:57] kke: Retrying download gem from https://rubygems.org/ due to error (2/4): Gem::RemoteFetcher::UnknownHostError timed out (https://rubygems.org/gems/byebug-10.0.1.gem)
[08:12:46] kke: using gem 'byebug', github: 'deivid-rodriguez/byebug' works fine
[08:13:26] kke: and bundler has been working fine on this machine forever

2018-03-20

[12:36:47] kke: what's prettier than self.class.method_name?

2018-03-19

[21:23:46] kke: what's the most awesomely written web service api wrapper you ever saw? (looking for inspiration)
[21:39:35] kke: perhaps leaning towards droplet_kit in my current research
[21:40:55] kke: to Float::INFINITY and beyond
[21:41:41] kke: there's also Float::NaN
[21:43:56] kke: conceivably: maybe because floating point math is so weird. 0.0 could also be 0.00000....00000000234 but you just don't have enough precision
[21:44:47] kke: let's get those bastards
[21:57:52] kke: of course they had a reason to demand that
[22:00:59] kke: >> 1 / 1.0e-308
[22:01:16] kke: ok then.
[22:01:29] kke: 309 gives float::infinity on my machine, so that you know.

2018-03-09

[09:38:19] kke: could there be some clever way to make unknown_local_variable_or_method || "hello" to return hello instead of raising NameError?
[10:05:00] kke: hmm actually i just want an instance of NilClass that has to_s that raises
[10:05:24] kke: and i know there's several things wrong in the whole concept of that :D
[10:06:24] kke: but is this doable? could i do the equivalent of foo = nil; foo.extend(NotStringable)
[10:08:29] kke: dminuoso: i'm trying to create a sort of a Namespace for erb binding. I would like to have something like <%= some_var || "default_value" %> and <% some_var ||= 'default_value' %> working, but raise a NameError, "unknown local variable or method X" for something like <%= some_var %> if it's not defined
[10:09:54] kke: so in essence, i think, having a nil that is not to_s:able
[10:11:12] kke: currently i have something like def method_missing(meth, *args) NilObject.new(meth) end and that works for everything except for the <%= some_var || "default_value" %> (of course there may be some other non working cases i haven't thought of yet)
[10:11:53] kke: where nilobject is a class that has def nil? { true } and def to_s { raise NameError }
[10:12:35] kke: and the namespace thing is kind of derived from the answer in https://stackoverflow.com/a/5462069/681520
[11:15:09] kke: mostly refering to things like "an instance of NilClass"

2018-03-02

[10:25:32] kke: can i do something like data = 'abcd'; EM.defer(proc { process(data) }) or is the scope of data messed up there?

2018-02-27

[13:44:58] kke: i wonder why the monitormixin module documentation examples call things with self like "self.synchronize do .." http://ruby-doc.org/stdlib-2.5.0/libdoc/monitor/rdoc/MonitorMixin.html
[13:47:38] kke: also i wonder why my class with include MonitorMixin gives undefined method `lock' for nil:NilClass when trying to synchronize { ... }
[13:49:03] kke: ah, maybe because i don't call super in initialize
[13:49:42] kke: yes, that is why.
[13:50:19] kke: string.gsub('n', '\n')
[13:51:58] kke: cork didn't speak anything about linefeeds, his quotes were for style :)

2018-02-23

[08:33:34] kke: has joined #ruby

2018-02-22

[10:57:57] kke: Ping timeout: 264 seconds
[10:59:13] kke: Ping timeout: 264 seconds
[10:59:58] kke: has joined #ruby

2018-02-09

[14:15:12] kke: is there some thread safe shared hash-like thing that can be used with eventmachine?
[14:25:28] kke: hmm, right, so i can use Concurrent::Hash without using the rest of the concurrent-ruby package

2018-01-18

[10:00:29] kke: Remote host closed the connection
[10:32:38] kke: has joined #ruby

2018-01-11

[07:02:05] kke: Changing host
[07:02:06] kke: has joined #ruby

2018-01-10

[23:53:28] kke: Ping timeout: 268 seconds
[23:54:10] kke: has joined #ruby

2018-01-05

[09:28:41] kke: has joined #ruby
[09:28:41] kke: Changing host

2018-01-04

[01:12:47] kke: Ping timeout: 276 seconds
[01:14:07] kke: has joined #ruby

2017-12-12

[10:31:29] kke: has joined #ruby
[10:32:00] kke: has joined #ruby
[10:32:00] kke: Changing host
[10:33:21] kke: any ideas how you can order by a composite column in sequel? like Items.order("version.major")
[10:54:58] kke: Items.order("(version).major") does not work either
[10:55:58] kke: Sequel::DatabaseError: PG::SyntaxError: ERROR: non-integer constant in ORDER BY "ORDER BY '(version)..."

2017-12-09

[05:06:26] kke: *.net *.split
[05:14:00] kke: has joined #ruby

2017-12-07

[14:48:36] kke: *.net *.split
[14:55:10] kke: has joined #ruby

2017-12-01

[02:29:00] kke: has joined #ruby

2017-10-23

[05:55:16] kke: has joined #ruby

2017-10-21

[19:18:08] kke: Remote host closed the connection

2017-09-07

[05:46:44] kke: ruby could just drop class variables, i don't see any use for them
[05:46:54] kke: oh i'm 9 hours late from the discussion

2017-09-06

[12:35:30] kke: rahul_bajaj: it's defined in http://www.rubydoc.info/github/theforeman/foreman/Api/V2/BaseController
[12:36:19] kke: i think.
[12:42:41] kke: could be some rails thing. no idea really.
[12:44:54] kke: it comes from apipie
[12:45:47] kke: rahul_bajaj: https://github.com/Apipie/apipie-rails#dsl-reference
[12:46:31] kke: so it's for api documentation and perhaps parameter validation

2017-08-25

[06:56:17] kke: has joined #ruby
[07:04:57] kke: what would be the most sane way these days to have something like def parser { @parser ||= Parser.for(input) }, currently i'm using inheritance with automatic registration upon require by using Parser.self.inherited(where) { parsers << where } .. but i have a hunch that something like this is not 2017 ruby.
[07:11:43] kke: of course i could convert them to modules and have some kind of Parser.register(FooParser) in the end
[07:12:30] kke: or scan constants under some namespace

2017-08-11

[02:14:46] kke: has joined #ruby

2017-06-27

[09:02:02] kke: has joined #ruby
[09:02:02] kke: Changing host
[09:35:03] kke: *.net *.split

2017-06-20

[00:22:44] kke: has joined #ruby

2017-05-31

[09:01:06] kke: *.net *.split

2017-05-30

[09:55:18] kke: how would i make my own Foo("123") coercer thing, like Integer("123"), Array(foo), etc?
[09:56:25] kke: monkeypatching Object i guess
[09:59:26] kke: or Kernel. isn't that what you are monkeypatching if you run `def foo` from main?
[10:00:25] kke: >> def foo; puts "bar"; end; Kernel.method(:foo).call
[10:04:46] kke: looks like Array() String() etc are defined as methods in Kernel https://ruby-doc.org/core-2.4.1/Kernel.html#method-i-Array
[10:07:43] kke: unless you're `load`ing the file
[10:07:51] kke: from some strange context
[10:08:09] kke: i think
[13:15:52] kke: yes. just hypothesising.
[13:28:44] kke: apeiros: looks clean and nice.

2017-05-26

[08:38:32] kke: what kind of pattern/composition would you use for something like Food.new(state: :ordered) that requires several steps before reaching state == :finished, such as obtain_ingredients, cook, put_on_a_plate, etc? the steps can take some time and are performed by some background workers.
[09:20:54] kke: that's what i'm trying to avoid. i think i'm going to use AASM or statesman, but i think what i actually would like is a workflow engine, but seems like there aren't any good candidates
[12:10:11] kke: looks like i don't like AASM or statesman either
[12:20:24] kke: aasm readme claims it's thread safe
[12:21:11] kke: i was planning to use sucker_punch to run concurrent-ruby based workers
[12:23:13] kke: i thought it would be a pretty common problem and would have been solved a zillion times already
[12:25:58] kke: something to script a multi stage job

2017-05-22

[22:13:40] kke: Ping timeout: 240 seconds
[22:13:47] kke: has joined #ruby

2017-05-16

[11:24:48] kke: hmm what's this: def border(options=(not_set=true)
[11:25:56] kke: keyword argument defaulting?
[11:28:41] kke: no. something even more exotic.
[11:31:51] kke: border('foo') --> options == 'foo', not_set = nil border() --> options = true, not_set = true.

2017-05-12

[08:57:03] kke: >> arr = ['foo']; arr.insert('bar'); arr
[08:57:28] kke: i don't know why it doesn't raise or something
[08:57:44] kke: (insert should require the position argument)
[09:04:07] kke: the source seems to do pos = NUM2LONG(argv[0]);
[09:05:58] kke: "If x is not a Fixnum , Float , or Bignum object, it attempts to implicit type conversion by x.to_int."
[09:08:06] kke: i wonder why that is there
[09:08:20] kke: >> [].insert(Exception.new)
[09:08:51] kke: i think it should raise something if the first arg is bogus
[09:09:37] kke: yep but that would have catched a syntax error in my code
[12:59:45] kke: args = args.first if args.first.is_a?(Array) <-- i find myself doing a lot of something like this with methods that take splats
[12:59:53] kke: maybe i'm doing it wrong.

2017-04-13

[15:10:51] kke: *.net *.split

2017-04-12

[13:37:34] kke: all of the other methods say "you must require 'io/console' to use this method"
[13:38:01] kke: so that one should say "you must require io/console/size etc"
[13:38:13] kke: well of course it could very well be in io/console