Skip to content

Instantly share code, notes, and snippets.

@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": {},
from __future__ import ...
@qsorix
qsorix / duplicates.py
Created July 1, 2015 10:45
Duplicated json keys
#!/usr/bin/env python
import json
import sys
def list_duplicates(seq):
seen = set()
seen_add = seen.add
# adds all elements it doesn't know yet to seen and all other to seen_twice
-- here's the function used to actually drag & reorder tags
local function tag_drag(t)
local dr = mywibox[1]._drawable
mousegrabber.run(function (_mouse)
for k, v in ipairs(_mouse.buttons) do
if v then
local x = _mouse.x
local y = _mouse.y
@qsorix
qsorix / movable callback
Created March 18, 2014 21:41
Proof of concept. Callbacks that can be moved. This can be used to pass non-copyable resources between job queues of worker threads.
#include <memory>
#include <iostream>
#include <type_traits>
#include <tuple>
#include <vector>
/*
* seq<> and gen<> are used to call function with arguments saved as a tuple
*/
template<int...>
#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 / 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 / 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 / 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)