#ruby - 24 January 2018
« Back 1 day Forward 1 day »
[02:27:21] malwar3hun73r: LoadError: incompatible library version - /.../bundle/ruby/2.3.0/gems/mysql2-0.4.4/lib/mysql2/mysql2.so
[02:41:22] havenwood: malwar3hun73r: If that doesn't do the trick, turn it off and back on again (start a fresh shell): exec "$SHELL" --login
[03:10:46] nchambers: is EventMachine.Connection#start_tls the proper way to establish a tls connection with a client/server?
[03:37:00] malwar3hun73r: havenwood, it seems the issue could be that gem install mysql2 installs mysql2-0.4.10 and the error is for mysql2-0.4.4
[07:24:13] za1b1tsu: anyway I can print the reference? For ex x = "Hello", can I print the actual x value, the reference to "Hello"?
[07:46:45] al2o3-cr: 1) [x].pack('p').unpack('l!') 2) Fiddle::Pointer[x].to_i 3) Fiddle::Pointer[Fiddle.dlwrap(x)].to_i 4) x.object_id << 1 || * 2
[08:46:15] havenwood: >> require 'fiddle'; require 'json'; require 'objspace'; x = 'Hello'; [JSON.parse(ObjectSpace.dump(x))['address'].hex, x.object_id << 1, Fiddle.dlwrap(x), [x].pack('p').unpack('l!').first - 16]
[08:46:16] ruby[bot]: havenwood: # => [1106940300, 1106940300, 1106940300, 1106940292] (https://eval.in/941104)
[08:47:48] havenwood: >> require 'fiddle'; require 'json'; require 'objspace'; x = 'Hello'; [JSON.parse(ObjectSpace.dump(x))['address'].hex, x.object_id << 1, Fiddle.dlwrap(x), [x].pack('p').unpack('l!').first - 8]
[08:47:49] ruby[bot]: havenwood: # => [1106825400, 1106825400, 1106825400, 1106825400] (https://eval.in/941106)
[09:05:37] bawNg: https://www.neowin.net/news/linus-torvalds-calls-intels-meltdown-and-spectre-patches-garbage
[09:40:36] al2o3-cr: suprisingly String#unpack1('Z*') is significantly faster the String#delete("\x00")
[09:42:18] apeiros: eh, depending on your use case, even worse, it'll truncate your string after the first null byte
[09:42:48] apeiros: or more correctly, before the first null byte :) (since the null byte is removed too)
[10:14:42] apeiros: al2o3-cr: e.g. if you have a format which says "5 null-padded fields, first field is 10 bytes, second 20 bytes, the other three 8 bytes", then you can just do: fields = binary_data.unpack("Z10Z20Z8Z8Z8") and it'll do "the right thing"™
[11:09:00] dminuoso: I dont know whether we have some "tell" command and you didn't seem to respond, so.. =)
[11:17:02] dminuoso: adaedra: I was asking you to upgrade `derpy to 2.5 whenever you found the time. :)
[13:03:49] malwar3hun73r: when running rake assets:precompile, i get the error "LoadError: incompatible library version - /var/www/.../vendor/bundle/ruby/2.3.0/gems/mysql2-0.4.4/lib/mysql2/mysql2.so"
[13:06:46] apeiros: so seems like your mysql gem is vendored. you'd need to recompile/update that one
[13:08:46] apeiros: hm, can't find meaningful info regarding that. haven't used vendored gems in ages :-/
[13:09:17] apeiros: I *think* in the worst case you could just delete the entire vendor dir (I'd move it away instead of deleting, though)
[15:01:08] tcopeland: dminuoso: (continuing from yesterday) true, static analysis could find that case - I am more aiming for trying to explore runtime analysis for code improvements
[15:23:03] impermanence: How can I grab a .deb or .dpkg or whatever is used in debian, not install it, but still be able to compare it to another installation?
[15:33:46] apeiros: impermanence: it's terrible! you interrupted dozens of very engaged discussions! and now all fell silent! terrible I tell you! ;-)
[15:36:33] hays: I found found myself in the unfortunate situation of using syslog/logger and needing compatibility with 1.9.x Ruby. Anyone know of a way to backport this easily?
[15:39:30] hays: heh, funny ruby-installed doesn't even have 1.9.x available so not sure how I would test this. grr.
[15:43:15] hays: this is great--now I just need to figure out how to install 1.9.x on my mac to test it haha
[15:49:30] hays: Oh. OK. Well I think we found a solution. I was assuming I had 2.x everywhere I needed, and used a feature of syslog that was introduced in the 2.x series. Its a logger interface to syslog (require 'syslog/logger').
[15:50:03] hays: So aperios helped me find the source code to logger.rb and it looks pretty straightforward. Also I found a backports gem that might help
[15:53:26] hays: anyone here use a mac? trying to determine best way to get an old unsupported ruby. Right now I use ruby-install and chruby to manage my rubies
[15:54:57] apeiros: still mainly because it's what I started with and never really had a problem with it
[15:55:41] hays: I am showing my age but I am way behind on understanding the subtleties and differences between these methods
[15:55:53] apeiros: it might be that rvm uses ruby-installer to install ruby. at least I remember that they intended to do that.
[16:00:57] hays: its a bit manual, but you can navigate to https://cache.ruby-lang.org/pub/ruby/ and find the tarball, and then pass that into ruby-install. seems like that might work. building right now
[16:45:25] Hanmac1: "ruby code hurt my eyes so i need |> and <|" https://bugs.ruby-lang.org/issues/14392
[16:46:50] WA9ACE: in the mean time I made this https://github.com/WA9ACE/pipe/blob/master/spec/pipe_spec.rb
[16:52:33] Hanmac1: i think i once made a gist so i can use &:to_s.(2) https://gist.github.com/Hanmac/ab77c649d799ade9670c
[17:06:48] nchambers: if I wanted to dynamically load a folder of ruby files at runtime (without knowing their names in advance, eg for a plugin system), and call a module function in each of them (something like Plugin::onload), how would I do that?
[17:10:24] apeiros_: nchambers: filenames are not linked to constants defined in them. so you either have a convention (filename <-> constant name mapping) or a registry
[17:11:46] apeiros: registry itself can be either explicit like `class MyPlugin; end; Plugins.register(MyPlugin)` or implicit, e.g. `class MyPlugin < Plugin::Abstract` (self.inherited), `class Plugins::MyPlugin` (const_added)
[17:15:49] nchambers: apeiros: so soemthing like: https://gist.github.com/ntchambers/ec59149478702ab1d46c6d87bb8a6317
[17:21:03] nchambers: thanks a ton! so just to be clear, even though Plugins is a module, I still use self.register?
[17:23:10] apeiros: it's the same for modules as with classes. `def foo` is an instance method, and hence requires an instance to call it on
[17:23:27] apeiros: just the means to get an instance differs. with a class it's direct (YourClass.new.foo)
[17:23:45] apeiros: with a module it's indirect, by including the module into a class and then create an instance of that class
[18:04:22] nchambers: apeiros: so I've got the plugin system working, but I want register to add it to an array of callbacks to be called later. how can I append the callbacks to the array without calling them?
[18:05:20] ruby[bot]: nchambers: We can't help you without your code, please post it to https://gist.github.com
[18:09:03] nchambers: so heres the repository: https://github.com/ntchambers/plugin-example/blob/master/plugin.rb, heres the current output when running plugin.rb: https://asciinema.org/a/S2tcle35qyrKImSYEi5HArwRV, and here is the output I would like to acheive: http://ix.io/ECp
[18:21:30] apeiros: nchambers: well, if you have a method named callback for all plugins, then you don't need to register the callback method ;-)
[18:21:49] apeiros: you just use `registered_plugin.send(:callback)` at the time when you want to invoke it
[18:24:50] havenwood: nchambers: If you have no state, use a Module. If you have a single instance of state, use a Singleton Class. If you have multiple instances of state, use a Class.
[18:24:52] nchambers: apeiros: that was just an example. in the actual app the callbacks will have different names
[18:25:39] havenwood: nchambers: Plugins is currently a module. I think it should be a Singleton Class.
[18:56:04] rubycoder38: I have this api where I'm supposed to use the courses data: https://api.eadbox.com/ and I have to import this data to my database but I'm not sure how to do that only for the new records, the api only allows me to fetch results per page
[18:56:46] rubycoder38: importing everything all the time while preventing duplicates would be bad for performance
[18:59:44] guacamole: or do something that caches the results and can diff them to see if there's a change/new record?
[19:04:48] rubycoder38: I'm not sure, this is for a job interview, but the HR person is being too ambiguous, she refuses to give me more information
[19:05:05] rubycoder38: I googled one of the candidate's code, I found it on github, he made a twitter bot, that's not even 10% of what I would have done
[19:05:30] guacamole: to see how you deal with ambiguity, just document any assumptions you're making and should be fine
[19:07:54] guacamole: do you have the tweeting part done? or is there an area you can focus on with more solid requirements?
[19:08:21] guacamole: if you can get it to tweet you can tweak the other parts later... might be good for motivation to accomplish a task :)
[21:51:56] havenwood: hays: A gem named `foo-gem_i_want` should be a `Foo::GemIWant` that you can require with `"foo/gem_i_want"`.
[21:54:43] hays: Ahh. Ok. I think it might have been messed up because I had a hyphen in the gem name
[22:38:40] hays: is loading a gem with : gem 'my_gem', '>=1.2' deprecated or old-fashioned in any way? I just havent seen this before and want to make sure im not relying on something that is going to be cut
[22:40:49] apeiros: it isn't loading. was never. it's activating. and unless you have a reason to, you should never have done it.
[22:41:24] apeiros: and it's old-fashioned in that nowadays having a Gemfile is what you do and that makes activating superfluous anyway.
[22:42:15] apeiros: re what's activating - if you have multiple versions of a gem installed, it makes sure that a require will use a gem satisfying the version requirement you specify in the activation.
[22:43:00] apeiros: e.g. `gem 'foo', '=1.0'; require 'foo'` and you have 1.0 and 1.1 installed, would without the `gem` call load 1.1. with, it loads 1.0
[22:52:40] hays: apeiros: I'm in a bit of a weird situation. I am writing a script that will be deployed, but customer doesn't want this script in a gem, they want it to be in a file that they can 'easily see'
[22:53:20] hays: so I am trying to figure out how to do some sort of check when they are using this script that they don't have an older version of the gem loaded than is supported
[22:55:46] hays: we might get there. or at least require 'myscriptasagem'; set_some_configuration; run_stuff_from_gem
[22:57:02] hays: ok im outta here for now. thanks for answering these questions I've had, and especially for the syslog:logger tip
[23:33:35] weaksauce: is there a place to get old old versions of ruby? i need 1.9.3 for a client that doesn't want to update
[23:35:13] weaksauce: i figured it was out there somewhere. just was curious if there is an easy way to get it
[23:37:03] havenwood: weaksauce: With ruby-install if you want a system-wide install to /usr/local use the --system flag.
[23:41:11] havenwood: weaksauce: Mind you, that version is unsupported and has known security issues.
[23:52:39] weaksauce: that was actually a lot less painful as it had been in the past to get an old version up and running with bundler