Skip to content

Instantly share code, notes, and snippets.

View moleike's full-sized avatar
🤘
dare to think for yourself

Alexandre Moreno moleike

🤘
dare to think for yourself
View GitHub Profile
@moleike
moleike / rethrow.cc
Last active August 29, 2015 14:16
Convert a C++ exception into a Java exception
void rethrow_cpp_exception_as_java_exception()
{
try
{
throw;
}
catch (const package::Exception& e)
{
jclass jc = env->FindClass("group/package/Exception");
if(jc) env->ThrowNew (jc, e.what());
@moleike
moleike / heap-lambda.cc
Last active August 29, 2015 14:22
Lambda in a C callback
#include <functional>
#include <iostream>
// using a lambda in a C callback
extern "C" void
register_callback (void (*callback)(void *), void * context)
{
// for simplicity we just call it
callback (context);
// credit to http://stackoverflow.com/a/14665230/339222
#include <functional>
#include <chrono>
#include <future>
#include <iostream>
class later
{
public:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import gtk
import webkit
def entry_activated_cb(entry, embed):
embed.load_uri(entry.get_text())
# Widgets and signals
@moleike
moleike / NavigationDrawer.qml
Last active August 29, 2015 14:27 — forked from jbache/NavigationDrawer.qml
Qt Quick Navigation Drawer
/*
Copyright (c) 2014 Cutehacks A/S
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
@moleike
moleike / server.js
Last active September 12, 2015 05:18 — forked from mixonic/server.js
Node.js + Socket.io + Bash. A collaborative terminal for your browser.
//
// This server will start a bash shell and expose it
// over socket.io to a browser. See ./term.html for the
// client side.
//
// You should probably:
//
// npm install socket.io
// curl -O https://github.com/LearnBoost/Socket.IO/raw/master/socket.io.min.js
//
@moleike
moleike / list.cc
Last active September 15, 2015 07:13
Linked list using polymorphic lambdas
// http://lists.boost.org/Archives/boost/2014/06/214213.php
// http://stackoverflow.com/questions/25338795/is-there-a-name-for-this-tuple-creation-idiom
#include <iostream>
#include <string>
#include <functional>
auto list = [](auto ...xs) {
return [=](auto access) { return access(xs...); };
};
@moleike
moleike / tags.cc
Created November 19, 2015 17:32
tag dispatching based on type traits
#include <iostream>
struct fast_speed_tag {};
struct slow_speed_tag {};
template <typename T>
struct traits { // default
typedef slow_speed_tag speed;
};
@moleike
moleike / restful.js
Created March 29, 2016 01:46 — forked from BinaryMuse/restful.js
Express API with Async/Await
import express from "express";
/**
* Takes a route handling function and returns a function
* that wraps it after first checking that the strings in
* `reserved` are not part of `req.body`. Used for ensuring
* create and update requests do not overwrite server-generated
* values.
*/
function checkReservedParams(routeHandler, ...reserved) {