Recently I have been handling the security of some sensitive data. I had originally been encrypting/decrypting data with a symmetric-key system using mcrypt for PHP. This was due to the web frontend and the backend existing on the same server. However for security purposes I am now separating the frontend and backend onto different servers, …
UPDATE: I updated this article with some information about password cracking with the reason to use the algorithms bcrypt or scrypt to store the user’s password instead of hash + salt mechanisms. Moreover, I proposed a new RNG based on the usage of /dev/urandom if OpenSSL is not available.
If you are a professional web developer, …
C++ Copy Constructor passed by value or by reference ?
The parameter in the copy constructor A(A other) is an instance of type A.
When the copy constructor is executed, it calls the copy constructor itself because of the pass-by-value parameter.
Since endless recursive calls cause call stack overflow, a pass-by-value parameter is not allowed in the C++ …
Static Shared Library in C - Linux
1. Create a C file with a function - example :
int addnumbers(int a , int b)
total = a + b;
2. The next step is to complile this file :
gcc -c …
To create the shared (*.so) library, use these steps
Example instructions for compiling
1) g++ -fpic -c CLib.cpp
2) g++ -shared -o libCLib.so CLib.o
3) g++ CLibTest.cpp -o CLibTest -L. -lCLib
C Programming Tutorial in Linux #040 - Dynamic Shared Library
Tell your C++ compiler which instantiations to make while it is compiling your template class's .cpp file.
(If you've already read the previous FAQ, this answer is completely symmetric with that one, so you can probably skip this answer.)
As an example, consider the header file Foo.h which contains the following template class. Note that method Foo<T>::f() …
Google C++ Style Guide
Table of Contents
The #define Guard
Function Parameter Ordering
Names and Order of Includes
Nonmember, Static Member, and Global Functions
Static and Global Variables
Doing Work in Constructors
Copyable and Movable Types
Delegating and Inheriting Constructors
Structs vs. Classes
Write Short Functions
Ownership and Smart Pointers
Other C++ Features
Provide a surrogate or placeholder for another object to control access to it.
Use an extra level of indirection to support distributed, controlled, or intelligent access.
Add a wrapper and delegation to protect the real component from undue complexity.
You need to support resource-hungry objects, and you do not want to instantiate such objects unless and until they …
Since a time_t is only required to represent time intervals of ±68 years, and many implementations use a base year of 1970 for representing the current time, there is an inability for many popular C++ implementations to represent dates and times after 2038. This means that a lot of software could break in 2038, if …
1. Mapping Objects to Databases
2. Active Record
3. Data Mapper
4. Using a Repository
5. Identity Map
6. Lazy And Eager Loading
7. Virtual Proxy Pattern
8. Taking the Next Step
Data access is a popular subject among developers. No doubt you've heard plenty of opinions on specific data access technologies and persistence frameworks, but what's the best way to consume these …
This article aims at understanding when we could find the Adapter pattern useful and how can we have a rudimentary implementation of the Adapter pattern using C# and C++.
It was almost 6 years back, at the very beginning of my career, that one of my clients told me to write an adapter. Back then I …
Design Patterns are names we give code constructs. We’re not usually inventing anything new, we’re just giving a name for things we’ve always done. You’ve probably been doing it this way forever, but you never knew what to call it, it was just “the way it’s done”. Giving it a name …
This piece of code illustrates how your compiler library handles different settings of the TZ environment variable. It also shows
the problematics arising from time zone conversion localtime/gmtime when daylight saving is currently in effect and the time to be converted would have no daylight time set and vice versa.
In your shell set the environment variable …
This is because of structure alignment. Structure alignment refers to the ability of the compiler to insert unused memory into a structure so that data members are optimally aligned for better performance. Many processors perform best when fundamental data types are stored at byte-addresses that are multiples of their sizes.
Here's an example using typical settings …
You have two objects, and you need to know if their respective classes have a base class/derived class relationship or if they are unrelated.
Use the dynamic_cast operator to attempt to downcast from one type to another. The result tells you about the class’s relationships.
Example presents some code for doing this.
Determining class relationships
using namespace …
ODB is an open-source, cross-platform, and cross-database object-relational mapping (ORM) system for C++. It allows you to persist C++ objects to a relational database without having to deal with tables, columns, or SQL and without manually writing any mapping code. ODB supports MySQL, SQLite, PostgreSQL, Oracle, and Microsoft SQL Server relational databases as well …
In this article we will learn to implement a One-To-One relationship between two classes. As in the previous article, at first we will try to understand the best use of a One-To-One relationship.
There might be a situation where we need to implement a relationship between a student and his registration number. In a university a …
In this article we will learn to implement a Many-To-One relationship in a C# class. As in the previous two articles, we will explain the scenario where a Many-To-One relationship is relevant. Think about the situation where we want to represent a relationship between a teacher and a student. It is a very common scenario …
In this article we will see how to implement a Many-To-Many relationship in a C# class. Let's explain a few scenarios where a Many-To-Many relationship is relevant.
The relationship between a Cricket match and Cricketer is one example of a Many-To-Many relationship. One Cricket match is played by many Cricketers and one Cricketer takes part in …
The following macro is not quite as compact as a single-use ostringstream or boost::lexical_cast.
But if you need conversion-to-string repeatedly in your code, this macro is more elegant in use than directly handling stringstreams or explicit casting every time.
It is also very versatile, as it converts everything supported by operator <<(), even in combination.
#define SSTR( …