Monday, September 1, 2014

Stop your Mac from keeping a perpetual connection to Apple

I had done this some time ago on my laptop, but had to try to remember once again while helping someone else. I am just noting it here so it is not as difficult to remember the next time :-)

Basically, the problem is:

$ netstat -an
tcp4       0      0    ESTABLISHED
tcp4       0      0      ESTABLISHED

These connections are established as soon as the user logs in, and maintained perpetually.

$ lsof -i 4tcp
apsd    334 root    8u  IPv4 0x…      0t0  TCP 192.…:52622-> (ESTABLISHED)
apsd    334 root   11u  IPv4 0x…      0t0  TCP 192.…:52622-> (ESTABLISHED)
apsd    334 root   12u  IPv4 0x…      0t0  TCP 192.…:52623-> (ESTABLISHED)
apsd    334 root   14u  IPv4 0x…      0t0  TCP 192.…:52623-> (ESTABLISHED)

Seriously annoying.

apsd is not a rogue process or anything, but here's what the man page says:

ApplePushService daemon for Apple Push Notification service.
This is part of the ApplePushService framework.

There are no configuration options to apsd.
Users should not run apsd manually.

Well, alrighty then.

apple.stackexchange to the rescue:

$ sudo launchctl unload -w \

turns it off, and,

$ sudo launchctl load -w \

turns it back on.


Sunday, August 31, 2014

Context dependence in Turkish

So, I tried to improve the Turkish translation of Gabor's Scalar and List context in Perl, the size of an array. Given that my heart is not really in it, I am not going to make a habit of this, but I do hope that the new version is useful.

In thinking for a corresponding Turkish example to Gabor's example of context dependence in English, the first thing that popped into my had was karı-koca versus karı küredim which is OK, but not very impressive.

I like my example much better:

  1. Çivi çakmak
  2. Çakmak çakmak
  3. Matematik'ten çakmak
  4. Beşlik çakmak

where çakmak çakmak and Matematik'ten çakmak both have at least two meanings each depending on the context.

Friday, August 29, 2014

Replacing hash keys with values does not a translation make


Some time ago, Gabor and I had a disagreement regarding the value of translating programming articles to languages other than English.

In a nutshell, having actually worked as a translator (Danish↔Turkish and English↔Turkish, including a stint translating for CTW producers Sesame Street episodes written by Turkish writers for the Turkish version), I am quite familiar with what happens when people attempt to translate meaning by looking up terms in a dictionary.

I am afraid, Perlde scalar ve list bağlam, bir dizinin boyutu (English original) forms a good example of why such translations are not only not useful, but also harmful.

I am sure Kadir Beyazlı put in a lot of good work into the translation, but the result is an abomination.

The grammar error in the first word of the title is repeated throughout the body of the post.

More importantly, look at that title again:

Perlde scalar ve list bağlam, bir dizinin boyutu

Is that Turkish or English?

Having failed to find good terms to replace scalar and list, the translator decided to keep using the English words. How does that help a person who supposedly doesn't understand English, and, therefore, would be reading this translation? For all she knows, we could have used pony and rabbit, instead of scalar, and list, and, so long as the substitution was consistent, she would get the same benefit out of reading this.

If you look at the English-Turkish Math Dictionary, scalar is translated as sayısal which actually means numeric, which kinda works when we are talking about an array in scalar context, but then fails when we say a reference is a scalar.

Let me state this unequivocally: The Turkish language has been impoverished over the past century by the blind culling of words of Arabic, Farsi, and in some instances Hebrew origin (although, at least Eylül is still Eylül) in some blind drive towards purification of the language following Atatürk's reforms. Blind importation of words from English and French did not help either (Turks cannot distinguish among the meanings of the word economy in the Turkish Economy, the Economics Department, and economy class — which saddens me. Hint: Türkiye Ekonomisi, İktisat Bölümü, and ucuz bölüm.

I am happy I did not have to learn to write Turkish in Arabic alphabet, but every time I think of my grandfather Dr. Şinasi Kıpçak's vocabulary, mastery of the language, I am filled with both nostalgia and envy.

Coming back to how to translate scalar and list context to Turkish …

Here, as in many cases, the translator must think about what words express the meanings of those phrases most consistently and usefully.

To me, the answer is clear: Scalar context in Perl refers to situations where something is interpreted as just one thing.

So, a translation of that title that actually conveys the meaning instead of doing a simple hash lookup might be:

Perl programlarında tekli ve çoklu bağlam: Bir dizinin elemanlarının sayısı

whose literal translation back to English would be Scalar and list context in Perl programs: The number of elements in an array. I believe such a translation conveys a whole lot more meaning to a person who actually does not speak English.

Moving on, we have:

Mesela "left" kelimesi birçok anlam içerir:

I left the building.

I turned left at the building.

Why use English examples to explain how we can deduce the meaning of homonyms from context? How does someone who does not speak English get anything out of that?

Why not use a simple Turkish example?

Karı küredim.


I am willing to bet the sentence Çözümü SCALAR bağlamda veri döndüren scalar() fonksiyonunu kullanmaktır does not make any more sense to a Turkish speaker who speaks no English than The solution is to use the scalar() function that will create SCALAR context for its parameter.

Translation and hash-lookup are different things. If you want to convey meaning, you have to have a command of both languages, and the subject matter. Without that, you are only going to add to the word soup. Translating big event as büyük okazyon helps no one.

I am sure both Kadir and Gabor had the best of intentions with these translations. I just happened to notice that their collaboration happened to produce a translation that highlights everything that a non-English speaking aspiring programmer has to fight with.

In my experience, trying to learn programming from translated technical writings is a fool's errand. One would be far better off picking up a little English, watching movies with subtitles, and reading a great book such as Learning Perl. When doing so, consult mostly an English-English dictionary. Stick with it for about six months, through thick and thin, and you'll be amazed how much better your results will be through that process rather than fighting through:

Şu an bir dizinin SCALAR bağlamdaki değerinin eleman sayısı olduğunu biliyoruz. Ayrıca eğer ki dizi boş ise bu değerin 0 (that is FALSE) olduğunu, 1 veya daha fazla eleman içeriyor ise pozitif bir sayı (that is TRUE) olduğunu da biliyoruz.

Allah rızası için, sen n'apıyorsun yav gözümün içi??? "That is" ifadesini o bağlamdaki karşılığı Türkçe'de "yani" dir. Ayrıca niye "şu an"? Bi de Perl'de olacak başlıktaki.


Friday, August 22, 2014

Convert multi-page PDF to invidual PNG images using GraphicsMagick

I had to look this up … A lot of hits by Google show ancient syntax. Here's what works:

$ gm convert 'document.pdf[12-45]' +adjoin output-%03d.png


Monday, August 18, 2014

File::Which comes with its own 'multiwhich'

I uploaded App::multiwhich, based on a script I have been using for many years, in observance of #CPANDAY. While honestly thought it was a cute, useful little utility which I could improve by fixing edge-cases, I just realized that there is no reason for you to use it ;-)

File::Which comes with its command line utility called pwhich. For example:

$ pwhich -a perl vim doesnotexist
pwhich: no doesnotexist in PATH

The module definitely predates my foray into Perl. I cannot fathom how I missed the pwhich utility.

So, don't use App::multiwhich. Use pwhich. I'll make the requisite changes in the module distribution.

Saturday, August 16, 2014

Just uploaded App::multiwhich in observance of CPAN day

multiwhich is a small utility which looks for an executable in all directories in your $PATH. For example, on my MacBook Pro, it gives me:

$ multiwhich perl vim doesnotexist
- perl:
  - /Users/auser/perl/5.20.0/bin/perl
  - /opt/local/bin/perl
  - /usr/bin/perl
- vim:
  - /opt/local/bin/vim
  - /usr/bin/vim
- doesnotexist: []

It should soon be available on CPAN. The repo is on GitHub.

For more, see CPAN day, or follow @cpan_new, or search #cpanday.

Monday, August 11, 2014

Are you a code monkey?

Despite my appreciation of Stackoverflow, I can never see myself agreeing with Jeff Atwood on anything substantial. A post of his that is still featured in my regular nightmares is the one titled We Are Typists First, Programmers Second.

He says:

When you're a fast, efficient typist, you spend less time between thinking that thought and expressing it in code.

That might matter, but, frankly, what I encounter regularly are people who really ought to think hard and long about what they are about to type, and, then, when it is time to type that, think another half an hour before touching a keyboard.

Because, otherwise, they end up generating a 500,000,000 line CSV file from a database by just inserting commas between text fields, as in, VAR1 || ',' || VAR2 || ',' ….

When the source data contains single character flag fields whose "specification" dates back decades to some COBOL thing where they ran out letters and numbers a long time ago, you sometimes get, say, 100 rows with more commas than expected.

But, the code monkey don't care!

He typed that SELECT fast. Put the dump on a server, remembering to use SFTP (of course, self-signed certificate), and got back to his typing.

After all, he is a coder. He understands things no one around him understands.

I wish all you coders, typists, brogrammers would just go on a cruise to the Bermuda Triangle.

Don't be a code monkey!

Typing fast is the LEAST important component of programming.


He goes on to gratuitously attack Perl programmers:

Don't just type random gibberish as fast as you can on the screen, unless you're a Perl programmer.

Perl has Text::CSV_XS and Text::xSV. Any programmer who is aware of these modules would not waste others' time with nonsense.