Skip to content

Instantly share code, notes, and snippets.

View khasanov's full-sized avatar

Sergey Khasanov khasanov

  • Novosibirsk, Russia
View GitHub Profile
@khasanov
khasanov / gist:44ce3d5d4f1be06d1c6e65b0e7804417
Created August 18, 2017 06:03
Convert function from node style callback to promise
// https://stackoverflow.com/questions/22519784/how-do-i-convert-an-existing-callback-api-to-promises
// Convert from node style callback
function getStuff(dat,callback){
gettStuff("dataParam",function(err,data){
//
});
};
// To promise
function getStuffAsync(param) {
@khasanov
khasanov / gist:0b31e8c0c041e89c88fbb1ad1614b8d7
Created November 29, 2016 02:17
QtDD13_signals_slots_qt5_OliverGoffart
Is there a way to avoid typing the type of the object?
connect(QSIGNAL(button, clicked), QSLOT(receiver, buttonClicked));
// C++11 Only
#define QSIGNAL(OBJ, FUNC) OBJ, [&](){ \
typedef std::remove_reference<decltype(*(OBJ))>::type Type; \
return &Type::FUNC; }()
@khasanov
khasanov / gist:4363fa5a6a97da4bda2a
Created January 8, 2016 12:24
Disassembly windows executable on linux
$ objdump -D -b binary -m i8086 <file>
/**
#include <cstdio>
int main() {
int a[4];
a[0] = 3;
a[1] = 2;
a[2] = 1;
a[3] = 0;
class A { public: A(int _a, int _b) : a(_a), b(_b){} int a; int b; };
QList<A*> tstItems;
tstItems.append(new A(1,2));
tstItems.append(new A(3,4));
tstItems.append(new A(5,6));
QList<A*>::iterator tstIt = std::find_if(tstItems.begin(), tstItems.end(), [] (const A *const a) {
qDebug() << "inside lambda " << a;
return a->b == 4;
@khasanov
khasanov / horror.cpp
Created July 14, 2014 10:57
GOTO label inside class method, do not use in production!!!
// GOTO label inside class method, do not use in production!!!
// g++ -Wno-pmf-conversions horror.cpp
#ifndef HORROR_H
#define HORROR_H
#include <iostream>
#include <cstdlib>
struct Foo {