(jQuery) Get Latitude and Longitude using jQuery and Googles Geo Coding Service

Nice ajax function to grab the latitude and longitude of an address or postcode. Don’t forget your google key and address formatting.

Read More »

→ Continue Reading

(C++) Nasdaq IPOs Scrape

This is a C++ program that scrapes IPO data from Nasdaq.com using libcurl for downloading the data and htmlcxx for parsing the html code.

Read More »

→ Continue Reading

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 and relatively prime to (p-1)(q-1), which means e and (p-1)(q-1) have no common factors except 1. Find another number d such that (ed – 1) is divisible by (p-1)(q-1). The values e and d are called the public and private exponents, respectively. The public key is the pair (n, e); the private key is (n, d). The factors p and q may be destroyed or kept with the private key.

Large prime numbers can be found with a primality test. A primality test will determine whether a number is prime or composite. The C# console application below is able to check whether a supplied number is prime or composite and able to randomly produce large prime numbers. Two methods for primality testing are used. Namely, Fermat’s little theorem for pseudo primality testing and the Miller-Rabin primality test.

The primality test based on Fermat’s little theorem is probabilistic and will produce errors for numbers such as 341 and 645 whereas the Miller-Rabin primality test is deterministic.

The theory in chapter 31.8 of Introduction to Algorithms has been used for the implementation. Thus, major credits to Thomas H. Cormen, Clifford Stein, Ronald L. Rivest and Charles E. Leiserson.

Read More »

→ Continue Reading

(JavaScript) Observer-Pattern in JavaScript

Could be improved by passing an event instead of a simple payload.

Read More »

→ Continue Reading

(C) Dijkstra’s Shortest Path algorithm

Its Dijkstra’s Shortest Path algorithm written in C. Reads from a file the nodes and the connected edges and implements Dijkstra’s algorithm. I am uploading for your comments in my code. Thank you.

Files content should be in the format:
n N
startNode endNode distance
startNode endNode distance
.
.
.
startNode endNode distance

where n is the total number of Nodes and N is the total number of Acnes.

Read More »

→ Continue Reading

(C#) Download text or bytes via HTTP

Downloads contents as a byte array or string, depending on need.

Read More »

→ Continue Reading

(C++) linked_list class (both the header file and the template file)

This is a linked list that can be used like an array where instead of using [] after the reference you just used .get() (and some other methods) but now you don’t have to worry about sizing.

For example, with an array you would do:

cout

Read More »

→ Continue Reading

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.

Read More »

→ Continue Reading

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.

Example of a Huffman tree

Read More »

→ Continue Reading

(Java) Fun with Fibonacci, Golden Ratio and Factorials, with loops vs recursives

 

Read More »

→ Continue Reading