Skip to content

Instantly share code, notes, and snippets.

@qsorix
qsorix / udp_socket_addr.cc
Created November 13, 2012 16:01
Getting original destination address on a UDP socket
#include <sys/socket.h>
#include <netinet/in.h>
#include <iostream>
#include <string.h>
int main()
{
// --------------------------------------------
struct sockaddr_in addr;
@qsorix
qsorix / Jumpy.hs
Created March 9, 2012 21:17
Bouncing ball - Functional Reactive Programming in Haskell using Fal.
module Main where
import Text.Printf
{- Module Fal is from the book "The Haskell School of Expression" by Paul Hudak.
- You need to read it, or google for the code -}
import Fal
count :: Event a -> Behavior Int
count ev = 0 `stepAccum` ev ->> (+1)
@qsorix
qsorix / indexed_contact.json
Created February 25, 2016 09:48
SQ on sandbox
{
"_id": "4172840",
"_index": "contacts_v1",
"_routing": "60635",
"_source": {
"account_id": 60635,
"actionable_per_type": [],
"billing_address": null,
"billing_address_city_suggest": {},
"billing_address_country_suggest": {},
#include "foo.pb.h"
#include <iostream>
/* protocol:
message Foo
{
message Pair
{
required string key = 1;
required string value = 2;
@qsorix
qsorix / almost-erlang.cc
Created February 1, 2013 21:31
Playing with C++11 lambdas to get erlang-like receive statement.
#include <iostream>
#include <vector>
#include <functional>
enum message_type {PING, PONG};
struct Message {
message_type m_type;
Message(message_type t) : m_type(t) {}
message_type type() const { return m_type; }
@qsorix
qsorix / events.hs
Created July 26, 2012 21:11
DSL for event pattern detection
-- Construct 1
-- ===========
-- ev1 >- time -< [ ev2
-- , Null
-- ]
-- Means that if ev1 happens then ev2 may happen within time and then [ev2, ev1]
-- is reported. If ev2 does not happen within time, don't wait longer and report
-- [ev1, Null] == [ev1].
--
-- Note: ev1 will always be reported.
@qsorix
qsorix / hanoi-4.hs
Created February 18, 2012 22:13
Tower of Hanoi in Haskell, part 4
import Control.Monad.State
import Data.Lens.Common
type Disc = Int
type Tower = [Disc]
data Towers = Towers
{ towerA_ :: Tower
, towerB_ :: Tower
, towerC_ :: Tower
} deriving (Show)
@qsorix
qsorix / hanoi-3.hs
Created February 18, 2012 21:38
Tower of Hanoi in Haskell, part 3
import Control.Monad.State
type Disc = Int
type Tower = [Disc]
data Towers = Towers
{ towerA :: Tower
, towerB :: Tower
, towerC :: Tower
} deriving (Show)
@qsorix
qsorix / hanoi-2.hs
Created February 13, 2012 18:20
Towers of Hanoi in Haskell, part II
import Control.Monad.State
type Disc = Int
type Tower = [Disc]
data Towers = Towers
{ towerA :: Tower
, towerB :: Tower
, towerC :: Tower
} deriving (Show)
@qsorix
qsorix / hanoi-1.hs
Created February 9, 2012 22:12
Towers of Hanoi in Haskell, part I
type Disc = Int
type Tower = [Disc]
data Towers = Towers
{ towerA :: Tower
, towerB :: Tower
, towerC :: Tower
} deriving (Show)
data TowerName = A | B | C
deriving (Show)