Skip to content

Instantly share code, notes, and snippets.

View nebelgrau77's full-sized avatar
👾

Michal Lasak nebelgrau77

👾
View GitHub Profile
# this won't work, either:
# in flask_app:
from counter import counter_update, counter_display
@app.route('/counter/')
def counter():
@nebelgrau77
nebelgrau77 / gist:33f080d7302b8ff0cef4db21468487d3
Last active April 10, 2020 21:03
magic 8-ball - getting the random values
As the code is intended for an STM32F0xx board, which requires the peripherals to be defined within the CS,
the idea was to have them globally accessible, wrapped in Mutex - RefCell containers.
This does not work for the Random Number Generator. Code:
static GRNG: Mutex<RefCell<Option<rand::rngs::small::SmallRng>>> = Mutex::new(RefCell::new(None));
gives an error "module 'small' is private".
Ideas go go around this and solve the whole problem: three separate timer interrups.
@nebelgrau77
nebelgrau77 / UART_driver_problematic.md
Last active May 9, 2020 14:01
UART driver that bricked the boards while trying to debug with CubeIDE

main.c

#include "uart.h"

int main(void)
{
	USART2_Init();
	test_setup();
@nebelgrau77
nebelgrau77 / inventory.md
Last active May 24, 2020 16:31
Rust - struct with a str field - lifetime problem.
use std::io;
#[derive(Copy, Clone, Debug)]
struct Record<'a> {
    id: u16,
    name: &'a str,
    quantity: u16,
    price: f32,
}
#![no_main]
#![no_std]

extern crate panic_halt;

use cortex_m_rt::entry;
use stm32l0::stm32l0x1;
use stm32l0xx_hal::{
    pac,
@nebelgrau77
nebelgrau77 / cursive_select.md
Last active July 3, 2020 09:05
simple text-based user interface - FIXED

A simple app to choose a random episode of a TV show :)

extern crate cursive;

use cursive::views::{SelectView, TextView, Dialog};
use cursive::align::*;
use cursive::Cursive;
use cursive::traits::*;
@nebelgrau77
nebelgrau77 / sorenson-dice.md
Last active July 8, 2020 09:51
the Sørenson–Dice coefficient
@nebelgrau77
nebelgrau77 / bubble_sort.md
Last active July 18, 2020 15:24
bubble sort algorithm
def add(*args):
    
    if len(set([tuple([len(item) for item in arg]) for arg in args])) == 1:
    
        return [[sum(b) for *b, in zip(*item,)] for item in [b for *b, in zip(*args,)]]
        
    else:
 
use arduino_nano33iot as hal;

use hal::clock::GenericClockController;
use hal::prelude::*;
use rtic::app;
use core::fmt::Write;
use hal::adc::Adc;

#[app(device = crate::hal::pac, peripherals = true)]