Elixir: Agent Fibonacci!

I got interested in Elixir when I had to help someone troubleshoot something called Hyperledger, and it seemed neat.  I've always wanted to try Erlang but had heard the statement "Erlang makes hard things easy, and easy things hard" so I had backed off.  (I assume it was the syntax...?)

Elixir seemed the best of both worlds so... let's take a look.

I'm now skimming through Dave Thomas's "Programming Elixir", and I found a pretty confusing example of using an Agent to maintain state (that's what Agent's do in Elixir) to compute a fibonacci number.  And it was, as I said, confusing.  Subjectively, this looks a *lot* cleaner to me:

# Fibonacci with an Agent

defmodule AgentFib do
  def sl do
    Agent.start_link(fn -> HashDict.new end, name: __MODULE__)

  def get(0), do: 0
  def get(1), do: 1
  def get(n) do
    f = Agent.get(__MODULE__, &(HashDict.get(&1, n)))
    if f do
      f2 = get(n-2)
      f1 = get(n-1)

      Agent.update(__MODULE__, &(HashDict.put(&1, n, f1+f2)))

n = String.to_integer(hd(System.argv))
AgentFib.get(n) |> IO.inspect


moved to google+

Update 2015-08-14: well it had to happen again... I am probably going to start using blogger again, at least when I want to post code snippets.  G+ sucks for that kind of thing...


Well it had to happen someday. I referred to it obliquely in
http://sitaramc.blogspot.com/2011/07/veracity.html but at that time I
did not expect to actually stop using blogspot.
There are in fact some advantages blogspot has. The blog-specific
search is one thing (G+ will search the whole world so you have to add
your name or something to make it focus on your "stream" or whatever
the heck they call it).
The URL itself is a big turnoff in G+. Compare blogspot's
http://sitaramc.blogspot.com/2011/07/veracity.html to G+'s
In fact the only reason I'm moving there is because my online world
has now pretty much reduced to git, gitolite, and related areas. And
most of those people are on G+. I reach, and am reached by, so many
more people there, it's an enormous difference from blogspot.


Microsoft makes .txt files dangerous!

This security update resolves a publicly disclosed vulnerability in Microsoft Windows. The vulnerability could allow remote code execution if a user opens a legitimate rich text format file (.rtf), text file (.txt), or Word document (.doc) that is located in the same network directory as a specially crafted dynamic link library (DLL) file.
-- Microsoft makes .txt files dangerous

(Courtesy http://lwn.net/Articles/459240/ )


git for computer scientists -- my version


It's quite similar to the original, classic version, but extends the
whole thing to explain detached HEAD, and the difference between reset
and checkout


Fwd: Git - Authenticate from Active Directory....

India in general is very "age conscious" as in, "respect people [significantly] older than you".  But among Indians, Punjabis are particularly so.  Not unlike Japan and Italy [which I used to call our "country-in-law" at one time ;-)]

So anyway, I decided to shamelessly play on this; see the last sentence of the email below ;-)  It may not have any short term effect, but who knows...!

---------- Forwarded message ----------
From: Sitaram Chamarty <sitaramc@gmail.com>
Date: Tue, Aug 9, 2011 at 11:07 PM
Subject: Re: Git - Authenticate from Active Directory....
To: [an obviously Punjabi name elided]

Although this link sounds like it is only about ssh, if you read it carefully it answers your question and it should help you: http://sitaramc.github.com/gitolite/doc/authentication-vs-authorisation.html

On a more personal note, I won't help anyone with Microsoft stuff.  I won't actively prevent gitolite from working with MS, but I will not actively help either.  For example, if someone sends me a write up on how to get gitolite to work with OpenLDAP, I will either add it to my docs, or link to it (whatever he wants).  But if you send me a document about how to make it work with AD, I will not do that.

Sorry if that sounds rude, arrogant, or whatever, but at my age (I'm close to 50) I'm entitled to my opinions, puttar ;-)



On Tue, Aug 9, 2011 at 10:49 PM, elided
<elided> wrote:
> Hi,
> A question on gitolite:
> I have git repository hosted on a Linux RedHat Enterprise machine.
> I am able to checkin/checkout using http (apache is configured for this).
> The users are setup using .htpasswd.
> I want to authenticate from Active Directory instead. Is this possible with
> gitolite?
> Also this access has to be given only to certain Active Directory users.
> If not, is this even possible?
> Looking forward to your response.
> Thanks
> <elided>



(WTF, mac idiocy!) oh yeah, about that "silky smooth OS X style"...

"git gui" and "gitk" are nice GUIs that come with git.  The latter especially is *very* powerful and even Linus uses it when needed.

GitX (http://gitx.frim.nl/) is what folks use on Macs.  Per its website, "GitX is a git GUI made for Mac OS X. It currently features a history viewer much like gitk and a commit GUI like git gui. But then in silky smooth OS X style!"

Nice.  Except, I learn while casually hanging around on #git, that you cannot open two GitX views on the same repo.

And this is not a GitX limitation.  It's damn well not a *Git* limitation, since the tools that GitX claimed to be "much like" don't have that limit.

No... it's apparently an OS X limitation not to allow GitX to open a repo twice.  Apparently a repo is a "document" so it "makes sense" to the poor brain-washed guy who told me this.

Damn... all the trouble Linus goes to avoid the need for locking, with stable objects and NFS-safe renames, and such.

And Mac OS X says "meh!"

Tell me again, why do *developers* use this piece of shit?


IE users stupid?


quote: "The comparison clearly suggests that more people on the higher side of IQ scale have moved away from Internet Explorer in the last 5 years," AptiQuant concludes.

I wish this were actually true, but sadly, it isn't very likely to be.  I call bullshit.

I do believe most IE users are seriously lacking **in information technology skills**, but even in my worst anti-MS rant I have never equated that with stupidity as a general trait.

My doctor uses IE.  My accountant uses IE.  99% of TCS' senior management probably uses it simply because it is the damn default and *they* didn't feel there was anything wrong with it.

In fact, I am coming to the opposite conclusion.  I suspect that most IE users are of the kind (see previous para) who would not even *bother* to visit an IQ measurement site.  And I am saddened that among Chrome/Opera/FF users, the more intelligent ones actually have the time to waste on trivial pursuits like "gee I wonder what's my IQ" (here's a hint: if you care, it's not high enough!)

And that doesn't mean IE is somehow being credited here.  It just happens to be the "incumbent", as they say in politics.



placeholder for https://plus.google.com/115609618223925128756/posts/PDPdXTxAvZk

I posted my comments on veracity there because a lot *more* of my gitolite/git contacts are there.


meta comment on blogs and g+: at some point we'll have to choose one; we can't update both.  I'd love to move to G+ for my blogging also, but it doesn't have a search box anywhere that I can see.  I depend on that a lot to find stuff I wrote about long ago, and without that I can't really make it the main outlet for my random typing!


Dijkstra endorses perl (well, I'm stretching it a wee bit... ;-)

Dijkstra quote: If we wish to count lines of code, we should not regard them as "lines produced" but as "lines spent".


debugging "clever" code

""Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."

— Brian W. Kernighan and P. J. Plauger in The Elements of Programming Style.

This came up in a comment about an LWN article on how subtle and tricky some of [the Linux kernel] core code has become.  Some of the more interesting quotes from that article and its links:

(in the original email from Hugh Dickins):
That -ENOENT in walk_component: isn't it assuming we found a negative dentry, before reaching the read_seqcount_retry which complete_walk (or nameidata_drop_rcu_last before 3.0) would use to confirm a successful lookup?  And can't memory pressure prune a dentry, coming to dentry_kill which __d_drops to unhash before dentry_iput resets d_inode to NULL, but the dentry_rcuwalk_barrier between those is ineffective if the other end ignores the seqcount?
Let's call this "establishing the baseline" -- anyone who did not understand at least 75% of this will be lost as far as the real problem is concerned.  But what about the people who *did* understand it (or at least, had the best chance to):
There is a sobering conclusion to be drawn from this episode, though. The behavior of the dentry cache is, at this point, so subtle that even the combined brainpower of developers like Linus, Al, and Hugh has a hard time figuring out what is going on. These same developers are visibly nervous about making changes in that part of the kernel. Our once approachable and hackable kernel has, over time, become more complex and difficult to understand. Much of that is unavoidable; the environment the kernel runs in has, itself, become much more complex over the last 20 years. But if we reach a point where almost nobody can understand, review, or fix some of our core code, we may be headed for long-term trouble.
uh oh...!