Skip to content

Instantly share code, notes, and snippets.

Avatar

Mattia Basaglia mbasaglia

View GitHub Profile
View loss.py
#!/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 Aug 11, 2017
Turing machine implementation in Python, with a couple examples
View turing.py
#!/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):
View anykey.sh
#!/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
View pix2text.py
#!/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 Jan 3, 2017
Kdevelop C++ file setup snippet
View kdevelop_initfile_scripts.js
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" )
View annoy.html
<!DOCTYPE html>
<html>
<head>
<title>,</title>
</head>
<body>
<style>
.wrapper
{
@mbasaglia
mbasaglia / pony_stream.htm
Created Sep 10, 2016
Simple webpage to view some mlp streams with the html5 player
View pony_stream.htm
<!DOCTYPE html>
<html>
<head>
<title>Pony!</title>
</head>
<body>
<h1>Pony! <span id="next_pony"></span></h1>
<iframe
id="stream"
width="1024"
View float_to_string.cpp
#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 Aug 14, 2016
Selects a random pony name from the mlp wiki.
View random_pony.py
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",
@mbasaglia
mbasaglia / open-delete.sh
Last active Nov 22, 2015
Open and delete random file
View open-delete.sh
#!/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"