Author Archives: Ferhat

DLL injection in C++

DLL injection in Windows can be used to inject a DLL into a process and to take over/extend functionality. For example, the distribution platform Steam uses DLL injection for the game overlay.

Posted in C++ | Tagged , , , , , , , , , , , , , | 5 Comments

Primality testing with Fermat’s little theorem and Miller-Rabin in C#

Prime numbers have many applications. For example, in cryptography. The RSA algorithm for public-key cryptography uses large prime numbers for generating keys. Quote: The RSA algorithm works as follows: take two large primes, p and q, and compute their product n = pq; n is called the modulus. Choose a number, e, less than n [...]

Posted in C# | Tagged , , , , , , , , , , , , , , , , , | 2 Comments

C# code execution at runtime with the Microsoft Roslyn CSharp ScriptEngine class

Microsoft has released the Roslyn CTP which allows developers to use the Visual Basic and C# compilers as APIs. The snippet below can be used to execute C# code at runtime.

Posted in C# | Tagged , , , , , , , | Leave a comment

Huffman coding in C#

Huffman coding is an encoding algorithm used for data compression. So called Huffman trees are used for encoding and decoding of data. The leaves of these trees contain the symbols and their frequencies. Each parent node contains the sum of the frequencies of its children.

Posted in C# | Tagged , , , , , , , , , | 11 Comments

Using Bootstrap to fasten the development of webapps and sites

Twitter has just released a toolkit called Bootstrap. Bootstrap includes CSS for Grids, Layouts, Typography, Tables, Forms, Navigation, Alerts and Popovers. Use the following snippet to include Bootstrap in your project. <link type=”text/css” rel=”stylesheet” href=”http://twitter.github.com/bootstrap/assets/css/bootstrap-1.0.0.min.css”>

Posted in Uncategorized | Tagged , , , , , , | 1 Comment

Scaling an image in Objective-C (Cocoa Framework)

The UIImage class can be used to represent an image. The following snippet scales an image according to a size which is provided with a CGSize parameter. + (UIImage *)scale:(UIImage *)image toSize:(CGSize)size { UIGraphicsBeginImageContext(size); [image drawInRect:CGRectMake(0, 0, size.width, size.height)]; UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return scaledImage; }

Posted in Objective-C | Tagged , , , , , , , , , , , | Leave a comment

Run a method in a separate thread in Objective-C (Cocoa Framework)

In some situations, performing operations in a single thread can cause an application to appear as if it is hanging. For example, when searching with autocomplete enabled within a large amount of records in a database . The user is typing and the application is performing a computationally complex operation at the same time (searching [...]

Posted in Objective-C | Tagged , , , , , , , , , , , | 1 Comment

Autocompletion with the jQuery autocomplete plugin

The jQuery autocomplete plugin allows developers to implement autocompletion for text input fields. Suppose you have a dictionary application. You might want to autocomplete words for a user to ease searching.

Posted in JavaScript | Tagged , , , , , , , | Leave a comment

Minimax algorithm with alpha-beta pruning in C#

Minimax is an algorithm where two players (min and max) play against each other for minimizing loss and maximizing gain. The following picture illustrates minimax with a game of tic-tac-toe. The algorithm uses a tree for the moves and scores of each player. In some cases, it is unnecessary for the algorithm to check certain subtrees. [...]

Posted in C# | Tagged , , , , , , , , , , , , , , , , , | 1 Comment