Skip to content

Instantly share code, notes, and snippets.

@studiofuga
studiofuga / QStreamEnum.h
Created February 24, 2023 11:29
Allow using Enum Classes with QDataStream and stream operators
//
// Created by Federico Fuga <fuga@studiofuga.com> on 15/02/23.
//
// Allow using Enum Classes with QDataStream and stream operators
#ifndef QSTREAMENUM_H
#define QSTREAMENUM_H
#include <QDataStream>
@studiofuga
studiofuga / main.h
Created September 5, 2018 18:23
Open std Console (cout/cerr) on Qt GUI Application
#include <QApplication>
#ifdef _WIN32
#include <Windows.h>
#endif
int main(int argc, char *argv[])
{
#ifdef _WIN32
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
@studiofuga
studiofuga / streamtuple.h
Created February 13, 2016 11:34
Pretty print a std::tuple to a stream
#ifndef STREAMTUPLE_H
#define STREAMTUPLE_H
#include <iostream>
#include <tuple>
namespace aux{
template<std::size_t...> struct seq{};
template<std::size_t N, std::size_t... Is>
@studiofuga
studiofuga / parsekv.h
Last active February 13, 2016 11:37
Parse Key/Value pairs with boost::regex
#ifndef PARSEKV_H
#define PARSEKV_H
#include <tuple>
#include <string>
#include <boost/regex.hpp>
// link against boost_regex (-lboost_regex)
std::tuple<std::string,std::string> parseKeyValue(std::string arg)
@studiofuga
studiofuga / MainWindow.cpp
Created February 2, 2016 10:42
Qt MainWindow state and position save/restore
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// ...
QSettings settings;
restoreGeometry(settings.value("geometry").toByteArray());
@studiofuga
studiofuga / gist:5262efb95968b02a365d
Created October 14, 2015 20:43
Bluez5 recipes with dbus-send
* Making an adapter discoverable (check that rfkill is enabled, otherwise /org/bluez/hci0 will not be available)
dbus-send --system --dest=org.bluez --print-reply /org/bluez/hci0 \
org.freedesktop.DBus.Properties.Set \
string:org.bluez.Adapter1 string:Discoverable variant:boolean:true
* Changing the discoverable timeout. Default is 180s.
dbus-send --system --dest=org.bluez --print-reply /org/bluez/hci0 \
org.freedesktop.DBus.Properties.Set \
@studiofuga
studiofuga / demangle.cpp
Last active September 23, 2015 16:09
C++ class demangling (g++ ABI)
#include <cxxabi.h>
int main()
{
MyClass *m = new SomeClass();
char *demangled = abi::__cxa_demangle(typeid(*m).name(), 0, 0, 0);
std::cout << demangled << std::endl;
free(demangled);
}
@studiofuga
studiofuga / bluezutils.py
Last active March 25, 2021 07:24
Bluetooth agent that performs pairing with a fixed pin ("0000").
import dbus
SERVICE_NAME = "org.bluez"
ADAPTER_INTERFACE = SERVICE_NAME + ".Adapter1"
DEVICE_INTERFACE = SERVICE_NAME + ".Device1"
def get_managed_objects():
bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object("org.bluez", "/"),
"org.freedesktop.DBus.ObjectManager")
@studiofuga
studiofuga / FormatDateAndTime.java
Created July 22, 2015 21:41
Forma Date and Time in Android
Date mDate = new Date();
String s = DateUtils.formatDateTime(this, mDate.getTime(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME);
@studiofuga
studiofuga / ShowDate.java
Last active August 29, 2015 14:25
DateTimePicker Dialog
private void shodDateDialog() {
final View dialogView = View.inflate(this, R.layout.date_time_picker, null);
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
/* This will set up the default values */
Calendar calendar = Calendar.getInstance();
calendar.setTime(mDate);
DatePicker datePicker = (DatePicker) dialogView.findViewById(R.id.date_picker);
TimePicker timePicker = (TimePicker) dialogView.findViewById(R.id.time_picker);