Interview question: Recreate groups

I was in an interview and another interview walked in and said “Hi, do you know the groups tool in unix?” At which point i said “Yes”. At which point the interview hands me a whiteboard marker and says “Great. Write it”. And after a couple of minutes of thinking about how to do it, I wrote it down.

Now, I didn't end up doing it on a whiteboard, I did it on a piece of paper I had, which I kept, but unfortunately I have not beed able to scan it for everyone's reading enjoyment. But I'll do that in the future.

So once I got home after the interview, I took the algorithm, and applied proper PERL syntax. And here is the code:

  1. #!/usr/bin/perl
  2. #######################################################################
  3. # Created By: Bryce Verdier
  4. # on 1/19/10
  5. # Function: rework the output of the unix groups command
  6. # NOTE: FOR USE ON UNIX MACHINES!
  7. #######################################################################
  8. use warnings;
  9. use strict;
  10. use Getopt::Std;
  11.  
  12. our($opt_u);
  13. getopts('u:');
  14.  
  15. #Get the results from /etc/groups
  16. my $groups= `grep -w $opt_u /etc/group`;
  17.  
  18. #split it into an array for per line processing
  19. my @split_groups= split(/\n/, $groups);
  20.  
  21. #output the username we're looking for ( to emulate groups better)
  22. print ("$opt_u : ");
  23.  
  24. #where all the magic really happens
  25. #split the array again, and output the first part of the split, as based
  26. #on the strcuture of the /etc/groups file
  27. foreach (@split_groups){
  28. my @temp_split= split(/:/, $_);
  29. print ("$temp_split[0] ");
  30. }
  31.  
  32. #clean up
  33. print ("\n");

So after writing the code above originally, the interviewer looks things over and asks me a couple of questions. I don't remember all of them, the only one I can remember now ( almost two weeks later ) is below:

“Why are you using calling out instead of using a system call?”
After looking around, PERL's systems calls abilities are fairly minimal. I could open a file, and parse through it. But I figured why not save myself some of the work and use the tools in the shell to ease my work.

Regardless, if you are in preparing for an interview maybe this might give you a leg up. Or at least now other interviewers will have to start using a different question.

Examples of how NOT to get a job

In my search for my first job after graduating college, I applied to any job that I was remotely capable of doing, whether because I'd done the job in the past, or the skill set sounded very similar to what I was doing at PSU. And for all of December I was applying for jobs and not getting any kind of response for my efforts. So like any human being I became frustrated, Probably more so than I should have been, but regardless, I was frustrated.

So when applying for jobs, I let that frustration out in some of my online application questions.

Do you consider yourself an expert in Linux?
“No. Even though I've been playing with it for over ten years and I am consonantly being challenged by it. All the new features that come out with each kernel version just keep things new and interesting. Linux itself is a moving target, and I feel the only people that can call themselves linux experts are the kernel developers. Everyone else is intermediate, including me.”

And of course this little nugget of pure angst:

Please read the job description below and tell us why you are a great fit for this position.
“Although I am a recent college graduate. And I know that in this bad economy that there are better qualified people for this job I can offer a couple of things that they can't. Because the other people might be better qualified, they will also be better qualified for other jobs once the job market improves, thus anyone you hire will probably leave sooner as opposed to later. I on the other hand have a lot of growing to do, and finding an environment that allows me to do such would be beneficial to everyone. I can attain the same level of skill as these other candidates, but I will also do it for cheaper ( as I have little experience now) and will probably stay longer because I need to build up the time to build up the experience.”

Both of these questions came from two different job opportunities, and I'm sure you are just as surprised as I am to hear that neither of these companies have contacted me. Which is kind of sad in a way because if one of them did, I would know that THAT company is one worth working and toiling for because it at least has some semblance of a sense of humor. Alas, no love for the little angry wanna-be worker bee.

On the positive side, I have received a job offer from one company. So the hard work is done. I'm going to ask for some time to finish up what current interviews I have left, and see if any more job offers roll in before deciding which job to take.

UPDATE: Never tell the CEO of a social networking company that social-networking is "nothing more than self-aggrandizement and is just a fad".

Blocking html links in anonymous Drupal comments

Time for another update on the battle against spam.

Mollom has been great in fending off the large amounts of spam on the other site I run Freaky Tiki Productions. But I allow anonymous comments to be posted so you know that is just a breeding ground for spam comments. And last year for some reason a lot more html linked spam comments were getting through... and to say that it was annoying would be the biggest understatement of last year ( maybe even this year but its too soon to tell).

So I decided it was time to change to that, but I wasn't sure how. I didn't want to give up on the anonymous comments, but I had to stop people from posting linked spam. But after some tinkering I found a solution:

once logged into Drupal, and under the Administer-> Site Configuration-> Input Formats.

1)Click Configure for Full HTML

    A.Un-check the box to allow unauthenticated users access to Full HTML

2)Return to Input Formats (the link at the top of the picture works well)
3)Set Filtered HTML to be the default
4)Under the Filtered HTML Edit tab
    A.click on the Configure tab at the top

    B.inside the “Allowed HTML tags” input box, remove "bracket a bracket"

And that is it. You have now disallowed anonymous users from using full html when posting comments and also stopped them from creating html links within said comments.

This has done wonders for me in cutting down comment spam. Next up, try to figure out the same thing for the name used when posting comments. The war continues!

Tweet Dump part 3

Welcome back to another, and probably the last, instalment of the tweet dump project.

The old tweet dump code was done locally. I wanted to see how things would be affected if I ran the tweet dump code to a remote server. Just to get an idea on how travel would affect latency.

So I changed things up a bit, I created a sql database through my hosting provider and imported the schema into the remote database. At which point I also modified up the tweet dump code to use this new remote database. And after running the python script 5 times, here are my numbers:

Run 1 43.998
Run 2 46.352
Run 3 45.029
Run 4 55.024
Run 5 49.174
Average 47.92

In my tweetdump code I have a lot of going back and forth between the server and client;

  1. def getId(in_id):
  2. sql = "select id from ids where twit_id = '" + in_id + "'"
  3. return runQuery(sql)
  4.  
  5. def addId(in_id):
  6. sql= "insert into ids values (null, '" + in_id + "')"
  7. runQuery(sql)
  8.  
  9. def addTweet(in_id, in_tweet):
  10. sql = "insert into tweets values ('" + in_id + "',\"" + in_tweet + "\")"
  11. runQuery(sql)
  12. ...
  13. site_id = getId(ids[j])
  14. if( not site_id):
  15. addId(ids[j])
  16. site_id = getId(ids[j])

When you see the three functions making up the code block near the bottom, you might realize that there are three seperate sql calls to the server. And while this might be fine for a local database, this is not good for a remote one. So I decided to try my hand at creating a sql function to reduce some of the back and forth between the two entities.

  1. delimiter //
  2.  
  3. drop function if exists `get_set_ids`//
  4. create function get_set_ids( in_tweet_id BIGINT )
  5. RETURNS int(10) unsigned
  6. BEGIN
  7. DECLARE new_id int(10) unsigned;
  8. select id into new_id from ids where twit_id = in_tweet_id;
  9. IF ISNULL(new_id) THEN
  10. insert into ids values (null, in_tweet_id);
  11. select id into new_id from ids where twit_id = in_tweet_id;
  12. END IF;
  13. return new_id;
  14. END //
  15.  
  16. delimiter ;

The function above takes the guess work away from the client, and keeps it within the server. By doing this we avoid and entire round of communication between the client & server. So in theory we should see at least some kind of speed-up.

With the function above created I then went and modified the script to take advantage of the function:

  1. def get_set_id(in_id):
  2. sql = "select get_set_ids(" + in_id + ")"
  3. return runQuery(sql)
  4. ...
  5. site_id = get_set_id(ids[j])
  6. addTweet(str(site_id[0][0]), final_texts[j])

After a bit of testing to make sure things worked, I ran five timed tests (on the same hardware and from the same location, to try and reduce any variables that might crop up).

Run 1 25.948
Run 2 24.35
Run 3 26.181
Run 4 24.667
Run 5 25.352
Average 25.3

The difference between the two averages is about 22 seconds. And to be honest, I did not expect these changes to cut down my times by about half. This was a little bit of a shock to me. I guess in this end this is an example of how design can really matter.

Syndicate content