Skip to content

Instantly share code, notes, and snippets.

View fcracker79's full-sized avatar
🎯
Focusing

Mirko Bonasorte fcracker79

🎯
Focusing
View GitHub Profile
@fcracker79
fcracker79 / pymi_passages.py
Created December 10, 2017 10:10
Passages by day
import datetime
import random
import typing
import unittest
from collections import OrderedDict
class Passage:
def __init__(self, aos: datetime.datetime):
self.aos = aos
@fcracker79
fcracker79 / kafka-cheat-sheet.md
Created April 8, 2018 07:53 — forked from ursuad/kafka-cheat-sheet.md
Quick command reference for Apache Kafka

Kafka Topics

List existing topics

bin/kafka-topics.sh --zookeeper localhost:2181 --list

Describe a topic

bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic mytopic

Purge a topic

bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic mytopic --config retention.ms=1000

... wait a minute ...

import itertools
import typing
from pprint import pprint
def full_join(d1: typing.Optional[dict], d2: typing.Optional[dict]) -> typing.Optional[dict]:
if d1 is None or d2 is None:
return None
return {k: d1.get(k, d2.get(k)) for k in itertools.chain(d1, d2)}
import collections
_ApiMethod = collections.namedtuple('_ApiMethod', ['name', 'path', 'http_method', 'query_params'])
API = [
_ApiMethod('print_hello', 'api/hello', "GET", ['limit']),
]
import itertools
import pprint
import typing
_SELECTED = 5
_MAX_VALUE = 40
values = list(range(1, _MAX_VALUE + 1))
_REQUIRED_SUM = _MAX_VALUE // 2
import subprocess
class RunCmd(object):
def __init__(self, cmd):
self.cmd = cmd
def cmd_run(self):
subprocess.call(self.cmd, shell=True)
import itertools
def a_default_value():
return 1
def b_default_value():
return 'hello'
@fcracker79
fcracker79 / readloud.rs
Created June 29, 2019 10:59
RustHero Rustlab Florence 2019
use std::str;
struct ReadLoud<'a> {
current_element: Option<u32>,
numbers_iterator: str::Chars<'a>,
next_elements: Vec<u32>
}
impl <'a> ReadLoud<'a> {
struct NiceStructure<'a, T: Iterator<Item=&'a u32>> {
it: T
}
fn f<'a, T: Iterator<Item=&'a u32>>(it: &mut NiceStructure<'a, T>) {
// This does not work: cannot move out of borrowed content
// for x in it.it {
// println!("Element {:?}", x);
// }
// This works
use std::sync::Arc;
use std::thread;
use std::time::Duration;
fn main() {
let ref_counter = Arc::new(true);
for i in 0..10 {
let cur_ref_counter = Arc::clone(&ref_counter);
thread::spawn(move || {
thread::sleep(Duration::from_secs(i + 1));