This file contains hidden or 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
#[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 */ |
This file contains hidden or 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
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>; | |
} |
This file contains hidden or 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
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 { |
This file contains hidden or 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
use serde::{Serialize, Deserialize}; | |
#[derive(Serialize, Deserialize, Debug)] | |
pub struct CaptionedImageValue { | |
pub caption: String, | |
pub contents_b64: String | |
} | |
#[derive(Serialize, Deserialize, Debug)] |
This file contains hidden or 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
{ | |
"id": "b", | |
"value": { | |
"caption": "<the caption>", | |
"contents_b64": "<base64 encoded image bytes>" | |
} | |
} |
This file contains hidden or 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
{ | |
"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.
This file contains hidden or 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
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) |
This file contains hidden or 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
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): |
This file contains hidden or 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
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) |