Values

November 27, 2016

People: fight for core values of freedom, not for superfluous virtuosity, even if the costs are high.

If a government tries to add censorship to the internet saying that it’s for preventing “extreme” pornography, fight it. Otherwise they’re soon going to have a database of every website you visit.

If a government demonitizes a large amount of money claiming to remove black money and corruption, and in the process removes your presumption of innocence and treats everyone a criminal until proven innocent, fight it. No amount of money is worth giving the government more power to treat you as a criminal at their whim.

If someone says an election can be rigged and asks for checks and balances, SUPPORT IT. You should’ve supported it back then (I did), and you should support it now. Checks and balance are necessary for a democracy, whether or not it’s your favorite candidate at stake.


All these dead links

November 16, 2016

All these dead links in my “blogroll”. I almost don’t want to remove it for nostalgia’s sake. In memory of a past time, where the “blogosphere” was relevant.

Perhaps it still is, but the dead links don’t seem to suggest that.

I’ve picked “The Old Reader” as my new feed reader for now.

(Oh, and it doesn’t look like WordPress has changed in half a decade either. It’s a bloated piece of junk, but it brings back memories and I think I’ll stick with it.)

(Oh, and I still love my blog’s tagline. Probably the only time in my life that I’ve ever been clever.)


Hello.

November 16, 2016

I need a place to disagree.


Simplicity is Profound

August 1, 2011

[Warning: tech stuff.]

So I’ve been thinking over a very simple technique for a couple of weeks now, that is so brilliant in its simplicity that I wonder why I haven’t come across this before, and why nobody ever suggested something like this in my programming career.

I feel like going into a rant of them imperative programming, and then into the beauty of functional programming, unit testing, lisp and some other things made in heaven, but then, I am aware that good programmers already know, and the others don’t care, so there would be no point in all that.

But for its simplicity this is beautiful code:

The problem: when you’re into the whole functional programming ideology, you tend to have multiple nestings of function calls. func1(func2(func3))). And then one fine day, comes along a bug, and you’ve got to find the value that func2 returns.

What do you do?

A normal Java or C++ programmer (who, I can still imagine nesting functions three levels deep), will just pull out that func2 and store it in a variable, and print it and then pass it to that func1.

Maybe I’m wrong, but in my reasonably short life of programming, I’ve never seen anyone do it better. I wish to be less arrogant, but I’m hurt and and upset that none of you good programmers decided to teach me the better way.

If this were elisp, define a function like:

(defun deb (obj)
   (message "%s" obj)
   obj))

Did you see what I did there? Maybe some ruby code (which already has exactly this function — but less advertised — and you should use it):

def p(obj)
  puts obj.to_s
  obj
end

And then some Java:

<T>T p(T t) {
  System.out.println(t.toString())
  return t
}

What this provides you now, is that you can debug anything anywhere, with minimum surgery. func1(p(func2(func3()))). It’s brilliant once you get used to it. You’ll find that it’s not just for things like func1(func2(..)), you can use it with just about any kind of weird syntax that your language defines for you.

So. Didn’t you know this, or am I just too young and have a lot of learning to do?


Don’t be evil

February 23, 2011

I just read this article on TechCrunch: http://techcrunch.com/2011/02/19/this-is-business-not-personal/

It depresses me.

For full disclosure, I just finished reading Into the Wild, and like when I watched the movie years ago, I’m still intoxicated by its indirect sermons of freedom and all that.

The corporate life depresses me sometimes. Google pulled it off for about 15 years, they kept their values strong. When they said Don’t be Evil, it wasn’t marketing propaganda, they really meant it. And it did them real good. And everybody loved them. You don’t have to pinpoint why you love them, there’s just this respect. This trust. Whether you’re on the inside or the outside. You start believing in the cloud.

Despite the fact that you loved your freedom as a geek from the first wrote that first printf statement. Despite the fact that you enjoyed the rare email from the rare grateful user of your open source code. (Users are ungrateful, but that doesn’t matter.) Money is evil. Job security even more so. Sometimes I think it’s easier to give it all up and live life on the road. Geek style. You know, in the hope that someday some biographer writes your biography, Into the code or something like that. Starved while optimizing an n^2 loop, they would write, for the good of mankind.

I could go on and on.

The cloud is like the life McCandless in the book despised. How does a programmer go back to his roots? Live off the real code on a real machine, on a real operating system.

How can business and real geeks live harmoniously? Google almost pulled it off. Almost. At least for fifteen years. By the way, I no longer work at Google, but all disclaimers about not representing my employer or anything like that still apply. Corporate requirements, I wouldn’t have needed that if I were writing code that I pushed to Github.

I do see a lot of incoherent blabber up there. But I’m working for a startup now. I don’t have time to edit stuff. Take what you want from it. Just to be entirely clear, since I’m talking of multiple things there, I’m criticizing: the cloud, corporates, programming for money, and life in general.


Elisp, CapsLock, X11, and total awesomeness.

July 21, 2010

I like Emacs is that I can customize it to the way I want it. I can figure out inefficiencies in my daily workflows and processes and solve it using e-lisp. The inefficiency I tried to solve today, turned out to be interesting becase a) it was a very simple requirement that b) was a very non-general requirement and therefore difficult to find online, and c) turned out to have a fairly simple solution. Some of the ideas here can be useful in themselves.

First things first, my emacs setup is as follows: I use GNU screen, with a text-based emacs, I use emacsclient for speeding up things. I use rxvt-unicode as my X11 terminal emulator. When at work, I use the above. When at home, I do SSH to my work system, and run “screen -dR” and get back my entire system as it is. (Although it doesn’t matter for this post, but I’m sure some of you are curious: I use “C-z” as my Screen escape character.)

Now, the problem I’m trying to solve: I tend to use Caps Lock every now and then for SHOUTING_OUT_LOUD, and I sometimes forget to turn it off, and therefore I waste time backspacing every now and then. I need to solve this.

(Another digression for the hardcore Emacs fans out there: yes, I haven’t swapped CapsLock and Ctrl, and I don’t ever intend to. I use a ThinkPad keyboard on my desktop, and a ThinkPad keyboard on my — well, ThinkPad, which has a Ctrl key slightly to the right, which makes it very accessible. Really, I think swapping CapsLock and Ctrl is stupid.)

How would I solve this? I think the following works: I would like to change the color of my cursor when my CapsLock is turned on.

The cursor color

First let’s figure out how to change the cursor color. If I were using X11, I would’ve called set-cursor-color and everything would look great. However, Emacs does not support changing the cursor color on a text terminal, and this is my first roadblock.

The reason it doesn’t support — as far as I understand — is that changing the terminal cursor color is a non-standard terminal capability. However rxvt-unicode and xterm do have this non-standard support. Try this from a urxvt:
echo -ne '\033]12;red\007'

You’d think we’re almost done, but this doesn’t yet solve my problem. Unfortunately GNU screen doesn’t support this escape sequence. But we can work around that: GNU screen has a [again, non-standard] escape sequence to send an escape sequence to the host terminal. So now, we have an escape sequence to change the cursor color from within GNU screen:
echo -ne '\033P\033]12;red\007\033\\'

It’s entirely possible that we can get GNU Screen to support the previous escape sequence directly by correctly playing with some termcaps and stuff like that, but I don’t have enough knowledge about those to do that, so let me just solve my own problem.

Finally, let’s write an e-lisp function to change the color of the cursor:


(defun noronha-set-cursor-color (color)
 (send-string-to-terminal (concat "33P33]12;" color "0733\\")))

And now all we need to do is test if the CapsLock is on and off and … uh oh.

CapsLock

It turns out, that there’s no way of figuring out whether the CapsLock is on or off, from within a terminal. This is because the terminal does not send any information when the CapsLock key is pressed. What now?

But then Xorg does have information about the CapsLock key. For instance, on Debian/Ubuntu install x11-xkb-utils, and run “xkbvleds”. So it seems possible that running Emacs in X might provide some functionality for reading the CapsLock state. But that still wouldn’t solve my inefficiencies.

So here’s my solution: if we can keep an xkbvled kind of daemon running separately with the X display information, we can read off the CapsLock state from that. Here’s how to do that:

First: “apt-get source x11-xkb-utils” and patch the file xkbutils/xkbvleds.c. What we’d like to do is, uncomment the code that displays the window, and add a small printf that displays the state of the CapsLock key in the event loop: “1” if it’s on, and “0” if it’s off. This is left as an exercise, it is not hard.

Now we have a program that displays the state of the CapsLock key everytime it changes. It does not need to continuously poll the X server and so runs efficiently.

Now we need e-lisp that reads this asynchronously. This turned out to be fun for me since it was the first time I was dealing with processes — and that too asynchronous processes from elisp.


;; my patched version of xkbvleds
(setq xkb-daemon-command "/home/noronha/builds/x11-xkb-utils-7.5+1/xkbutils/xkbvleds")
(setq xkb-process nil)

(defun noronha-set-caps-state (state)
 (cond
  ((= state ?0)
   (noronha-set-cursor-color "black"))
  ((= state ?1)
   (noronha-set-cursor-color "blue"))))

(defun noronha-process-caps (process output)
 (mapc 'noronha-set-caps-state (string-to-list output)))

(defun noronha-start-monitoring-caps (display)
 (if xkb-process (delete-process xkb-process))
 (let ((process-environment (cons (format "DISPLAY=%s" display) process-environment)))
  (setq xkb-process (start-file-process "xkb-daemon" "xkb-daemon" xkb-daemon-command)))
 (set-process-filter xkb-process 'noronha-process-caps))

(noronha-start-monitoring-caps ":0")

And, yes, it works.

(Finally we need to restart the xkbvleds program when we connect using “ssh -X” and then run screen. I haven’t done this yet, but that final step is simple: write a wrapper over screen that calls emacsclient and runs (noronha-start-monitoring-caps "$DISPLAY").)


I need this post to sleep

June 1, 2010

[EDIT: This isn’t right. Sleep grogginess. Confusion. I hope I can come up with a correct-er post soon.]

I am immature and stupid, but I’m rebellious and still learning from life.

I hope this’ll make sense to my future self when he needs it: Morality is subjective. You did right. They won’t understand.