DevHeads.net

Postings by Andy Jones

Problems with Time

Another one for you folks.

Something is wrong with my threads

Would any of you smart folks like to tell me what stupid thing I am doing here?

At this point I have a test program that just uses plain MRI, no gems. If I keep running it, it will eventually fail (after a dozen runs at most). Code at the end of this post.

What I'm doing is creating a lot of identical threads. In each one I stop immediately, and then after the thread is re-entered, set a thread variable to say the thread is done then stop again. I run them all, and then check they are all done.

The problem is, sometimes they aren't all done. Which makes no sense to me.

Representing money

Pardon my curiosity -- what do you use to represent money in your code? It seems to me that the choices are between:

1) BigDecimal

2) Rational

3) A custom class
To my way of thinking, if you are multi-currency, you almost certainly want #3; but otherwise it's down to personal preference?

"Nice"

I suspect that part of the problem is, "nice" is nearly meaningless in English. "Might I suggest that the world would greatly benefit if you jumped off a cliff?" is, arguably, nice, because I'm being polite.

I gather that the Japanese word that got translated to "nice" in "Matz is nice..." has a more specific meaning.

I'm one of those folks who would rather have a proper code of conduct, with an explanation for how it would be enforced.

Teaching people to code

Does anyone here have any recommendations for resources on teaching people to code?

I've kind of volunteered to teach Ruby to some of my co-workers. I'm good at _explaining_ but I'm rapidly discovering that there is a big gap between that and teaching.

Worse, it looks as if one of my students has never coded before.

Race Condition Tool?

It appears that Golang has Race Detector, a tool to detect race conditions -- <a href="https://blog.golang.org/race-detector" title="https://blog.golang.org/race-detector">https://blog.golang.org/race-detector</a>

Does anyone know of anything similar for Ruby? Or, any advice at all for testing that my code is threadsafe?

(Detail: I'm writing a connection pool. This is for Ruby, not Rails. I think I have a workable approach, but I'm not sure how best to write the tests...)

Click here to view Company Information and Confidentiality Notice.<http://www.jameshall.co.uk/index.php/small-print/email-disclaimer>

Functional programming in Ruby (Was: Reducing Enumerable (and writing again))

No, I've not tried it. I see the appeal from a functional perspective, but a part of me is not really buying it.

GC Stress mode

Can anyone tell me why I shouldn't turn on Garbage Collection Stress Mode (`GC.stress = true`) temporarily inside a library I am writing?

I'm assuming that this is a dreadful idea. Other than degraded performance, though, why?

There is precious little information about GC in Ruby in the documentation. I mean, I can see why. You shouldn't go messing with that stuff. But.

Mad Science Background
I'm writing a library that tracks objects the user creates for reasons of persistence. This is just a mad science project; I'm actually assuming that the whole thing is completely bonkers.

File.read() v Pathname.read() gotcha

This is damned annoying.

Octothorpe 0.4.0 released

I don't normally blow my own trumpet here, probably because it's a pound shop plastic one that somebody sat on.

But, what the hell: Announcing the release of Octothorpe 0.4.0! I am literally the only person using this right now (and probably forever). If you want to give me a thrill, raise an issue.

Octothorpe is a tiny, hash-like data class designed for passing information between other classes. I've been using it to pass data between models, controllers and views in Sinatra for a while now.

Compiling 2.4.1 from source under Linux -- dependancies?

The Ruby documentation has always been a bit coy about this. Can anyone point me to something that says exactly what I should be installing beforehand to get the best out of the language?

From memory / looking at the output of ./configure and guessing, I have:

* readline (is this still a thing?

JSON woes

This is all kinds of annoying. JSON will apparently encode a String but not decode it?

order of fields and values in a hash

Not sure if I'm being paranoid or not. But my code has to work in multiple flavours of Ruby, so.

Let's say we have a hash h, and

x = h.keys.zip(h.values).to_h

How confident can I be that x == h? In other words, how confident can I be that h.keys will give the same ordering of hash elements as h.values?

I see that the doc for Hash in MRI says "Hashes enumerate their values in the order that the corresponding keys were inserted". Can I really rely on that? In jRuby to?

I suppose I am used to the idea that you can't rely on the ordering of elements in a Hash.

Deploying ruby in a container

HI all,

I'm looking into the viability of using containers to deploy some basic ruby code. I know next to nothing about the subject.

Does anyone know of some basic resources that would help jump-start me here?

I'm looking at Rkt (<a href="https://github.com/coreos/rkt" title="https://github.com/coreos/rkt">https://github.com/coreos/rkt</a>) but if you have anything Ruby-related for Docker, that would be helpful, too.

We currently use Warbler and Tomcat to deploy web-facing applications. That works well.

Rspec - Vim - Snipmate

Hi all,

I threw together a set of snipmate snippets for rspec 3. Thought it just about possible someone else might get some use out of them, so here I am and here they are: <a href="https://bitbucket.org/andy-twosticks/rspec_snippets" title="https://bitbucket.org/andy-twosticks/rspec_snippets">https://bitbucket.org/andy-twosticks/rspec_snippets</a>

Snipmate is a Vim plugin that auto-inserts text. (Presumably I don't have to explain what rspec and vim are...)

It's entirely possible that some vim plugin provides this functionality and does it better.

Doris and Marge?

I'm all for whimsy in my favourite language. Can anyone shed any light on what Object.doris() does?

[9] pry(main)> ri doris
.doris

(from ~/.rdoc)
Implementation from Object

Something Functional, obviously. Maybe this is a running joke if you are into FP.