One Step Security - Prevent most malware in one single step
Posted by: JordanSebastian
DISCLAIMER: This technique may not work on all system configurations. There are some software packages that require you to run in System Administrator mode. These packages are far and few between but be aware that they do exist which may make this technique impractical for your particular application.
Since windows security is always a problem. I'm going to show you one single techieque that will protect you and your system for a good portion of viruses and malware. Here's the secret:
Don't run as and Administrator. Most of you won't know what I mean by this so let me explain. Administrator accounts have access to the entire operating system. Anything installed, is system wide. Most people won't even know they're logging into an account because they only have one account. To add, remove, and see information about accounts click on Start->Control Panel->Users Accounts.
There you will see every user on your system Odds are you'll see a guest account (which should be turned off), your account and maybe otheres on the system. The first thing to do in this screen is to check what permissions your account has. Under the name of the account you will see either "System Administrator" or "Limited Account". If your account says "System Administrator" then you are at more risk of infecting your computer with a virus than if t says "Limited Account". So here's the general setup of what we're going to do allong with instructions to fix the problem.
1. Create a new "Limited User" account. Under User Accounts click on "Create a new Account". Fill in the name and information, then select "Limited" when asked what permissions this person should have. Accept all the settings.
2. Use this account for 90% of everything you do. Surfing the web? Use your limited user account. Playing games? Use your limited User account.
3. Password Protect your Limited account as well as your System Administrator account. To do this click on the name under User Accounts, then click on the "Change Password" button.
4. If you need to install software, change a system configuration, or other administrative task. Save what you're doing, log out of your Limited account and log back into your System Admin account. This will allow you to do what you need to. Just remember to log back out of Admin and back onto your Limited account when done.
This may sound like a lot to do. After all it is an extra step. However, this one extra step will save you from the greater majority of problems in the future. Besides, you probably won't find yourself switching back and forth very often. The number of times you actually need an administrator account is very few.
Two Variable Swap
Posted by: JordanSebastian
If you're like me, you're always looking for the coolest and most elegant way to do things. Here's a problem I've had for a while.
void swap(int &a, int &b)
{
int tmp = a;
a = b;
b = tmp;
}
Why use the extra variable? A variable for what?! NOTHING!!! So I was working out to day and for some reason I get wonderful ideas when I work out. I decided to try to come up with an algorithm that will be just as efficient and take up only two variables. Sadly, people have beat me to it. Here's my solution anyways:
void swap(int &a, int &b)
{
a = a + b;
b = a - b;
a = a - b;
}
Sure, I'll admit, maybe we've missed the mark as far as efficiency goes. More so, perhaps it's not as self documenting. But when you're in a large function and you all the sudden need to do a swap and don't want to declare an extra variable just for that reason, you can use this little trick.
Oh and if you want to be 1337 about it, figure out how to use XOR to do the same thing. It's probably more efficient since it's bit level.
Here are a few time results from using the UNIX "time" command replacing each function only. Here is my two variable way to do it:
Real: 0.012s
User: 0.005s
Sys: 0.007s
The Three variable method gave the exact same resluts as did the XOR method. So, unless you're really worried that you calling the function "Swap" won't be documentation enough, or you're avoiding comments, it's much more elegant to use my way or the XOR method. Here is the XOR algorithm:
void swap(int &a, int &b)
{
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
Although it's essentially the same thing, I think it looks prettier than my method. There's some extra elegance to it.
Virtual Private Assistants
Posted by: JordanSebastian
I thought i'd talk about this becuase it's gotta be one of the most interesting thing's i've seen in a while. It's called a Virtual Private Assistant, and they're available cheap! It's not so much virtual as it is an actual person who will do anything you require as long as it can be done on the internet or over the phone. Some companies offer these assistants as low as $5.00 an hour and I've heard of them being as cheap as $3.00 an hour. How does it work?!
Well, it's simple really. It's all a matter of outsourcing your responsibility and work load. The person you hire is typically from India or Jamaca and speaks perfectly fluent, easy to understand english. So why use one? Here are several reasons why you might want to give this a try.
- Screen your email
- Send weekly emails
- Call you to remind you of something or to gain information about an email they're going to send. Got a meeting every week but the details can change? Your VPA will call you to get those details and send the email out for you.
- "Chase" people. Can't ever get ahold of people or just never run into them to get information from them? Your VPA can do all of this for you.
- Summerize documents
- Research topics
- Schedule apointments
- Much More!
Again, like I said, VPA's can be an extreamly cost effective way to get the stuff you don't want to do, done. Sure most of this you could do your self, but think about the time you'd save and the headache you wouldn't have to deal with in your every day, weekly or even monthly life.
Here are a few Resources:
http://www.longerdays.com/?gclid=CKOT3uicqpYCFQSwFQod0W-Yzw
http://www.taskseveryday.com/?_kk=virtual%20personal%20assistant&_kt=8d43cbdd-4d97-4a54-a644-82c80c7c2b77&gclid=CIiPqoCdqpYCFRoSFQodLTp0zg
Elegant Code pt 2 of 2
Posted by: JordanSebastian
Most people don't understand that relational operators ALWAYS return a boolean values. You don't have to use an if-statement to get a boolean values. Lets look at a quick example
(Not so Sexy)
bool isEqual(int num1, int num2)
{
bool tf;
if(num1 == num2)
tf = true;
if(num1 != num2)
tf = false;
return tf;
}
What I want to convey is that the boolean operators will do exactly what these if statements would do. Here's the cleaned up code.
(Very Sexy)
bool isEqual(int num1, int num2)
{
return (num1==num2);
}
Did you notice what I did here? the == operator (and any relational operator) will automatically return a boolean value. When ever you say "num1 == num2" this is a comparison and the result is a boolean value. Lets look at another example.
Quick question: What is an if statement? An if statement says one thing: if the statement in the parenthesis is true, then execute the code assigned with the if statement (inside the {}'s or the very next statement). So this tells us that the statement: "if(true)" will always be executed (so never write that, you may as well just remove the if statement). Similarly the statement "if(false)" will never execute. This may sound obvious but I'm trying to make a valuable point. Lets look at another example:
int something(int goofy, int mickey)
{
//Returns the bigger number
bool isBigger = (goofy > mickey);
if(isBigger == true)
return goofy;
if(isBogger == false)
return mickey;
}
(Angelina Jolie)
int something(int goofy, int mickey)
{
bool isBigger = (goofy > mickey);
if(isBigger)
return goofy;
}
We did two major things here. Why go to the trouble of doing two comparisons. We already have the answer stored in "isBigger" so lets just put it to use! Also, we knew that if isBigger was true, the only other possibility was it was false, so why test for it? We'll simply return it.
NOTE: that trick only works if you're leaving the function with a return statement (or maybe a loop with a break statement).
Play around with these concepts. Remember that boolean values work by themselves, without more tests of "true == true" or "false == true". And comparison operators return boolean values with or without a if or while statement. All those statements say are "while( this is true)" or "if (this is true)".
Code Elegance pt 1 of 2
Posted by: JordanSebastian
Elegant code serves several purposes. First elegant code is efficiant. This is a major goal. The more elegant the solution, the more efficant it tends to be. Secondly Elegant code is readable. This may seem contrary to efficancy, and this may be true to some extent, but that's what makes it elegant. It finds a balance between efficancy and readability. Many times (in examples we'll soon see) there is no trade off. It is as efficant as it is easy to read. Finally, elegant code is simple. This will be an overriding theme. Easy to read + efficiant almost always produces simplicity. Lets look at an example:
Lets assume that your task is to create a exponent function where you raise any x to the power of y. This exmaple will show two major goals of elegant code.
(The Wrong Way)
int pow(int x, int y)
{
int i;
int final = x;
for(i=y; i>0; i--)
{
final = final + x*x;
}
return final;
}
(The Right Way)
int pow(int base, int expo)
{
if(expo == 0)
return base;
return ( base * pow(base, expo-1) );
}
Dosn't that just look nicer? The right way takes advantage of several things which make it better code. We'll start with the top and work our way down.
First and foremost we changed what we called our variables. These are much more readable. It's not always bad to use variables such as 'i' or 'j' but typically these are used as incremental variables only. If you are actually storing data, name them something descriptive but keep it short. When in doubt, use descriptive variables.
Next we take advantage of C++ (and almost every other language's) ability to do one line if statements out {'s. This makes things look much cleaner. Keep in mind however, you can only execute one comand after such a statement. For our situation, this isn't a problem.
FInally we made sure to use recursion. It seems no one's comfortable with recursion. Personally, it scares me but its simplicity and elegance make it very powerful. Start looking for ways to use recursion in your software. It'll help you out tremendously in the long run.
Next installment, we'll be looking at the most under-raited and missunderstood data type in the programming world, and how to use it to create elegant code.
Quick Update
Posted by: JordanSebastian
It's homecoming and we got a Uhal...
I've changed the entire layout of the webstie as well as minimuzed the number of blogs I have to 1. I'm working on a 3 part series coming up very soon on elegant code.