Tuesday, September 19, 2017

My standard spiel.

The interview process is inherently stressful. Getting a job is a life-changing event, so the stakes are high. I think it is counterproductive for both parties if the interviewer creates any additional stress. It can interfere with your memory and reasoning skills, which makes it harder to answer questions.

So I'm telling you in advance what to expect from me.

  1. I am going to interrupt you. I interrupt everyone. It doesn't mean that things are going poorly. It's just that our time is finite. So don't let it bother you when I interrupt.
  2. Make sure that you understand my questions. If something isn't totally clear, ask me to repeat the question or rephrase it. Different companies can use different names for the same things. It could be that I'm using an unfamiliar term for something that you know by a different name.
  3. You don't have to answer right away. It's okay to pause before answering. And it's okay to pause in the middle of an answer. It's okay to pause in the middle of a sentence. That's fine with me.
  4. If a better answer pops into your head later on, go ahead and tell me. We can rewind. We're humans. That's fine.
  5. Sometimes your best answer could actually be "I don't know." That's okay. I might be asking you a question that I don't expect you to be able to answer. I may just be trying to probe the perimeter of your knowledge. So don't worry if you don't know the answer to a question.
  6. I don't have a secret question which you must answer correctly. Some interviewers have a pet question that everyone has to get right. If you bomb on a question, don't worry. It's not a landmine.
  7. Every interview website suggests that you ask your interviewer questions to show interest. You don't have to do that. I don't care if you have questions. That being said, do you have any questions? This is not a trick.

Friday, April 25, 2014

Feature Idea for Blogging Software

When presenting the user with the list of tags applied to a post, how about you omit any tag that has only 1 member (i.e. the post you just read)?

Clicking on such a tag is a total waste of time.

Calling the patent attorney now...

Friday, April 18, 2014

Python speech synthesis on OS X

I know, this is cheating. But it's fun.

def speak(*args):
    from subprocess import Popen, PIPE
    
    cmd = ["/usr/bin/say"]
    cmd.extend(args)
    
    Popen(cmd, stdout=PIPE, stderr=PIPE).communicate()

Tuesday, April 8, 2014

Copying text via Python on OS X (revisited)

Let's try that again.

import Cocoa
pb = Cocoa.NSPasteboard.generalPasteboard()

def get_clipboard_text():
    """Get the text contents of the system clipboard. 
    @return (string)
    """
    return pb.stringForType_(Cocoa.NSPasteboardTypeString)


def copy_text_to_clipboard(text):
    """Copy the supplied text to the clipboard.
    @param text
    """
    pb.declareTypes_owner_([Cocoa.NSPasteboardTypeString], None)
    pb.setString_forType_(text, Cocoa.NSPasteboardTypeString)

Wednesday, December 12, 2012

Copying text via Python on OS X

It took me an embarrassingly long time to figure out why I was getting an extra newline character appended to the copied text. (It was because I forgot to include the -n parameter to echo.)

from subprocess import Popen, PIPE

def copy_to_clipboard(self, text):
    # equivalent to: echo "text" | pbcopy
    p1 = Popen(['/bin/echo', '-n', text], stdout=PIPE)
    p2 = Popen(['/usr/bin/pbcopy'], stdin=p1.stdout, stdout=PIPE, stderr=PIPE)
    p2.communicate()

def get_clipboard_text(self):
    return Popen(['/usr/bin/pbpaste', '-Prefer', 'txt'], stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate()[0]

Friday, April 20, 2012

Igpay Atinlay

def pig_latinize(text):
    '''
    Returns the Pig Latin version of the supplied English text.
    @return (string) Pig Latin
    '''
    import string

    new_text = ''

    for word in text.split():
        punctuation_mark_begin = ''
        punctuation_mark_end   = ''

        if word[-1] in string.punctuation:
            punctuation_mark_end   = word[-1]
            word = word[:-1]

        if word[0]  in string.punctuation:
            punctuation_mark_begin = word[0]
            word = word[1:]

        all_caps   = word == word.upper()
        title_caps = word[0] in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

        word = word.lower()

        new_word = None

        m = len(word)

        if m < 3 or word in ['and', 'the']:
            new_word = word + 'kay'

        else:
            vowel_offsets = [word.find(v) for v in 'aeiouy' if (word.find(v) != -1)]

            m = 0 if (len(vowel_offsets) == 0) else min(vowel_offsets)

            if m == 0:
                new_word = word + 'way'
            else:
                new_word = word[m:] + word[:m] + 'ay'

        if all_caps and (len(new_word) > 1):
            new_word = new_word.upper() 

        elif title_caps:
            new_word = new_word[0].upper() + new_word[1:]

        new_text += punctuation_mark_begin + new_word + punctuation_mark_end + ' '

    return new_text[:-1]


INKAY ONGRESSCAY, ULYJAY 4KAY, 1776WAY Thekay unanimousway Eclarationday ofkay thekay irteenthay unitedway Atesstay ofkay Americaway Enwhay inkay thekay Oursecay ofkay umanhay eventsway itkay ecomesbay ecessarynay orfay oneway eoplepay tokay issolveday thekay oliticalpay andsbay ichwhay avehay onnectedcay emthay ithway anotherway andkay tokay assumeway amongway thekay owerspay ofkay thekay earthway, thekay eparatesay andkay equalway ationstay tokay ichwhay thekay Awslay ofkay Aturenay andkay ofkay Ature'snay Odgay entitleway emthay, akay ecentday espectray tokay thekay opinionsway ofkay ankindmay equiresray atthay eythay ouldshay eclareday thekay ausescay ichwhay impelway emthay tokay thekay eparationsay.

Oodgay enoughway.

Thursday, November 17, 2011

str() is the Devil

Recently I discovered the folly of using str() within Python 2.7 scripts. My program would ingest arbitrary UTF8 text from outside sources and then try to print it to a file, only to crash with a UnicodeDecodeError or UnicodeEncodeError exception. In good time, I realized how to do it The Right Way and converted all my str() calls to unicode().

But the error kept occurring. It took me quite a while to remember that

foobar = ''

is functionally equivalent to

foobar = str()

This problem shouldn't happen in Python 3, since all strings are Unicode by default there.