Category Archives: development

The ACM competition

Judging the 2003 ACM ICPC Manila regionals was tons of fun. Although I
was somewhat delinquent in terms of making problems – I’d only made
one which was simplified due to contest limitations – my problem was
nonetheless included and a few teams actually solved it.

It was a straightforward problem – a text-based database. Helpful
teacher that I was, I made several test cases that checked for
specific errors in program logic, but had to merge them into one
enormous test case for the contest. Coded the solution in 10 to 15
minutes and submitted it via PC^2 for testing. Very glad to see it
work on the first run.

Had some tussles with PC^2 and compiler support. Jerome knew the magic
cmd trick, though, so we managed to get all the compilers to work.

Glad to see the other people from the SEARCC contests. Seemed like
nothing had changed. Mike still crazy-funny self. Chipi still somewhat
insane (but very good). Mars (Gabutz) somewhat less insane (no more
Wendy’s action figures? awww).

Story: It was an hour or so before the contest and Ces still didn’t
have judges’ test data for her problem. General panic. We quickly
prepared 10 copies of a 10×10 matrix for her 3-D problem and started
filling in letters. We finished the test data but weren’t quite sure
if it worked, so I sat down and quickly wrote a solution. Actual
output and expected output differed. Inclined to trust program, so
copied actual output into sample output for initial testing and then
spent some time debugging the test data. (Debugging the test data!
Pfft.) Eventually worked. Felt very pleased when other people solved
the problem, as that confirmed that test data was now correct.

Rejoiced when a team finally solved my problem. Had been on pins and
needles previously as had thought my problem ridiculously easy, thus
lack of attempted solutions was most worrisome. A number of teams
didn’t test with sample output given in problem, tsk tsk.

Went bowling with Dominique, Chipi, Mike, Jerome, and Mars. Non-zero
score. Very happy.

Ateneo still top-ranked Philippine team. Yay. =) Also, they beat more
foreign teams than last year. 5th place, big improvement.

Must work on consistency, though. Last team freaked out and did not
solve any.

A question of scale

([[OpenSource#note2][OpenSource:2]]”[[oss]]”[[OpenSourceIssues#note2][OpenSourceIssues:2]]”[[ToBlog#note2][ToBlog:2]])

Open source allows people to work on an individual basis. Developers
can jumpstart their projects by using existing code, creating software
that answers their own needs and perhaps the needs of a small group of
users that often also contribute improvements. Because the source code
is open, people can easily choose the features they want to include or
make minor modifications to get existing code to behave the way they
want. Open source development promotes personal communication with
users, and user requests can go straight to developers without passing
through marketing. How is this different from other kinds of
user-developer relationships, and is this an advantage open source
developers can use?

On Technorati: ,

Working with Emacs

A recent post on the Philippine Linux Users’ Group suggested a
separate plug-emacs mailing lists for all the Emacs messages that have
popped up recently. The suggester said:

There is a
difference between discussion and stroking each other’s ego. :)

Working with Emacs is a humbling experience. It brings you face to
face with accumulated centuries of developers’ work. Emacs involves
people in its development to an unusual extent. Working with vi and
even Eclipse made me feel more like a user than a co-developer.
Working with Emacs made me feel part of the community, even when I was
still struggling to make sense of the parentheses.

If in that sense, Emacs worship is considered ego-stroking, then sure,
I’m guilty. I can’t help but express my appreciation for one of those
things that has really changed my life and made free, open source
software really meaningful to me. For the culture, really, that made
it possible. It’s a piece of software, but it’s also a conversation
with so many developers around the world.

To newbies: if you’re curious about the thrills of open source
development and you want a nice, easy way to get started, why not try
modifying Emacs? It’s easy to pick up. All the source code is there,
and you can modify it on the fly. We’ve had complete non-programmers
try it out and fall in love with programming. They get thrilled when
they share their tweaks and other people respond with comments and
suggestions. This is good stuff. Try it out. =)

I suppose Emacs is off-topic. After all, it’s cross-platform, not
Linux-specific. I could easily be extolling the wonders of Emacs on
Mac OS X, Microsoft Windows, or BSD. Emacs doesn’t require Linux.
(Neither does Apache, but you don’t see people waxing lyrical about
web servers that often, do you?) The flood of Emacs-related posts that
deluge the list whenever someone unwittingly brings up the topic is
probably incomprehensible to people who’ve never tried Emacs or tried
Emacs as just an editor and didn’t like it.

Still, I want to share what makes open source real for me. Not kernel
hacking, which is still too intimidating despite the existence of
projects like kernel-janitor. Not network or system administration,
which I don’t have the patience to do. Just the free and flexible
customization of something I use everyday and the thrill of sharing
these customizations with other people in a community that spans the
world.

I guess that’s why I post on PLUG instead of plug-misc. I don’t think
PLUG should just be a venue for asking and answering technical
questions, but also for sharing nifty hacks and examples of how far a
Linux system can be pushed. Other people push their systems in terms
of hardware and services. I push mine in terms of how well it can fit
me, how well it can anticipate my needs.

I want to stroke other people’s egos. I want people to discover how
they can contribute to free and open source software, to experience
the thrill of seeing their code out there and being used. Open source
development isn’t just for PHP wizards or C freaks who can contribute
to existing projects or launch an entirely new project on their own.
Maybe—just maybe!—people who thought themselves just users of a text
editor will be inspired to think about how they can start customizing
their own.

コンピュータを使えば時間に節約になる。 Computers will save you a lot of time.

clair ching says:

I can’t help but agree with you. Emacs is the way that I
appreciated FOSS more compared to GNU/Linux per se. Why? It’s because
I easily felt part of the community of Emacs users and hackers on the
Emacs Wiki. That kind of interaction makes it less scary for newbies,
IMHO. I mean, not all people on the Emacs Wiki are very friendly, I
suppose, but the ones I have interacted with as I was learning to use
various tools and modes available showed me that I can do something
for the FOSS community, which is to write about what I learn. I don’t
even know ELISP but at least I know that my blog entries are helpful
to others too. =)

I guess we have been too giddy over Emacs on the PLUG mailing list
that is why someone suggested that. Well, I know I have always been
giddy about it but I can’t help myself! ^_^ Emacs is wonderful…

Besides there are so many hacks in Emacs that make FOSS usage,
learning and advocacy so much fun! Like the Planner mode that allows
me to somewhat organize my life, my thoughts, my schedule. Eshell
allows me to do some things without opening a separate terminal. In
Planner, I also store my notes on advocacy and my blog entry drafts. I
also listen to music on Emacs. And when something goes wrong on
whatever mode I am using, I can email the maintainer immediately, to
tell him/her what happened so that the bug can be fixed, etc. I try to
be as detailed as possible when I do that. So I guess that is my
contribution. =)

In any case, I also enjoy the company of people using Emacs, not just
because we talk about Emacs but because I am learning so much about
you guys =)

On Technorati: , , , ,

How to find great developers

Joel Spolsky writes about finding great developers. Internships are a terrific way to scope out a candidate and also get them passionate about your company. Previous blog post about career aside, I do really like IBM and I *am* really curious to see how far we can take social software – and one of the reasons why I’m crazy about that company and all the cool people in it is because I’ve seen it from the inside, thanks to the IBM Toronto Centre for Advanced Studies.

Check out the essay.

More thoughts: One of the things that frustrates me about the
Philippines is that we’ve got this entire chicken-and-egg problem in
the schools. Few companies do on-campus recruitment for challenging
internships, so students don’t get motivation or experience – which is
why few companies bother to do on-campus recruitment or R&D.
Programming competitions help, I guess, and we do still manage to find
a couple of geeks who learn about open source and end up teaching
themselves. Still…

On Technorati: , , , ,

Emacs: Keyboard shortcuts for navigating code

UPDATE 2014-01-21: Add regexp-quote around current-word.

One of the lines on my list of things I can do in order to make progress on my book is to move my Drupal development environment from Eclipse to Emacs, as immersion would no doubt give me plenty of things to tweak and describe. When you use something every day, you notice the rough edges. With Emacs, you can sand those edges down. I already use Emacs every day, but I had been doing most of my development work in Eclipse because Eclipse packaged a number of useful features I wanted. If I can move my environment to Emacs, though, I’ll be able to customize it a lot more freely.

Take something as simple as navigation, for example. In Eclipse, I can hit Ctrl+K to search for the next instance of the current word, which is a handy way to look for function calls or definitions in the same file. How would you do that in Emacs? The built-in search functions allow me to take text from the buffer, but I wanted something even faster. Here are some of the ways you can tweak navigation, too.

If you haven’t tried it yet, you’ll probably like interactive search (C-s) because you can modify the search and see the results as you type. All you need to do to make it better than Eclipse’s Ctrl+K is to add a function to grab the current word, even if the point in the middle of the word. Add the following code to your ~/.emacs:

(defun sacha/isearch-yank-current-word ()
  "Pull current word from buffer into search string."
  (interactive)
  (save-excursion
    (skip-syntax-backward "w_")
    (isearch-yank-internal
     (lambda ()
       (skip-syntax-forward "w_")
       (point)))))
(define-key isearch-mode-map (kbd "C-x") 'sacha/isearch-yank-current-word)

Type C-s (isearch-forward) to start interactively searching forward, and type C-x to get the current word. Use C-s and C-r to search forward and backward. You can modify your search, too.

Want to make it even faster? Use these functions to bind similar searches to shortcut keys:

(defun sacha/search-word-backward ()
  "Find the previous occurrence of the current word."
  (interactive)
  (let ((cur (point)))
    (skip-syntax-backward "w_")
    (goto-char
     (if (re-search-backward (concat "\\_<" (regexp-quote (current-word)) "\\_>") nil t)
	 (match-beginning 0)
       cur))))

(defun sacha/search-word-forward ()
  "Find the next occurrance of the current word."
  (interactive)
  (let ((cur (point)))
    (skip-syntax-forward "w_")
    (goto-char
     (if (re-search-forward (concat "\\_<" (regexp-quote (current-word)) "\\_>") nil t)
	 (match-beginning 0)
       cur))))
(global-set-key '[M-up] 'sacha/search-word-backward)
(global-set-key '[M-down] 'sacha/search-word-forward)

Feel free to change the keybindings or otherwise improve the code. =) Good luck and have fun!

Deploying to servers

I’m heading to the Philippines tomorrow, and to make life easer for the two other Windows-based PHP developers on my team, I updated the web-based deployment script I mentioned in
Development kaizen: deployment and testing. I added the ability to push a specified revision to the production server. It took me less time than I thought it would (I love it when things Just Work!), so I decided to spend time documenting it just in case I ever need to do it again (almost certainly) or just in case it breaks while I’m away (hope not).

Behind the scenes, there are a number of moving parts:

  • Key-based authentication. Because I need to copy files and run commands on the production and QA servers non-interactively, I needed to set up key-based authentication using SSH. I’m somewhat nervous about using a passphrase-less key, but I couldn’t see a way to work around this.
  • Rsync. I use rsync over ssh to transfer files to the remote system. It’s good at efficiently transferring changed files. I couldn’t use –delete to get rid of old files, though, as our source tree does not include the complete system.
  • A shell script with the suid bit. The shell script is responsible for exporting the requested revision to a temporary directory, rsyncing it over to the selected host, and running a few commands on the server in order to reset file permissions and clear the cache. The suid bit is there so that it takes my identity and uses the key that I set up. I resorted to suid because I couldn’t figure out how to make sure that Apache had its own key. I tried associating it with the user that Apache ran as, but I kept running into “no tty”-type errors. The suid workaround solved the problem quickly.
  • A PHP script that displays a form and the last 20 revisions. The form includes a drop-down box of the revisions displayed, a button for deploying to QA, and a button for deploying to the server. When submitted, the script does some error-checking, then uses system to call the relevant shell script. The script determines the list of revisions by using shell_exec to store the output of svn log … -limit 20 in a string, then using preg_match_all to match all instances of /r([0-9]+)/. Seems to work.