Coding Standards

About

Link: Operation Fahrenheit: "The Hacker News" Hacking Awards : Best of 2011


operationfahrenheit:

2011 has been labeled the “Year of the Hack” or “Epic #Fail 2011”. Hacking has become much easier over the years, which is why 2011 had a lot of hacking for good and for bad. Hackers are coming up with tools as well as finding new methods for hacking faster then companies can increase their…
17 notes
Reblogged from operationfahrenheit

A “FizzBuzz” Faux Pas

by ALAN SKORKIN on APRIL 18, 2010

A little while ago while writing this post, I came across the post by Jeff Atwood where he talks about the FizzBuzz test (originally foundhere). I remember seeing that post for the first time a couple of years ago and thinking that I would be a little insulted if someone asked me to write something that trivial in an interview. Seeing it again the other day I realized that my feelings hadn’t changed. It IS an insulting question. Sure you may quickly weed out complete incompetents by asking it, by you will also alienate just about every competent developer. There is really no reason to ask a question that simple. You might as well ask something more complex, that could really test a programmer’s skills. The incompetent will still have no chance, and you won’t make the decent developers feel like you’re making fun of them. If you can’t think of any interesting programming questions to ask (and you don’t like my quine question :)), I will try and cover a few decent, straight forward coding questions at some point in the future. But, that’s not what this post is about.

Read More

11 notes fizzbuzz

Write A Function To Determine If A Number Is A Power Of 2

by ALAN SKORKIN on OCTOBER 18, 2010

One of my friends always asks that question when interviewing developers. Apparently it’s quite ambiguous and many people misunderstand – which is curious since I thought it was rather straight forward, but that’s not what this story is about.

When he first told me about this question my brain immediately went ahead and tried to solve it, as your brain probably did as soon as you read the title of this post, if you’re a developer :). After thinking about it for a couple of minutes I said that people should get extra points” if their function uses bit hackery to solve the problem. I later realised that the most interesting thing about this was how I arrived at that conclusion.

The First Thing I Thought Of Was…

Something along the lines of the following:

def power_of_2?(number)
 return false if number == 0
 while(number % 2 == 0)
   number = number / 2
 end
 return false if number > 1
 true
end

Read More

power of 2

When Developers Go To Great Length To Save Typing 4 Letters

by ALAN SKORKIN on AUGUST 24, 2011

Great LengthsHeroku is a great platform. Long before I joined and when I say long, I mean in startup terms (i.e. a few weeks before I joined :)) – the decision was made that CrowdHired would be hosted on Heroku. Shortly after I came on board, Heroku released their new Cedar stack and we quickly migrated across to that. I find it kinda amusing that we’re currently in alpha, deploying to a platform that’s in beta. Latest and greatest FTW. While migrating to the new stack we also settled onThin as our web server. The Cedar stack allows you to use whatever web server you want in production and will run on Webrick by default – not ideal. Since we were going to use Thin in production it made sense that we’d also use it in development instead of Webrick.

Read More

Google C++ Style Guide (a must see & read & learn)

Background

C++ is the main development language used by many of Google’s open-source projects. As every C++ programmer knows, the language has many powerful features, but this power brings with it complexity, which in turn can make code more bug-prone and harder to read and maintain.

The goal of this guide is to manage this complexity by describing in detail the dos and don’ts of writing C++ code. These rules exist to keep the code base manageable while still allowing coders to use C++ language features productively.

Style, also known as readability, is what we call the conventions that govern our C++ code. The term Style is a bit of a misnomer, since these conventions cover far more than just source file formatting.

One way in which we keep the code base manageable is by enforcing consistency. It is very important that any programmer be able to look at another’s code and quickly understand it. Maintaining a uniform style and following conventions means that we can more easily use “pattern-matching” to infer what various symbols are and what invariants are true about them. Creating common, required idioms and patterns makes code much easier to understand. In some cases there might be good arguments for changing certain style rules, but we nonetheless keep things as they are in order to preserve consistency.

Read More

3 notes

operationfahrenheit:

Stuxnet: Anatomy of a Computer Virus

by Patrick Clair

This short film discusses “Stuxnet”, the most complex and dangerous computer virus in the world. It is pretty intriguing considering they don’t know who is behind its development. It was initially released on Iran’s nuclear power plants. Stuxnet is considered the first military weapon made entirely out of computer code. The scary thing is, Stuxnet is available for download on the internet.

Reblogged from operationfahrenheit

operationfahrenheit:

 

Operation Titstorm : cyber activism

a video made by Patrick Clair

Reblogged from operationfahrenheit

operationfahrenheit:

Infographic - Wikileaks Profile

by Patrick Clair

(Source:vimeo.com)
Reblogged from operationfahrenheit

Duqu: Status Updates Including Installer with Zero-Day Exploit Found

The group that initially discovered the original Duqu binaries, CrySyS, has since located an installer for the Duquthreat. Thus far, no-one had been able to recover the installer for the threat and therefore no-one had any idea how Duqu was initially infecting systems. Fortunately, an installer has recently been recovered due to the great work done by the team at CrySyS.

Read More

(Source:symantec.com)
15 notes duqu symantec security worm virus zero day exploit

C++ Log File Class

C++ can become very difficult to use especially with large projects where you can’t see all the variables. Here’s a very simple C++ logging class that can take logs for your software without any effort. This will make you a better programmer as you won’t have to rely on debuggers like in Microsoft’s Visual Studio.

First you should create a project, with files like log.h and log.cpp. Let’s show you the log.h file:

#include <fstream>

using namespace std;

class Log {
  
public:
    
Log(char* filename);
    ~
Log();
    
void Write(char* logline);
  
private:
    ofstream m_stream;
};

Read More

c++ log file c++ log

C++ Volatile Keyword

Volatile keyword can be specified for any C++ variable in order to tell the compiler that the variable should not be optimized. I’ll show you what this means and why this Computer Engineering secret is very rare to find in any code. It’s used in multi-threaded code orembedded system designs.

Take this code for example:

volatile int importantCheck;

void InterruptOrThread(){
  importantCheck = 5;
}

void main(){
  importantCheck = 0;
  CreateThread();
  ExecuteActions();
  DoEvents();
  if(importantCheck == 5){
    LaunchProgram();
  }
}

If we did not have the volatile keyword on importantCheck integer, then the compiler will optimize this code, because the InterruptOrThread() function isn’t called directly by the main thread, but it is called as a thread or an interrupt in an embedded system.

Volatile means that the C++ variable should not be optimized.

The compiler will remove the check “importantCheck == 5” and it will remove the LaunchProgram() function, because the compiler believes that it’s a mistake and that importantCheck will never be 5, so it removes it.

Volatile is used in multi-threaded or interrupt driven programs because the compiler shouldn’t optimize all variables because compilers cannot understand threads very well.

13 notes c++ volatile

C++ Threads

C++ Threads are useful for doing more than one thing at the same time, or have a loop do your work while the rest of the program continues to operate at the same exact time.

First off we need to include <windows.h> and <stdio.h>. These provide us with the basic functions need for threading, and stdio.h provides us with very basic functions useful for most applications.

toc_collapse=0;
Contents [hide]

Creating The Thread

Now, we must create the thread. First off, declare the thread. I’m going to call mine threader, you can name your thread whatever you like. (Hint: Declarations go outside of functions)
DWORD WINAPI Threader( LPVOID lpData );
That is what I always use for my threads, then I just change the name to fit my needs.

Remember to include in your files.

So now make the function for the thread. You do this by copying the declaration we just made, and replacing the ; with { signaling that we are going to place some code there.

Read More

4 notes c++ threads

C++ Buffer Overflow Exploit

When you have a certain amount of bytes allocated for a buffer and someone enters more bytes than you allocated, this is called a buffer overflow or buffer overrun. It is a very serious security threat and many programmers make this mistake, even experienced programmers. You must secure your code, otherwise someone can inject code directly into your system using your program. These C++ security exploits can be used in any language, even on websites.
Remember that the following code should be used for educational purposes and to improve your security in programming.

Vulnerable Password Program

Read More

19 notes c++ Buffer Overflow Exploit

Code’s Readability

Use Tabs To Indent Your Code

This one is a no-brainer. Code indentation is essential when it comes to readable code. There are a lot of ways of indenting your code and I am not going to advocate for one of them. I’m simply going to show you how you are notsupposed to write code, and then, I’m going to show you one of the ways of properly indenting code.

//      Don’t write code like this…
int main()
{
int variable;
cin»variable;
if(variable>2)
{
cout«“Variable is bigger than 2: “«variable;
}
else
{
cout«“Not bigger than two: “;
while(variable)
{
cout«variable«” “;
}
}
}

Read More

c++

Substitution Cipher in C++

A substitution cipher is probably the simplest cipher to implement and, at the same time, it is also the easiest cipher to break.

The algorithm is quite simple. Let’s consider an alphabetical string, and a number — the offset. What we’re going to do is this: replace each letter with the letter that’s “number” positions ahead of it. So we’ll be shifting each letter a few positions ahead. For instance, if the offset number is 2 then the letter “a” becomes “c” (since “c” is the 2nd letter after “a”), “b” becomes “d”, “c” becomes “e”, or “z” becomes “b”, etc.

Read More

1 note c++ Substitution Cipher Cipher