Skip to content

Instantly share code, notes, and snippets.

View ntakouris's full-sized avatar
🤖
Building robots

Theodoros Ntakouris ntakouris

🤖
Building robots
View GitHub Profile
#[macro_use] extern crate rocket;
use rocket::serde::json::Json;
use rocket::State;
#[post("/publish_event", format="application/json", data="<request>")]
pub fn publish_event(request: Json<EventEntity>, db: &State<Box<dyn DB>>) -> Result<(), String> {
let event = request.0;
/* map EventEntity -> DataResource */
pub trait DB: Send + Sync {
// fill out your own `Err` types
fn save(&self, resource: DataResource) -> Result<(), String>;
fn retrieve(&self, id: &String) -> Result<Option<DataResource>, String>;
}
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct CaptionedImagePayload {
pub caption: String,
pub blob_storage_ref_id: String
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum DataResourcePayload {
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug)]
pub struct CaptionedImageValue {
pub caption: String,
pub contents_b64: String
}
#[derive(Serialize, Deserialize, Debug)]
{
"id": "b",
"value": {
"caption": "<the caption>",
"contents_b64": "<base64 encoded image bytes>"
}
}
{
"id": "a",
"value": "<your value here>"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
class SelfAttentionBlock(keras.Model):
def __init__(self,head_size, num_heads=1, ff_dim=None, dropout=0, name='SelfAttentionBlock', **kwargs):
super().__init__(name=name, **kwargs)
if ff_dim is None:
ff_dim = head_size
self.attention = SelfAttention(head_size, num_heads, dropout=dropout)
self.attention_dropout = keras.layers.Dropout(dropout)
self.attention_norm = keras.layers.LayerNormalization(epsilon=1e-6)
import tensorflow.keras as keras
import tensorflow.keras.backend as K
class Time2Vec(keras.layers.Layer):
def __init__(self, kernel_size):
super().__init__(trainable=True, name='Time2Vec')
self.k = kernel_size
def build(self, input_shape):
@ntakouris
ntakouris / gpio_short_check.py
Created June 18, 2021 05:58
recorder.service (lepton thermal camera, raspberry pi)
import RPi.GPIO as GPIO
import time
def are_gpio_shorted(gpio_a = 26, gpio_b = 16, sleep_seconds=1, init_gpio=True, cleanup=True):
if init_gpio:
GPIO.setmode(GPIO.BCM)
GPIO.setup(gpio_a, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(gpio_b, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)