Skip to content

Instantly share code, notes, and snippets.

View mbasaglia's full-sized avatar

Mattia Basaglia mbasaglia

View GitHub Profile
@mbasaglia
mbasaglia / kdevelop_initfile_scripts.js
Last active January 3, 2017 09:27
Kdevelop C++ file setup snippet
function find_components(header)
{
var url = document.url();
var components = url.split("/");
var end = header ? components.length : components.length-1;
components = components.slice(3, end);
var cut = -1;
for ( cut = components.length-1; cut >= 0; cut-- )
if ( components[cut] == "src" || components[cut] == "include" )
#!/usr/bin/env python
import sys
from argparse import ArgumentParser
from PIL import Image
import svgwrite
def pix2char(image, x, y, palette):
try:
l, a = image.getpixel((x, y))
#!/bin/bash
echo "This script will determine the future of all humanity"
read -n 1 -s -r -p $'Press \x1b[1mANY\x1b[m key to continue\n'
read -n 1 -s -r -p $'Do you want humanity to survive? [Y|n]\n' hooman
if [ "$hooman" = "n" ]
then
read -n 1 -s -r -p $'You are about to kill all humans, confirm? [y|N]\n' confirm
if [ "$confirm" = "y" ]
then
@mbasaglia
mbasaglia / turing.py
Last active August 11, 2017 14:24
Turing machine implementation in Python, with a couple examples
#!/usr/bin/env python
class Tape(object):
def __init__(self, data="", blank=None):
self.tape = dict(enumerate(data))
self.pos = 0
self.blank = blank
def move_right(self):
#!/usr/bin/env python
import sys
import math
word = sys.argv[1] if len(sys.argv) > 1 else "loss"
rlen = 3 + len(word)
spacing = " " * int(math.floor(rlen / 3))
for letter in word:
@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 / test_rendering_instructions.py
Last active February 11, 2024 21:18
Testing shape instructions for lottie-spec
# pip install lottie cairosvg
import io
import re
import sys
import enum
import math
import json
import lottie
import pathlib
import argparse
@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")