Skip to content

Instantly share code, notes, and snippets.

View mbasaglia's full-sized avatar

Mattia Basaglia mbasaglia

View GitHub Profile
@mbasaglia
mbasaglia / copy-maps.sh
Last active March 7, 2021 23:54
Simple script to copy maps from a file
#!/bin/bash
INPUT_DIR=~/.xonotic/data
OUTPUT_DIR=$(pwd)
# @brief Prints a list of files in a pk3
# @param $1 pk3 name
function pk3_files()
@mbasaglia
mbasaglia / rcon.sh
Created June 5, 2014 21:04
A shell script which executes rcon commands
#!/bin/bash
SERVER='localhost'
PORT='26000'
PASSWORD='foo'
SECURE=0
SECURE_PORT="1234"
RCON_HEADER=$(echo -e "\xff\xff\xff\xff")
ESCAPE_CHAR=$(echo -en "\x1b")
@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)