Skip to content

Instantly share code, notes, and snippets.

View Mec-iS's full-sized avatar

Lorenzo Mec-iS

View GitHub Profile
# 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)
# 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 -*-
"""
<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.
# 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)
@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",
@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 / 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 / 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 / labeled_loop.rs
Created April 11, 2019 13:13
[RUST] labeling nested loops
/// Taken from "Programming Rust" by Jim Blandy and Jason Orendorff
// A loop can be labeled with a lifetime. In the following example, 'search: is a label for
// the outer for loop. Thus break 'search exits that loop, not the inner loop.
'search:
for room in apartment {
for spot in room.hiding_spots() {
if spot.contains(keys) {
println!("Your keys are {} in the {}.", spot, room);
@Mec-iS
Mec-iS / divergent_functions.rs
Last active April 11, 2019 13:25
[RUST] Functions that are exception to uniformity of return type (forever loops, break, exits ...)
/// Taken from "Programming Rust" by Jim Blandy and Jason Orendorff
// Expressions that don’t finish normally are assigned the special type ! ,
// and they’re exempt from the rules about types having to match.
// You can see ! in the function signature of `std::process::exit()`:
fn exit(code: i32) -> !
// The ! means that exit() never returns. It’s a divergent function.
// You can write divergent functions of your own using the same syntax,
// and this is perfectly natural in some cases: