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
const machine = Machine({ | |
id: 'sensor', | |
initial: 'inactive', | |
states: { | |
inactive: { | |
on: { | |
HW_HIGH: 'active' | |
} | |
}, | |
active: { |
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
const level_active_high = { | |
initial: 'inactive', | |
states: { | |
inactive: { | |
on: { | |
HW_HIGH: 'active' | |
} | |
}, | |
active: { |
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
const initialState = 'inactive'; | |
const toggleMachine = Machine({ | |
id: 'toggle', | |
initial: initialState, | |
states: { | |
inactive: { // 'inactive' state | |
on: { // "on event, transition to state..." | |
TOGGLE: 'active' // on event 'TOGGLE', transition to 'active' | |
} |
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
const initialState = 'inactive'; | |
const toggleMachine = Machine({ | |
id: 'toggle', | |
initial: initialState, | |
states: { | |
inactive: { // 'inactive' state | |
on: { // "on event, transition to state..." | |
TOGGLE: 'active' // on event 'TOGGLE', transition to 'active' | |
} |
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
// Uncomment /* */ blocks within functions to see compiler errors. | |
/* | |
Links to documentation | |
str, the string primitive: | |
https://doc.rust-lang.org/std/primitive.str.html | |
str, trait implementations: | |
https://doc.rust-lang.org/std/primitive.str.html#implementations |
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
# Docs: | |
# https://docs.python.org/3/library/functools.html#functools.reduce | |
import functools | |
# reduce(function, iterable) | |
# Applies function to each item of the sequence, left to right. | |
# Passes two arguments to the function: | |
# the current total | |
# the next item in the sequence |
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
// Example of non-lexical lifetimes for references in Rust | |
// | |
// References go out of scope at their last use, | |
// not at the end of a block. | |
fn main() { | |
example1(); | |
example2(); | |
example3(); | |
} |
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
# Get the exercise name from the current directory | |
get_filename_component(exercise ${CMAKE_CURRENT_SOURCE_DIR} NAME) | |
# Basic CMake project | |
cmake_minimum_required(VERSION 3.1.3) | |
# Name the project after the exercise | |
project(${exercise} CXX) | |
# Locate Boost libraries: unit_test_framework, date_time and regex |
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
// Bird's-eye view of overall production code | |
Cmac_Calculate() | |
{ | |
aes_handle = Aes128_Create(key, iv) | |
// Perform several technical operations (CmacOps) per the CMAC spec. | |
CmacOps_GenerateSubkeys(aes_handle, *subkey1, *subkey2) | |
//... | |
CmacOps_ApplyCbcMac(aes_handle, <relevant_parameters>) | |
//... |
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
// From production code | |
typedef struct AES_STRUCT * AES_HANDLE; | |
typedef struct | |
{ | |
char *key; | |
size_t key_len; | |
char *iv; | |
size_t iv_len | |
} CREATE_PARAMS; |
NewerOlder