Skip to content

Instantly share code, notes, and snippets.

View mbasaglia's full-sized avatar

Mattia Basaglia mbasaglia

View GitHub Profile
@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
#!/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 / 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):
#!/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
#!/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))
@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" )
<!DOCTYPE html>
<html>
<head>
<title>,</title>
</head>
<body>
<style>
.wrapper
{
@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"
#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 / 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",