Skip to content

Instantly share code, notes, and snippets.

@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...>
-- 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 / 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
from __future__ import ...
import SocketServer
SocketServer.TCPServer.allow_reuse_address = True
class PingHandler(SocketServer.StreamRequestHandler):
"""
Simple ping service.
Dziedziczysz po StreamRequestHandler i potem mozesz robic
self.rfile.readline().
def singleton(cls):
instances = {}
def getinstance():
if cls not in instances:
instances[cls] = cls()
return instances[cls]
return getinstance
@singleton
class MyClass:
TODO: reprezentacja krawędzi w model i network musi umożliwiać jednoznaczne
mapowanie portów. Jak nazwać krawędzie? Czy wprowadzić porty już w
konfiguracji model?
TODO: a jak w model przedstawić port, w sytuacji, kiedy trzeba na nim założyć
jakąś konfigurację (np. packet-loss).
#v+
model Foo
{
def read(self, model, network, mapping, schedule):
# local variables for each configuration file
ctx_model = {}
ctx_network = {}
ctx_mapping = {}
ctx_schedule = {}
# resources can be defined in any configuration part
glob_resources = Resources.public_functions
def setup_glob(module):
#include <iostream>
#include <string>
template <typename T, typename T_Infix>
struct InfixProxy {
T const & lhs_;
T_Infix const & oper_;
InfixProxy(T const & lhs, T_Infix const & oper)
: lhs_(lhs), oper_(oper)
#include <iostream>
namespace ns1 {
template <typename T, typename U>
int operator+(const T&, const U&)
{
std::cout << "ns1::operator+" << std::endl;
return 1;
}