Skip to content

Instantly share code, notes, and snippets.

View markusl's full-sized avatar

Markus Lindqvist markusl

  • Supercell
  • Finland
View GitHub Profile
@markusl
markusl / IpToCountrySlow.cpp
Created July 16, 2011 15:32
C++ class to map IP addresses to countries using database from http://software77.net/geo-ip/
#include <string>
#include <fstream>
#include <vector>
#include <sstream>
#include <algorithm>
#include <stdexcept>
std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
std::stringstream ss(s);
std::string item;
@markusl
markusl / IpToCountry.fs
Created July 13, 2011 15:35
Fast F# API for IpToCountry.csv - Class for mapping IP addresses to countries in FSharp using GPL'd CSV database from http://software77.net/geo-ip/
module IpToCountry
open System
open System.IO
type CountryCode = { code : string }
type IpAddressMapping = { cc : CountryCode; startAddress : uint32; }
/// Class to store the IP-addresses in 255 different buckets
/// countryIpList = The list of IP address mappings to store in this intance
@markusl
markusl / IpToCountrySlow.fs
Created July 12, 2011 17:12
Slow F# API for IpToCountry.csv - Class for mapping IP addresses to countries in FSharp using GPL'd CSV database from http://software77.net/geo-ip/
module IpToCountry
open System
open System.IO
/// Construct new class for mapping ip addresses to countries using
/// database from http://software77.net/geo-ip/
type IpToCountrySlow(?fileName) =
let fileName = defaultArg fileName "IpToCountry.csv"
// Read all non-comment lines
@markusl
markusl / FinnishSSN.fs
Created July 11, 2011 17:00
Finnish social security number calculator in F#
open System
/// Finnish social security number calculator in F#
/// Suomalainen henkilötunnuslaskuri F#:lla
module SSN =
let getSeparator year =
if year < 1900 then '+'
else if year < 2000 then '-'
else 'A'