Pop Quiz

So, while at work you wrote some scripts. And after a code review your boss tells you that he would like to see some variable names changed, to help make the code more readable. So at the beginning of your code you have:

#set script variables
use vars qw/ %opts /;
my $append="\@pdx\.edu";

getopts( 'hrl:m:',\%opts );

#make sure the arguments are provided, fail if #not
usage() if ( $opts{h} || (!$opts{m} || !$opts{l}));

#everything's good, program can start now
my $ldap= signin('true') || die;

#rename variables from opts to something more #"readable"
my $username= $opts{l};
my $mail_alias= $opts{m};
my $remove_flag= $opts{r};

But below this code section, $opts is being called quite a few times, and the script is another 100 hundred lines of code or so. So what do you do?

1)Tell your boss how adding these variables will reduce efficiency and the overall speed of the code and revert the variables name.
2)Do the changes manually
3)open up vim or use sed with the expression s/$opts{}/$/g
4)I don't care... but I do want to see what you think
5)Other (Please leave a comment. How else will the rest of us learn?)

Answer:

Okay, this isn't the “only” answer, but it is what I did. Opened up VIM, and used the following commands:

:32,$ s/$opts{l}/$username/g
:32,$ s/$opts{r}/$remove_flag/g
:32,$ s/$opts{m}/$mail_alias/g

For those of you not familiar with this let me explain. In the first block of text, “:31,$”, the “:” is just a way to signify to vim that your going to preform a command. The “31,$” is telling vim to limit the following command between line 31 and the end of the file (which is what $ means). And then the second part s/$opts{l}/$username/g the command itself. For those of you who are not familiar with sed syntax, it says that your going to substitute an instance of $opts{l} for $username. The ending g means to it more than once.

So when you put the whole command together you get, between line 31 and the end of the file, replace all instances of $opts{l} with $username.

Hopefully this will help someone else as much as it helped me.

Prime Number Generator Project Pt. 1

NOTE: Sorry for the delay in posting. School is hitting me rather hard as of late, and will continue too until the end of the month. Thus until September posts are going to be a little sporadic... unfortunately. :(

I'm fascinated with the idea of doing real world calculations on the GPU. The idea just seems to make sense to me. You have this piece of hardware in almost all machines today that is around to do one thing really quickly, and that thing is to crunch numbers so video games can look good. And unless your playing video games that card is mostly sitting in the background just sucking up energy and maybe helping to provide some nice eye candy for you desktop.

But within the last couple of years this idea has been changing. People are figuring out ways to make this super calculator to do more general purpose math manipulations. And now you have the idea of GPGPU, which means General Purpose computation on Graphics Processing Units. And of course like a good geek, I want to play with this.

Of course, before I start to play with CUDA, I needed to come up with a baseline. Which leads me to ask myself, “What am I going to program?” After some time, I decided I would program a prime number generator. My next step was to code up a basic prime number generator, using just a simple algorithm.

Again, nothing very special going on here. Taking some basic liberties with calculations, like just giving the value of 2 & 3 as prime, and starting to run calculations after 3. Also avoiding all calculations of even numbers. Pretty simple stuff. And I'm positive that if I wanted to I could tweak the current algorithm some more to squeeze an extra drop or two of performance out of it. But that wasn't the point of this. This program above is to just give me a baseline of performance . So as I now start to play with CUDA and GPGPU I can get an idea on how much performance might be gained.

And of course, what would be the point of creating a baseline if I din't include the numbers of running this program.

Iterations Times (in seconds)
10 .001
100 .001
1000 .002
10000 .018
50000 .343
1000000 1.570
5000000 30.760
750000 64.410
1000000 109.660
5000000 2301.504
10000000 8713.000

And as the table shows, not only is the code simple... its get to be really slow with a really large number.

Next stop; somehow putting this code into CUDA and seeing what kind of performance improvement can be derived.

Flash Tutorial: Hello World Button pt. 2

Welcome to another installment of this Flash “Hello World” tutorial. In this tutorial I'm going to show you how to change the color of the button when you click on the button. Its really quite easy, and should only take us a minute to do. Let's get right to it.

I'm going to assume that you've kept your fla file from the previous tutorial. If not here is a copy of mine, feel free to start with that. (Or if your just joining us and have no real starting place.)

So with your “Hello World” button in front of you, its time to make it perform an action. Let's right-click on the text and choose “Edit”. At this point you'll notice that the timeline has changed.

In short, you can modify these to make the button look differently depending on the action involved. So, within this new timeline, right-click on the square under “Down”. (And within the menu click “Insert Blank keyframe”. You should be aware of two things: 1) your black “Hello World” is gone. 2) The layout of the timeline has changed. Well, the answer to one is, you want it blank, that is how you get to have multiple images in one button. And I'm not sure why the timeline changed, but when I find out I'll let you all know.

So within the blank page, go and copy this image just like you did in the previous write up. And now if you test with a little Control + Enter (on windows) you'll see your new button in action. See, I told you this was going to be easy.

If you decide to do the same thing with the “Over” section instead of the “Down” used above, you'll get your button to change when your mouse goes over the button, as opposed to clicking on it.

In the next tutorial, which I believe I will have next week, I'm going to go over how to make the button to go to a website when you click on it.

A Tale of a Failed Social Engineering Attempt

In computer security you hear a lot about Social Engineering, and for good reason. As far as computer security goes the human being really can be the weakest link, knowingly or unknowingly. And if your curious on examples or stories of social engineering I recommend the book " The Art of Deception" edited by Kevin Mitnick.

(NOTE: the book link goes to amazon and is linked to my partner id. No pressure to purchase, I just believe in full disclosure.)

However, not all social engineering has to be for technical reasons or even technically related. I say this because up until a couple of days ago, that is really how I generally thought about it. Granted I realize that social engineering is something that anyone can use for any reason. But as someone who lives and breathes computers, I tend to forget that there are things outside the world of binary computations.

Here in Portland, the last weekend of July is host to the Oregon Brewers' Beer Festival. And for the last three years I've volunteered as a server. The way the festival works is you buy a 12oz mug (pictured below). If you look at the mug you can see about the last 1/3 of the cup has a different shape than the top two thirds. That change is the taster line at 4 oz. And at the festival you pay one dollar to fill up a particular beer to that line. If you want a full cup of beer its four dollars. And to help with making sure that all of the servers are honest, instead of the transactions being done with money, the transactions are done with wooden tokens worth a dollar each.

Now just by the very nature of people, some are going to try and cheat the system. I've dealt with drunk people, and some that were less than friendly, but never someone who was trying to cheat the system, but to be honest until this year I never saw it (or at least I was never aware of it being done to me)

At some point in the evening, a very pretty brunette in sunglasses approached my booth. She holds out her hands, in her right hand is her cup and in her other hand is two tokens. Not saying a word I grabbed one token from her hand and proceeded to fill her cup to the requisite line. I put the cup back in front of her, and expect her to leave. Instead she looks at me and says “I'm sorry, can I get a full cup please?”. At which point I say “Sure, I just need three more tokens from you.” So she digs into her purse and proceeds to pull out two more tokens. And says, “Here you go.”

“I'm sorry, I your still one token short.”

“What about the two tokens I gave you to begin with?” This is where the actual trap sprang. Being I'm not actively paying attention for this, just kind of on auto pilot, I second guess myself. And try to remember what happened before, just to make sure that I only took one token. And I remember that I do and say, 

“Your right, but I only took one token from you. So your still one token short.”

“Are you sure?”

Taking a quick second to verify then I say, “Yup and when it comes to beer I don't fuck around.”

At which point she sighed, and proceeded to reach into her purse to grab me another token. At which point I handed her her glass, and she walked away.

Now I must be honest, I didn't recognize this attempt at subterfuge until after the interaction was over. While I was going through it I was trying to make sure I was correct with what I was saying. If it was a more sophisticated attack, she might have gotten away with it.

I will say that after going through this experience, I'm more aware of how easy it is to succumb to social engineering. And now I also have a bit of compassion and sympathy for those people to get socially attacked like this but are not aware of it till maybe after it happens to them.

Syndicate content