Skip to content

Instantly share code, notes, and snippets.

@elvinio
elvinio / hanoi.hs
Created February 24, 2015 07:32
Solving the Tower of Hanoi in Haskell
hanoi 0 _ _ _ = []
hanoi n a b c = hanoi (n-1) a c b ++ [(a,b)] ++ hanoi (n-1) c b a
han 0 _ _ _ = []
han n a b c = han (n-1) a c b ++ [(a,c)] ++ han (n-1) b a c
@elvinio
elvinio / AuditReport.hs
Created February 25, 2015 09:59
Audit Report Generator in haskell
import Prelude hiding (lookup)
import Data.Map (Map)
import qualified Data.Map as Map
import System.IO
import Data.List
import Data.List.Split
msgType = Map.fromList [("D", "NEW ORDER"), ("G", "MODIFY"), ("F", "CANCEL"), ("8", "EXECUTION"), ("9", "CANCEL"), ("i", "MASS QUOTE"), ("r", "QUOTE REQUEST"), ("b", "QUOTE ACK"), ("c", "SECURITY DEFINITION")]
ordStatus = Map.fromList [("0", "NEW ORDER ACK"), ("1", "PARTIAL FILL"), ("2", "COMPLETE FILL"), ("4", "CANCEL ACK"), ("5", "MODIFY ACK"), ("8", "ORDER REJECTED"), ("C", "EXPIRED"), ("H", "TRADE CANCEL")]
ordType = Map.fromList [("1", "MKT"), ("2", "LMT"), ("3", "STP"), ("4", "STP-LMT"), ("K", "MKT-LMT")]
@elvinio
elvinio / fix.vim
Last active August 29, 2015 14:23
" Fix syntax file
" Language: FIX
" Author: elvin.chua
" Created on: 16 June 2015
"
if exists("b:current_syntax")
finish
endif
let b:current_syntax = "fix"
@elvinio
elvinio / MIC
Last active April 18, 2016 16:46
MIC or Market Identifier Code from ISO10383 uniquely identifies exchanges and trading platforms. The list is from the MIC ISO page: http://www.iso15022.org/MIC/homepageMIC.htm
MIC,COUNTRY,ISO COUNTRY CODE (ISO 3166),OPERATING MIC,O/S,NAME-INSTITUTION DESCRIPTION,ACRONYM,CITY,STATUS DATE
360T,GERMANY,DE,360T,O,360T,,FRANKFURT,SEPTEMBER 2007
AATS,UNITED STATES OF AMERICA,US,AATS,O,ASSENT ATS,,JERSEY CITY,OCTOBER 2011
ACEX,INDIA,IN,ACEX,O,ACE DERIVATIVES & COMMODITY EXCHANGE LTD,,MUMBAI,APRIL 2011
AFET,THAILAND,TH,AFET,O,AGRICULTURAL FUTURES EXCHANGE OF THAILAND,,BANGKOK,JANUARY 2008
AIXE,SWITZERLAND,CH,AIXE,O,AIXECUTE,,BERNE,OCTOBER 2013
ALDP,UNITED STATES OF AMERICA,US,XNYS,S,NYSE ALTERNEXT DARK,AMEXDARK,NEW YORK,MAY 2011
ALTX,SOUTH AFRICA,ZA,XJSE,S,JSE ALTERNATE EXCHANGE,ALTX,JOHANNESBURG,APRIL 2015
ALXA,THE NETHERLANDS,NL,XAMS,S,EURONEXT - ALTERNEXT AMSTERDAM,,AMSTERDAM,MAY 2015
ALXB,BELGIUM,BE,XBRU,S,EURONEXT - ALTERNEXT BRUSSELS,,BRUSSELS,APRIL 2015
@elvinio
elvinio / stunnel.success.log
Last active August 29, 2015 14:25
Stunnel log of a successful SSL connection
2015.07.20 06:33:46 LOG6[2700:...]: Initializing service [prices]
2015.07.20 06:33:46 LOG7[2700:...]: Certificate: /home/test/test.pem
2015.07.20 06:33:46 LOG7[2700:...]: Certificate loaded
2015.07.20 06:33:46 LOG7[2700:...]: Key file: /home/test/test.pem
2015.07.20 06:33:46 LOG7[2700:...]: Private key loaded
2015.07.20 06:33:46 LOG7[2700:...]: SSL options set: 0x00000004
2015.07.20 06:33:46 LOG5[2700:...]: Configuration successful
2015.07.20 06:33:46 LOG7[2700:...]: Service [barx_trades] (FD=12) bound to 0.0.0.0:8444
2015.07.20 06:33:46 LOG7[2700:...]: Service [prices] (FD=13) bound to 0.0.0.0:8443
2015.07.20 06:33:46 LOG7[2706:...]: Created pid file /home/test/pid
@elvinio
elvinio / stunnel.conf
Last active August 29, 2015 14:25
Stunnel configuration
client = yes
cert = /home/test/test.pem
debug = 7
pid = /home/test/pid
output = /home/test/log
;output = /dev/stdout
fips = no
socket = r:TCP_NODELAY=1
socket = l:TCP_NODELAY=1
sslVersion = TLSv1.1
@elvinio
elvinio / openssl_convert
Created July 20, 2015 13:50
Convert certificate
# Convert .pfx, .p12 to .pem
openssl pkcs12 -in a.pfx -out a.pem -nodes
# Convert .p7b to .pem
openssl pkcs7 -inform der -in a.p7b -out a.pem
# Remove passphrase
openssl rsa -in a.pem -out b.pem
@elvinio
elvinio / tcp_connect.cpp
Last active August 29, 2015 14:25
Establishing a TCP connection
int connect(const std::string &host, const int port, const int timeout){
struct sockaddr_in sa = {0};
int socket;
// Create and populate the connect address structure
sa.sin_family = AF_INET;
// The htons() function converts the unsigned short integer hostshort
// from host byte order to network byte order
// On the i80x86 the host byte order is least significant byte first,
@elvinio
elvinio / tcp_listen.cpp
Created July 24, 2015 01:14
Code shows how to listen on a tcp socket in C++ and accept a connection
static struct sockaddr_in sa;
int listenCount = 0;
static const MAX_FD = 2048;
static struct pollfd listenFds[MAX_FD];
int main(int argc, char** argv){
int timeout = 15000;
listenPort(16000);
while(1){
@elvinio
elvinio / tcp_poll.cpp
Created July 24, 2015 01:17
C++: how to poll the TCP socket to read and write data.
void poller(int socketIn, std::string srcIP, int port){
struct pollfd fds[2];
// Initialize the fds to 0
memset(fds, 0, sizeof(fds));
// Wait in ms before poll times out. -1 for infinite
int timeout = 15000;
fds[0].fd = socketIn;