Skip to content

Instantly share code, notes, and snippets.

View mbasaglia's full-sized avatar

Mattia Basaglia mbasaglia

View GitHub Profile
@mbasaglia
mbasaglia / class_properties.cpp
Last active August 29, 2015 14:04
C++ Class Properties Hack
#include <iostream>
#include <map>
#include <functional>
#include <sstream>
namespace misc {
/**
* \brief Abstract class for classes that have some way to access properties
*
@mbasaglia
mbasaglia / xonchat.php
Last active August 29, 2015 14:06
PHP script for colorful Xonotic Chat
<?php
/**
* \file
* \brief Simple web script to get colorful text in Xonotic
* \par Basic Usage
* \code menu_cmd qc_curl --exec http://localhost/this_script.php cmd echo c1 000 c2 fff text "Hello world" \endcode
* \par Example with aliases
\code
set mb_net_chat_server "http://localhost/xonchat/index.php"
alias mb_net_chat "menu_cmd qc_curl --exec $mb_net_chat_server cmd \"$1\" c1 $2 c2 $3 text \"$mb_net_str\""
@mbasaglia
mbasaglia / read_config.sh
Last active August 29, 2015 14:07
shell script to read some config-looking data
#!/bin/bash
function read_config()
{
if [ -z "$2" ]
then
read -r -d '' $1
else
local input=""
for inp in "${@:2}"
@mbasaglia
mbasaglia / dyn_func_call.cpp
Created July 6, 2015 09:16
An example of conversions of run-time value to compile-time objects used in function calls
/**
* \file
* \brief An example of conversions of run-time value to compile-time objects used in function calls
*/
#include <iostream>
#include <vector>
#include <stdexcept>
#include <type_traits>
@mbasaglia
mbasaglia / property_tree.hpp
Created September 14, 2015 12:13
Property Tree for Qt
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2015 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@mbasaglia
mbasaglia / open-delete.sh
Last active November 22, 2015 17:05
Open and delete random file
#!/usr/bin/env bash
DIRECTORY="$PWD"
[ "$1" ] && DIRECTORY="$1"
selected="$(ls "$DIRECTORY" | sort -R | head -n 1)"
[ "$selected" ] || exit 1
xdg-open "$selected" && rm "$selected"
@mbasaglia
mbasaglia / random_pony.py
Created August 14, 2016 22:19
Selects a random pony name from the mlp wiki.
import urllib
import json
import random
class PonyList(object):
api_url = "http://mlp.wikia.com/api.php"
query_common = {
"action": "query",
"list": "categorymembers",
"format": "json",
#include <cmath>
#include <limits>
#include <iostream>
#include "melanolib/math/math.hpp"
using namespace melanolib;
template<class Float>
std::string float_to_string(Float value)
@mbasaglia
mbasaglia / pony_stream.htm
Created September 10, 2016 16:22
Simple webpage to view some mlp streams with the html5 player
<!DOCTYPE html>
<html>
<head>
<title>Pony!</title>
</head>
<body>
<h1>Pony! <span id="next_pony"></span></h1>
<iframe
id="stream"
width="1024"
<!DOCTYPE html>
<html>
<head>
<title>,</title>
</head>
<body>
<style>
.wrapper
{