Skip to content

Instantly share code, notes, and snippets.

View Mec-iS's full-sized avatar

Lorenzo Mec-iS

View GitHub Profile
@Mec-iS
Mec-iS / ubuntu-avahi-cleanup.md
Created February 5, 2019 13:04
Cleanup Ubuntu netwoking

So:

  1. sudo apt-get --purge remove avahi-autoipd avahi-daemon avahi-utils (this is causing A LOT of issues, and it is not needed for Linux networking).
  2. Open file /etc/systemd/resolved.conf
  3. Edit like this:
[Resolve]
DNS=172.16.21.2
#FallbackDNS=
Domains=local
@Mec-iS
Mec-iS / struct.py
Created November 19, 2018 11:50
Python: A generic structure to be used to access dictionaries
"""As in https://stackoverflow.com/a/1305663"""
class Struct:
def __init__(self, **entries):
self.__dict__.update(entries)
def __repr__(self):
return '<%s>' % str('\n '.join('%s : %s' % (k, repr(v)) for (k, v) in self.__dict__.iteritems()))
def __str__(self):
@Mec-iS
Mec-iS / msgpack.c
Created September 14, 2017 15:05 — forked from deltheil/msgpack.c
Pack / unpack some structs with C msgpack - see http://stackoverflow.com/a/15405794/1688185
#include <stdio.h>
#include <assert.h>
#include <msgpack.h>
typedef struct some_struct {
uint32_t a;
uint32_t b;
float c;
} some_struct;
@Mec-iS
Mec-iS / apidoc-example.json
Created September 6, 2017 10:36
A HYDRA ApiDocumentation vocabulary
{
"@context": {
"vocab": "http://www.markus-lanthaler.com/hydra/event-api/vocab#",
"hydra": "http://www.w3.org/ns/hydra/core#",
"ApiDocumentation": "hydra:ApiDocumentation",
"property": {
"@id": "hydra:property",
"@type": "@id"
},
"readonly": "hydra:readonly",
# pseudo-code
last_status = time()
while True:
current = time()
if current - last_status == 15 secs:
update_drone_status()
last_status = current
sleep(14.5 secs)
"""
<http://www.snarky.ca/how-the-heck-does-async-await-work-in-python-3-5>
"""
import datetime
import heapq
import types
import time
class Task:
"""A default task that makes a coroutine to wait.
# Install BigchainDB on a VM with Vagrant
It's quite easy to provision and run a Vagrant VM:
* Install Vagrant in your host system following instructions [here](https://www.vagrantup.com/docs/installation/)
* In your VM-to-be's home directory create the `VagrantFile` and the bash script to provision the machine (`config.sh`)
**VagrantFile**
```
# -*- mode: ruby -*-
# python3.5
p = {3: 'Crackle', 5: 'Pop'}
for i in range(1, 101):
try:
lst = [p.get(k) for k in p.keys() if i % k == 0]
el, length = lst[0], len(lst)
print({1: el, 2: 'CracklePop'}.get(length))
except IndexError:
print(i)
# coding=utf-8
__author__ = 'Lorenzo'
from secret import _KEY
def post_curling(url, params, file=None, display=False):
"""
POST to a remote url and print the response in a file or on screen or return the body of the response
:param url: target url
:param params: parameters in the request
@Mec-iS
Mec-iS / liarsdiceagent.py
Last active November 13, 2015 10:20
An agent to play Liar's Dice game, based on an API that serve information about a game been played by four players
"""
Experiment for an automated agent playing Liar's Dice.
It's a partial implementation, some possible moves are not yet implemented.
Work time spent: 9 hours, considering also the time taken to learn basic rules
of the game.
It won multiple games beating computer opponents with an average score of 27,
where the average score for computer winners were 25.
Version 0.1