October 17, 2009

Non-blocking raw_input for Python

I needed a way to allow a raw_input() call to time out. In case it's useful to anyone, I wrote this solution which works under Unix-like OS's.
import signal

class AlarmException(Exception):
    pass
    
def alarmHandler(signum, frame):
    raise AlarmException

def nonBockingRawInput(prompt='', timeout=20):
    signal.signal(signal.SIGALRM, alarmHandler)
    signal.alarm(timeout)
    try:
        text = raw_input(prompt)
        signal.alarm(0)
        return text
    except AlarmException:
        print 'Prompt timeout. Continuing...'
    signal.signal(signal.SIGALRM, signal.SIG_IGN)
    return ''

October 17, 2009 in Python, Web/Tech | Permalink | Comments (0)

October 12, 2009

Snow Leopard Guest User data loss bug

I've seen a number of mentions today of a bug that can cause a Snow Leopard user to lose all their data:

The problem appears to manifest itself on machines which had the Guest account option enabled under Leopard and were subsequently upgraded to Snow Leopard. Users booting their machines have reported that upon start-up, they have been logged into the Guest account. Upon switching to their regular account, the affected users have been finding all of their user data missing and unrecoverable except from a backup. [MacRumors.]

One user reports a way to recover the lost data. Since it's buried in a discussion thread, I'm reproducing it here (also fixing a typo pointed out by a reader of this blog):
The files were still in /Users,
recovery was not too difficult.
1) su in terminal
2) mv username username.old
3) create account username
4) mv username username.new
5) mv username.old username
6) chown -R username username

I don't know whether it's a general fix. If you run into the bug and decide to try this solution, feel free to post your experience in the comments section!

October 12, 2009 in Web/Tech | Permalink | Comments (2)

September 11, 2009

FlyFi.com upgrade

We've made a substantial upgrade to the look and feel of our Flyfi.com web site. The site does a lot, and this release has been geared toward making the functionality more readily apparent and easier to use.

September 11, 2009 in Music, Web/Tech | Permalink | Comments (0)

August 02, 2009

FlyFi Community Playlist

If you're a Facebook user, you might want to check out my company's FlyFi Community Playlist app which lets a Facebook community collaborate on a playlist... but it's more than a playlist because it also provides tracks related to the manually entered ones.

A fair number of the tracks are legally downladable free MP3's, from superb artists like Randy Newman (one of my personal top 5 artists), Ani DiFranco, Suzanne Vega, Dar Williams, and many others.

August 2, 2009 in Music, Web/Tech | Permalink | Comments (0)

July 29, 2009

Correction re singletons

The source code link presented at the main post for my singleton mixin classes was bad until now. It pointed to an earlier version that didn't have thread safety or various other improvements. Sorry.

July 29, 2009 in Web/Tech | Permalink | Comments (0)

July 28, 2009

Even more singleton improvements

singletonmixin now deals with cases where you want to be able to include args in calls to S.getInstance() even after the initial instantiation.

July 28, 2009 in Web/Tech | Permalink | Comments (0)

July 27, 2009

More singleton improvements

Based on internal work and feedback appearing in comments on this blog, I've updated the Python singleton class I posted way back in 2004. That earlier post remains the place to get the code and place any further comments.

It now handles keyword arguments, and is threadsafe for singleton creation.

July 27, 2009 in Web/Tech | Permalink | Comments (0)

June 16, 2009

Cable News

I was stunned at how poor the Iran coverage was on cable news over the weekend. Then I saw this thought from Matthew Yglesias:

Whenever I find myself talking about new media to skeptics of an older generation who worry that the standards online are too debased, I try to remind people that the real debasing came with the rise of multi-channel cable news. In terms of the Iranian elections, the world’s top newspapers have the people on the ground reporting the main facts, and there’s lots of smart analysis from legitimate experts all over the web, but on television if it can’t be captured by two talking heads debating each other it’s like it never happened. (Hat tip to Jason Linkins, who also provided the emphasis.)
I had noticed that CNN seems to show an awful lot of discussion between experts over each event -- often much more of that than direct coverage of the event itself But I'd never thought of it in quite the way Matthew puts it. Anyway, I turned on CNN this morning to see whether, for a change, they were covering Iran.

And they were -- kind of. There was some talking head being asked about whether Obama should be taking more of a stand in favor of the protestors. The guy's opinion was that he should.

The picture is being coming clearer. Generally CNN consists of one or more talking heads in a room, taking turns talking about whether the latest news event is being handled in accordance with their personal opinion. Proportionately speaking, there seems to be not all that much actual reporting of facts.

I still don't get the reason why this is happening. Maybe it's because people find it more enjoyable than actual reporting because it's a little like gossiping about the failures of the newsmakers? Or is it that and there's a tiny bit of "human drama" when the talking heads disagree -- kind of a combination of news and reality TV? Or could it simply be that it costs less than actual reporting? (They probably don't even have to pay the talking heads, who are happy to be there to publicize themselves.)

June 16, 2009 in Current Affairs | Permalink | Comments (1)

June 15, 2009

Iran

If you've been following developments in Iran, and particularly the Internet's essential role in reporting (and supporting) events, I don't have much to add.

If you haven't, I strongly suggest you go to Andrew Sullivan's blog and starting following him now -- as well taking a bit of time to look through his posts from the last couple of days. He's been doing a wonderful job. Far better than any mainstream news outlet, with the possible exception of the NY Times' Lede. (Although the Lede doesn't present as much detail and analysis as Sullivan does -- with the help of his readers and well-chosen links to other sources.)

One of Sullivan's readers sums up the key role Twitter is coming to play:

Ahmadinejad's and Khamenei's websites were taken down yesterday - I saw the latter go down within a couple of minutes because of a DDOS attack organised via Twitter. @StopAhmadi is a good source for tweets on this. The other important use of Twitter has been distribution of proxy addresses via Twitter. This would be how most video and pictures of today's rally have gotten out.

One amazing thing is that it seems at least conceivable that the protests would not have been as successful as they currently appear to be if Twitter didn't exist.

Sullivan suggests wearing green in support of the protesters. I think that's a great idea.

June 15, 2009 in Current Affairs, Web/Tech | Permalink | Comments (0)

June 09, 2009

Flyfi.com

Most people reading this blog will know that I am a founder of the company that makes Flyfi.com (basically a vastly improved reboot of the old Goombah site).

In the last couple of weeks we have added enormously to the site, including improved recommendations. If you haven't checked it out, please do!

Here's a note I wrote to introduce it to some high school friends who I recently reconnected with on Facebook:


Hi Everyone. You may remember me playing my guitar in the hallowed halls of B.H.S. In college I became interested in math & computer technology, and in recent years, I've come full-circle by finally merging my interests. I've co-founded a music-oriented Internet startup. Our product is FlyFi.

Our VP/Industry Relations who, in a former life, earned 10 Grammy nominations as a producer, is now dedicated to using his industry connections for getting us the highest quality free music collection on the Internet. We've got great indie artists like Ani DiFranco, some well-known, others up-and-coming. Unlike some of our competing services you don't just hear the music for free -- you can also download many tracks as free legal MP3's.

My area of focus is our music recommendation technology, which lets you type in artists you like and get music out that you'll probably also like. I love music from many genres, from the Beatles to Beethoven to John Coltrane to Leonard Cohen. But I think there are underlying commonalities in the music I most love, regardless of genre. So we have statistical algorithms that try to find music that has those commonalities for each person's tastes.

Over the last 6 weeks or so, I've been completely wrapped up in putting the finishing touches on the first full release of FlyFi (which is why some of you may have noticed that my Facebook communication flow has dropped pretty much to zero). It's out now, ready for your perusal.

So, if you love music, go check out FlyFi.com!

Best,
Gary

June 9, 2009 in Music, Web/Tech | Permalink | Comments (0)

June 06, 2009

Tom Swifties

One of my more unusual pastimes is making up Tom Swifties. Examples of my efforts in this area include:

"She said I look like a common farm animal!" Tom said sheepishly.
and
"Those damned cannibals! They're seasoning us with lemon juice!" Tom said sourly.

The NY Times is having Tom Swifty contest this weekend. Submissions include:

"My men will never mutiny," said the Captain blithely."

In the esthetic of the Tom Swifty, I believe that significant demerits apply to those where the description of the act of speaking doesn't really match the tone of what is said, such as this Times submission:

"She's got my photo in her locket," said Tom independently.

and this one:

"What's under this green jello," Tom asked sublimely.


Here are two particularly fine submissions, from Chris Doyle:

"I'll just have to kill the king," Reggie sighed.
"May I have this dance?" Fred asked gingerly.”

June 6, 2009 in Current Affairs | Permalink | Comments (0)

May 23, 2009

Inspiration from Miles, Herbie, and John

From an interview of Herbie Hancock and John Mclaughlin; they'd been discussing Miles Davis:

HH: We're not going to get rid of problems. I think there's a great beauty to having problems. That's one of the ways we learn. This is something I learned from Miles, first. I had this experience that I've talked about a lot of times. I was playing with Miles and we were doing this concert in Stuttgart. This was one of the nights when the band was hot. The stuff was burning, Tony Williams was smoking, Wayne wasä JM: Scrambling those eggs. HH: And sweating. And Miles was just playing like God-like stuff that he played. It was just smoking. And then, at this one point, which was like a peak in Miles' solo, I hit this chord that was so wrong. It was just awful. It was in the wrong place and it was like boom, I just felt like I destroyed the music. And Miles took his breath and played some notes that made my chord right. JM: Damn. HH: I don't know where he found these notes but he just wiped away the chord being wrong. He made this chord fit. I was dumbfounded. I couldn't even play for about two minutes. He just blew me away and what it taught me was that Miles didn't hear it as a mistake. He just heard it as an event. He just trusted it and did his musician thing and found the notes that fit that thing. I said, wait a minute, this is a lesson not just for music but for life. Things that happen to you are events. It's what you do with them that determine whether they're going to be problems or solutions. This is the kind of thing that I hope to develop more in my life and spread. And it's not something for just musicians, it's something that everyone can spread. JM: I'm on your side. We've got to encourage responsibility. We're all in it together. We need each other desperately. Now more than ever.

May 23, 2009 | Permalink | Comments (0)

May 03, 2009

Einstein and this blog

Er, no actual relationship there. But

a) This is one of the most wonderful short articles I have ever read. It's about one journalist's brief but enormously rich encounter with Einstein.

b) My hypothesis in my previous post has turned out to be correct; when I type my name into Google, I am the top hit again.

May 3, 2009 in Science, Web/Tech | Permalink | Comments (0)

April 08, 2009

Google vs. this blog

This blog used to be very highly ranked on Google. But as of today, I can't find it there at all. Instead, it finds my old blog, which I haven't updated in years. But that one did get a huge number of hits at one point, due to posting some anti-spam mathematical ideas. So that may be the reason for its still having a decent Google rank.

I have been extremely busy with FlyFi, and posting on this blog has simply become a lower priority. One problem is that much of what I spend my time thinking about is business and technology ideas for FlyFi, which are not yet appropriate to share publicly!

Anyway, I was wondering whether, simply by posting this on my blog today, Google will see more activity and therefore make me findable again.

April 8, 2009 | Permalink | Comments (0)

January 01, 2009

30GB Zune Deaths and Rebirths

You may have heard that all 30GB Zunes died last night and will be working properly again 24 hours later. In case you're interested, the C function that caused the problem is displayed and discussed at ZuneBoards.

Basically, somebody did a poor job of leap-year handling.

January 1, 2009 in Music, Web/Tech | Permalink | Comments (0)

September 28, 2008

Languages I've learned in order

Another meme.

IBM Basic assembly language (for 360 Series IBM mainframes)
APL
Nomad
COBOL
8086 assembly language
PL/I
Focus
Pascal
C (and Think C, a simple OO variant)
C++
Python

September 28, 2008 in Web/Tech | Permalink | Comments (0)

September 22, 2008

Magical Thinking?

I read Andrew Sullivan's blog regularly. I respect and enjoy his political thinking on a daily basis. But when it comes to religion, he can't think straight.

Today he said:

Bill Maher attacked people of faith by making fun of those who believe in guardian angels. But according to a new study, non-believers are far more superstitious than believers.

The second link above says:

The Gallup Organization, under contract to Baylor's Institute for Studies of Religion, asked American adults a series of questions to gauge credulity. Do dreams foretell the future? Did ancient advanced civilizations such as Atlantis exist? Can places be haunted? Is it possible to communicate with the dead? Will creatures like Bigfoot and the Loch Ness Monster someday be discovered by science?

The answers were added up to create an index of belief in occult and the paranormal. While 31% of people who never worship expressed strong belief in these things, only 8% of people who attend a house of worship more than once a week did.

Think about it. So, 69% of those who do never worship did not express strong belief in occult and the paranormal. But compare that to those who worship. I don't have exact figures, but I'd guess that number who believe don't believe in any such things as the "virgin birth" and the "resurrection of Christ" is low. After all, in the population-at-large, 68% do believe in the virgin birth (source: a 1994 Harris poll). The proportion who believe in that hypothesized event among those who attend services "more than once a week" is undoubtedly significantly higher.

Surely, the virgin birth should be classified as paranormal if you're not simply assuming that the Christian faith is true, don't you think? It sure isn't normal.

So, the correct way to read the data: among non-worshippers, we have 69% not having a strong belief in the paranormal; that proportion is significantly less than 32% for the worshippers mentioned in the quote.

Andrew links to Russ Douthat, who posts the quote I posted above, and sarcastically comments on the "bold, heroic rationalism of unbelievers." Perhaps he should try some rationality himself. It couldn't hurt; might help.

September 22, 2008 | Permalink | Comments (0)

Photo Meme

photo meme

Instructions: Take a picture of yourself right now. Don’t change your clothes, don’t fix your hair - just take a picture. Post that picture with NO editing. Post these instructions with the picture.

I think this meme may have started with Jeremy Hilton, and is now out of control...

September 22, 2008 | Permalink | Comments (0)

September 14, 2008

Video debunking McCain ads -- spread it.

Here's a great video debunking some of the McCain campaigns recent distortions/lies.

I've always liked McCain for being a "straight talker." Now it looks like he's decided he'd rather lose his integrity than lose an election. And it's working.

As I've noted on this blog before, the Internet gives us the possibility of strengthening the power of a truth through viral dissemination of that truth. If people don't know something, it's not going to have an effect on their thinking.

So, if you agree that people who can't be elected honestly shouldn't be elected, please spread this video around.


September 14, 2008 in Current Affairs | Permalink | Comments (0)

April 10, 2008

Splitting a Python list into sublists

Suppose you want to divide a Python list into sublists of approximately equal size. Since the number of desired sublists may not evenly divide the length of the original list, this task is (just) a tad more complicated than one might at first assume.

One Python Cookbook entry is:

def slice_it(li, cols=2): 
    start = 0 
    for i in xrange(cols): 
        stop = start + len(li[i::cols]) 
        yield li[start:stop] 
        start = stop

which gives the exact number of subsequences, while varying the length of the subsequences a bit if necessary. It uses Python's slicing feature to get the lengths.

That was written in response to an earlier cookbook entry which had the following one-liner:

[seq[i:i+size] for i  in range(0, len(seq), size)]

I like that it's a one-liner but don't like a couple of things about it. If your goal isn't a particular sublist length but rather to divide the list up into pieces, you need another line to compute the size. And then it doesn't turn out too well. Suppose you want to divide a string of length 10 into 4 substrings:


>>> size=10/4
>>> size
2
>>> seq = [1,2,3,4,5,6,7,8,9,10]
>>> [seq[i:i+size] for i in range(0, len(seq), size)]
[[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]

(One substring more than desired.)

Try setting size to 3 to get fewer substrings:

>>> size=3
>>> [seq[i:i+size] for i  in range(0, len(seq), size)]
[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]] 
(Dissimilar lengths.)

Here's a briefer one-liner using the slice idea, which doesn't require you to compute the length, and does give the exact number of subsequences you want and with lengths that are more appropriately divided:


[seq[i::num] for i in range(num)]

The drawback there is that the subsequences are not actually subsequences of seq; seq is sliced and diced. But, all the elements are in the output and the subsequences are as close as possible to the same length:

>>> seq = [1,2,3,4,5,6,7,8,9,10]
>>> [seq[i::num] for i in range(num)]
[[1, 5, 9], [2, 6, 10], [3, 7], [4, 8]]

April 10, 2008 in Web/Tech | Permalink | Comments (2)