This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <assert.h> | |
#include <msgpack.h> | |
typedef struct some_struct { | |
uint32_t a; | |
uint32_t b; | |
float c; | |
} some_struct; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"@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", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
<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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 -*- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. |