Category: Blog

  • intersight-server-power-control

    Automated Server Power Control for Cisco Intersight


    Deployment Tools Title Image


    The Automated Server Power Control Tool for Cisco Intersight automates the power state of multiple UCS servers managed by Intersight. Quickly perform “Power On”, “Power Off”, “Power Cycle”, “Hard Reset”, “Shutdown”, and “Reboot CIMC” operations on large groups of servers.


    Prerequisites

    1. Python 3.7 or higher installed, which can be downloaded from https://www.python.org/downloads/.

      • If you’re installing for the first time on Windows, select the option “Add Python 3.x to PATH” during the installation.
    2. Install the Cisco Intersight SDK for Python by running the following command:

      pip install intersight
      

      More information on the Cisco Intersight SDK for Python can be found at https://github.com/ciscodevnet/intersight-python.

    3. [Optional] If you already have the Cisco Intersight SDK for Python installed, you may need to upgrade. An upgrade can be performed by running the following command:

      pip install intersight --upgrade --user
      
    4. Clone or download the Automated Server Power Control for Cisco Intersight repository by using the GitHub Code Button link on the main repository web page or by running the following command from the target directory if Git is locally installed:

      git clone https://github.com/ugo-emekauwa/intersight-server-power-control
      

      If you are downloading the repository file as a zipped file, unzip the file once the download has completed.

    5. Generate a version 3 or version 2 API key from your Intersight account.

      (a). Log into your Intersight account, click the Service Selector and select System.

      Figure 1 - Go to Settings

      (b). Under the API section in the work pane, click API Keys.

      Figure 2 - Go to API Keys

      (c). In the API Keys section in the work pane, click the Generate API Key button.

      Figure 3 - Click the Generate API Key button

      (d). In the Generate API Key window, enter a description or name for your API key.

      Figure 4 - Enter an API key description

      (e). In the Generate API Key window, under API Key Purpose, select a version 3 or version 2 API key.

      Figure 5 - Verify version 2 API key selection

      (f). In the Generate API Key window, click the Generate button.

      Figure 6 - Click the Generate button

      (g). In the Generate API Key window, a new API key will be generated. Copy the API Key ID and download the Secret Key to a secure location.

      Figure 7 - Copy and save the API key data

    How to Use

    1. Please ensure that the above Prerequisites have been met.

    2. Within the unzipped Automated Server Power Control for Cisco Intersight repository, navigate to the intersight_server_power_control.py file.

    3. Edit the intersight_server_power_control.py file to set the key_id variable using the following instructions:

      (a). Open the intersight_server_power_control.py file in an IDLE or text editor of choice.

      (b). Find the comment # MODULE REQUIREMENT 1 #.

      Figure 9 - MODULE REQUIREMENT 1 location

      (c). Underneath, you will find the variable key_id. The variable is currently empty.

      Figure 10 - key_id variable location

      (d). Fill in between the quotes of the key_id variable value with the ID of your API key. For example:

      key_id = "5c89885075646127773ec143/5c82fc477577712d3088eb2f/5c8987b17577712d302eaaff"
    4. Edit the intersight_server_power_control.py file to set the key variable using the following instructions:

      (a). Open the intersight_server_power_control.py file in an IDLE or text editor of choice.

      (b). Find the comment # MODULE REQUIREMENT 2 #.

      Figure 11 - MODULE REQUIREMENT 2 location

      (c). Underneath, you will find the variable key. The variable is currently empty.

      Figure 12 - key variable location

      (d). Fill in between the quotes of the key variable value with your system’s file path to the SecretKey.txt file for your API key. For example:

      key = "C:\\Keys\\Key1\\SecretKey.txt"
    5. Edit the intersight_server_power_control.py file to set all the configuration variable values using the following instructions:

      (a). Open the intersight_server_power_control.py file in an IDLE or text editor of choice.

      (b). Find the comment # MODULE REQUIREMENT 3 #.

      Figure 13 - MODULE REQUIREMENT 3 location

      (c). Underneath, you will find the instructions to edit the configuration variable values to match your environment. Each variable has a sample value for ease of use. The variable values to edit begin under the comment ####### Start Configuration Settings - Provide values for the variables listed below. #######.

      Figure 14 - Start Configuration Settings location

      Completion of editing the configuration variable values is marked by the comment ####### Finish Configuration Settings - The required value entries are complete. #######.

      Figure 15 - Finish Configuration Settings location

    6. Save the changes you have made to the intersight_server_power_control.py file.

    7. Run the intersight_server_power_control.py file.

    Demonstrations and Learning Labs

    The Automated Server Power Control Tool for Cisco Intersight is used in the following demonstrations and labs on Cisco dCloud:

    Cisco UCS X-Series Lab Topology

    dCloud is available at https://dcloud.cisco.com, where Cisco product demonstrations and labs can be found in the Catalog.

    Related Tools

    Here are similar tools to help administer and manage Cisco UCS and Intersight environments.

    Author

    Ugo Emekauwa

    Contact Information

    uemekauw@cisco.com or uemekauwa@gmail.com

    Visit original content creator repository https://github.com/ugo-emekauwa/intersight-server-power-control
  • intersight-server-power-control

    Automated Server Power Control for Cisco Intersight


    Deployment Tools Title Image


    The Automated Server Power Control Tool for Cisco Intersight automates the power state of multiple UCS servers managed by Intersight. Quickly perform “Power On”, “Power Off”, “Power Cycle”, “Hard Reset”, “Shutdown”, and “Reboot CIMC” operations on large groups of servers.


    Prerequisites

    1. Python 3.7 or higher installed, which can be downloaded from https://www.python.org/downloads/.

      • If you’re installing for the first time on Windows, select the option “Add Python 3.x to PATH” during the installation.
    2. Install the Cisco Intersight SDK for Python by running the following command:

      pip install intersight
      

      More information on the Cisco Intersight SDK for Python can be found at https://github.com/ciscodevnet/intersight-python.

    3. [Optional] If you already have the Cisco Intersight SDK for Python installed, you may need to upgrade. An upgrade can be performed by running the following command:

      pip install intersight --upgrade --user
      
    4. Clone or download the Automated Server Power Control for Cisco Intersight repository by using the GitHub Code Button link on the main repository web page or by running the following command from the target directory if Git is locally installed:

      git clone https://github.com/ugo-emekauwa/intersight-server-power-control
      

      If you are downloading the repository file as a zipped file, unzip the file once the download has completed.

    5. Generate a version 3 or version 2 API key from your Intersight account.

      (a). Log into your Intersight account, click the Service Selector and select System.

      Figure 1 - Go to Settings

      (b). Under the API section in the work pane, click API Keys.

      Figure 2 - Go to API Keys

      (c). In the API Keys section in the work pane, click the Generate API Key button.

      Figure 3 - Click the Generate API Key button

      (d). In the Generate API Key window, enter a description or name for your API key.

      Figure 4 - Enter an API key description

      (e). In the Generate API Key window, under API Key Purpose, select a version 3 or version 2 API key.

      Figure 5 - Verify version 2 API key selection

      (f). In the Generate API Key window, click the Generate button.

      Figure 6 - Click the Generate button

      (g). In the Generate API Key window, a new API key will be generated. Copy the API Key ID and download the Secret Key to a secure location.

      Figure 7 - Copy and save the API key data

    How to Use

    1. Please ensure that the above Prerequisites have been met.

    2. Within the unzipped Automated Server Power Control for Cisco Intersight repository, navigate to the intersight_server_power_control.py file.

    3. Edit the intersight_server_power_control.py file to set the key_id variable using the following instructions:

      (a). Open the intersight_server_power_control.py file in an IDLE or text editor of choice.

      (b). Find the comment # MODULE REQUIREMENT 1 #.

      Figure 9 - MODULE REQUIREMENT 1 location

      (c). Underneath, you will find the variable key_id. The variable is currently empty.

      Figure 10 - key_id variable location

      (d). Fill in between the quotes of the key_id variable value with the ID of your API key. For example:

      key_id = "5c89885075646127773ec143/5c82fc477577712d3088eb2f/5c8987b17577712d302eaaff"
    4. Edit the intersight_server_power_control.py file to set the key variable using the following instructions:

      (a). Open the intersight_server_power_control.py file in an IDLE or text editor of choice.

      (b). Find the comment # MODULE REQUIREMENT 2 #.

      Figure 11 - MODULE REQUIREMENT 2 location

      (c). Underneath, you will find the variable key. The variable is currently empty.

      Figure 12 - key variable location

      (d). Fill in between the quotes of the key variable value with your system’s file path to the SecretKey.txt file for your API key. For example:

      key = "C:\\Keys\\Key1\\SecretKey.txt"
    5. Edit the intersight_server_power_control.py file to set all the configuration variable values using the following instructions:

      (a). Open the intersight_server_power_control.py file in an IDLE or text editor of choice.

      (b). Find the comment # MODULE REQUIREMENT 3 #.

      Figure 13 - MODULE REQUIREMENT 3 location

      (c). Underneath, you will find the instructions to edit the configuration variable values to match your environment. Each variable has a sample value for ease of use. The variable values to edit begin under the comment ####### Start Configuration Settings - Provide values for the variables listed below. #######.

      Figure 14 - Start Configuration Settings location

      Completion of editing the configuration variable values is marked by the comment ####### Finish Configuration Settings - The required value entries are complete. #######.

      Figure 15 - Finish Configuration Settings location

    6. Save the changes you have made to the intersight_server_power_control.py file.

    7. Run the intersight_server_power_control.py file.

    Demonstrations and Learning Labs

    The Automated Server Power Control Tool for Cisco Intersight is used in the following demonstrations and labs on Cisco dCloud:

    Cisco UCS X-Series Lab Topology

    dCloud is available at https://dcloud.cisco.com, where Cisco product demonstrations and labs can be found in the Catalog.

    Related Tools

    Here are similar tools to help administer and manage Cisco UCS and Intersight environments.

    Author

    Ugo Emekauwa

    Contact Information

    uemekauw@cisco.com or uemekauwa@gmail.com

    Visit original content creator repository https://github.com/ugo-emekauwa/intersight-server-power-control
  • plugin-registry

    Plugin Registry for Golang

    GitHub Releases Build Status codecov Go Report Card GoDevDoc Donate

    Install and manage plugins for Golang application.

    Prerequisites

    • Go >= 1.15

    Install

    go get github.com/nhatthm/plugin-registry

    Usage

    plugin-registry helps to install plugins to a container at your choice. There are 4 tasks to manage them:

    • Install
    • Uninstall
    • Enable
    • Disable

    plugin-registry is backed by spf13/afero so feel free to use it with your favorite backend file system by using WithFs(fs afero.Fs) option. For example

    package mypackage
    
    import (
    	registry "github.com/nhatthm/plugin-registry"
    	_ "github.com/nhatthm/plugin-registry-github" // Add github installer.
    	"github.com/spf13/afero"
    )
    
    func createRegistry() (registry.Registry, error) {
    	return registry.NewRegistry("~/plugins", registry.WithFs(afero.NewMemMapFs()))
    }

    By default, plugin-registry will record the installed plugin in config.yaml file in the given container, you can change it to a new place of your choice by using WithConfigFile(path string) option, for example:

    package mypackage
    
    import (
    	registry "github.com/nhatthm/plugin-registry"
    	_ "github.com/nhatthm/plugin-registry-github" // Add github installer.
    )
    
    func createRegistry() (registry.Registry, error) {
    	return registry.NewRegistry("/usr/local/bin/plugins", registry.WithConfigFile("~/plugins/config.yaml"))
    }

    If you want to manage the plugins differently, you can write your own Configurator and use WithConfigurator() option to set it, for example:

    package mypackage
    
    import (
    	registry "github.com/nhatthm/plugin-registry"
    	_ "github.com/nhatthm/plugin-registry-github" // Add github installer.
    	"github.com/nhatthm/plugin-registry/config"
    )
    
    var _ config.Configurator = (*MyConfigurator)(nil)
    
    type MyConfigurator struct{}
    
    func createConfigurator() *MyConfigurator {
    	var c MyConfigurator
    
    	// init c.
    
    	return &c
    }
    
    func createRegistry() (registry.Registry, error) {
    	return registry.NewRegistry("/usr/local/bin/plugins", registry.WithConfigurator(createConfigurator()))
    }

    Installer

    There is no installer provided by this library, you need to install and import it in your project.

    Known 3rd party installers:

    Examples

    package mypackage
    
    import (
    	"context"
    
    	registry "github.com/nhatthm/plugin-registry"
    	_ "github.com/nhatthm/plugin-registry-github" // Add github installer.
    )
    
    var defaultRegistry = mustCreateRegistry()
    
    func mustCreateRegistry() registry.Registry {
    	r, err := createRegistry()
    	if err != nil {
    		panic(err)
    	}
    
    	return r
    }
    
    func createRegistry() (registry.Registry, error) {
    	return registry.NewRegistry("~/plugins")
    }
    
    func installPlugin(source string) error {
    	return defaultRegistry.Install(context.Background(), source)
    }

    Donation

    If this project help you reduce time to develop, you can give me a cup of coffee 🙂

    Paypal donation

    paypal

           or scan this

    Visit original content creator repository https://github.com/nhatthm/plugin-registry
  • CatKeychain

    menu-preview

    A clever app that hides secrets within photos of cats.
    Photos are downloaded within the app from TheCatAPI.
    I cannot distribute an executable version (yet), but a demo is available here and the instructions to build it yourself are simple (and listed below).

    Building

    If you want to build your own copy or even create your own version, the steps are simple:
    Note: the encryption functionality is hidden from github. This is to simply build an app that views cat photos.

    1. Clone or fork this repository (requires git) or simply download the source code
    2. Download and install Haxe
    3. Follow the instructions to install HaxeFlixel
    4. If you aren’t going to use Neko, you’ll need to set lime up for your OS
    5. Without a key to TheCatAPI, the code will compile into a demo build which will use predetermined photos and data. To get around this, get yourself a key, then add -DCAT_API_KEY="YOUR_KEY_HERE" to your build command. (Windows example: lime build windows -DCAT_API_KEY="YOUR_KEY_HERE")

    Note:

    This is built with Windows and HTML5 in mind. I do not have the means to test on Mac or Linux, so those builds may not function as expected.

    If you have any questions, leave them in the discussions tab.

    Credits

    Visit original content creator repository https://github.com/JBB248/CatKeychain
  • remix-jokes

    Remix Jokes App Tutorial with CockroachDB Serverless

    This app is based on the Remix Jokes App Tutorial but uses CockroachDB Serverless instead of SQLite for the database.

    Netlify Setup

    1. Install the Netlify CLI:
    npm i -g netlify-cli
    1. Sign up and log in to Netlify:
      netlify login
    1. Create a new site:
      netlify init
    1. You’ll need to tell Netlify to use Node 14, as at the time of writing Netlify uses Node 12 by default
      netlify env:set AWS_LAMBDA_JS_RUNTIME nodejs14.x

    Development

    You will be running two processes during development when using Netlify as your server.

    • Your Netlify server in one
    • The Remix development server in another

    # in one tab
    $ npm run dev:netlify
    
    # in another
    $ npm run dev

    Open up http://localhost:3000, and you should be ready to go!

    If you’d rather run everything in a single tab, you can look at concurrently or similar tools to run both processes in one tab.

    Deployment

    There are two ways to deploy your app to Netlify, you can either link your app to your git repo and have it auto deploy changes to Netlify, or you can deploy your app manually. If you’ve followed the setup instructions already, all you need to do is run this:

    $ npm run build
    # preview deployment
    $ netlify deploy
    
    # production deployment
    $ netlify deploy --prod

    Visit original content creator repository
    https://github.com/aydrian/remix-jokes

  • icalm

    icalm

    Ip – CIDR Annotation Lookup Microservice

    A microservice to lookup annotations for IP Addresses based on CIDR mappings

    Annotations can be loaded from a cvs file. Such cvs file has 2 columns: NETWORK,ANNOTATION

    Example CSV

    192.168.0.0/16,Annotation for RFC1918 Network (192.168.0.0/16)
    10.0.0.0/8,Annotation for RFC1918 Network (10.0.0.0/8)
    172.16.0.0/12,Annotation for RFC1918 Network (172.16.0.0/12)
    192.0.2.0/24,(TEST-NET-1)
    198.51.100.0/24,(TEST-NET-2)
    203.0.113.0/24,(TEST-NET-3)
    2001:DB8::0/32,v6 Example
    ff00::/8,v6 Multicast
    

    Lookups can be done via the line-protocol or http

    line-protocol

    The line-protocol is the easiest way to query icalm. It used via a TCP or UNIX socket.

    • A client just sends an IP-Address terminated with a NEWLINE.
    • icalm replies with the annotation of the matching network.
    • If there is no hit in icalms lookup table, the response is an empty line.

    Example usage

    Run server

    # bin/icalm-server -networks test.csv -line-listen 127.0.0.1:4226
    IP: CIDR annotation lookup microservice
    2024/05/21 18:15:04 Loaded lookuptable with 6 entries
    2024/05/21 18:15:04 Listening on 127.0.0.1:4226 for lineproto requests
    2024/05/21 18:19:35 Shutting down
    

    simulate client with netcat

    # nc localhost 4226
    192.168.1.1
    Annotation for RFC1918 Network (192.168.0.0/16)
    10.2.34.5
    Annotation for RFC1918 Network (10.0.0.0/8)
    

    http protcol

    Lookups via http api are currently not implemented. 🙁

    Visit original content creator repository
    https://github.com/securitym0nkey/icalm

  • RE-Context-or-Names

    RE Analysis

    Dataset and code for Learning from Context or Names? An Empirical Study on Neural Relation Extraction.

    If you use this code, please cite us

    @article{peng2020learning,
      title={Learning from Context or Names? An Empirical Study on Neural Relation Extraction},
      author={Peng, Hao and Gao, Tianyu and Han, Xu and Lin, Yankai and Li, Peng and Liu, Zhiyuan and Sun, Maosong and Zhou, Jie},
      journal={arXiv preprint arXiv:2010.01923},
      year={2020}
    }
    

    Quick Start

    You can quickly run our code by following steps:

    • Install dependencies as described in following section.
    • cd to pretrain or finetune directory then download and pre-processing data for pre-traing or finetuning.

    1. Dependencies

    Run the following script to install dependencies.

    pip install -r requirement.txt

    You need install transformers and apex manually.

    transformers
    We use huggingface transformers to implement Bert. And for convenience, we have downloaded transformers into utils/. And we have also modified some lines in the class BertForMaskedLM in src/transformers/modeling_bert.py while keep the other codes unchanged.

    You just need run

    pip install .
    

    to install transformers manually.

    apex
    Install apex under the offical guidance.

    2. More details

    You can cd to pretrain or finetune to learn more details about pre-training or finetuning.

    Visit original content creator repository
    https://github.com/thunlp/RE-Context-or-Names

  • posenet-python

    PoseNet Python

    This repository contains a pure Python implementation (multi-pose only) of the Google TensorFlow.js Posenet model. For a (slightly faster) PyTorch implementation that followed from this, see (https://github.com/rwightman/posenet-pytorch)

    I first adapted the JS code more or less verbatim and found the performance was low so made some vectorized numpy/scipy version of a few key functions (named _fast).

    Further optimization is possible

    • The base MobileNet models have a throughput of 200-300 fps on a GTX 1080 Ti (or better)
    • The multi-pose post processing code brings this rate down significantly. With a fast CPU and a GTX 1080+:
      • A literal translation of the JS post processing code dropped performance to approx 30fps
      • My ‘fast’ post processing results in 90-110fps
    • A Cython or pure C++ port would be even better…

    Install

    A suitable Python 3.x environment with a recent version of Tensorflow is required.

    Development and testing was done with Conda Python 3.6.8 and Tensorflow 1.12.0 on Linux.

    Windows 10 with the latest (as of 2019-01-19) 64-bit Python 3.7 Anaconda installer was also tested.

    If you want to use the webcam demo, a pip version of opencv (pip install opencv-python) is required instead of the conda version. Anaconda’s default opencv does not include ffpmeg/VideoCapture support. Also, you may have to force install version 3.4.x as 4.x has a broken drawKeypoints binding.

    A conda environment setup as below should suffice:

    conda install tensorflow-gpu scipy pyyaml python=3.6
    pip install opencv-python==3.4.5.20
    
    

    Usage

    There are three demo apps in the root that utilize the PoseNet model. They are very basic and could definitely be improved.

    The first time these apps are run (or the library is used) model weights will be downloaded from the TensorFlow.js version and converted on the fly.

    For all demos, the model can be specified with the ‘–model` argument by using its ordinal id (0-3) or integer depth multiplier (50, 75, 100, 101). The default is the 101 model.

    image_demo.py

    Image demo runs inference on an input folder of images and outputs those images with the keypoints and skeleton overlayed.

    python image_demo.py --model 101 --image_dir ./images --output_dir ./output

    A folder of suitable test images can be downloaded by first running the get_test_images.py script.

    benchmark.py

    A minimal performance benchmark based on image_demo. Images in --image_dir are pre-loaded and inference is run --num_images times with no drawing and no text output.

    webcam_demo.py

    The webcam demo uses OpenCV to capture images from a connected webcam. The result is overlayed with the keypoints and skeletons and rendered to the screen. The default args for the webcam_demo assume device_id=0 for the camera and that 1280×720 resolution is possible.

    Credits

    The original model, weights, code, etc. was created by Google and can be found at https://github.com/tensorflow/tfjs-models/tree/master/posenet

    This port and my work is in no way related to Google.

    The Python conversion code that started me on my way was adapted from the CoreML port at https://github.com/infocom-tpo/PoseNet-CoreML

    TODO (someday, maybe)

    • More stringent verification of correctness against the original implementation
    • Performance improvements (especially edge loops in ‘decode.py’)
    • OpenGL rendering/drawing
    • Comment interfaces, tensor dimensions, etc
    • Implement batch inference for image_demo

    Visit original content creator repository
    https://github.com/rwightman/posenet-python

  • SlotNVM

    SlotNVM

    I was looking for a way to store different data with different size to EEPROM where the size is only known at runtime.
    Also data should not get lost if a write access was interrupted.
    Most libraries I found can handle only compile time fixed data size or writes are not transactional or are not suitable for Arduino.
    This library should implement this as an Arduino library.

    Two possible solutions come to my mind.
    The first is a block based organization. There is a lot of extra data needed and if you don’t need a full block
    some bytes could remain unused. In contrast it is robust. If one block is defect all other could still be OK.
    An other solution is a heap implementation. There is less overhead and no unused bytes. But such an implementation is a little bit more difficult
    and if one structure is defect all data behind this is lost or at least not allocateable.

    This repository implement a block based EEPROM structure. Later also Flash access could added, therefore I will write about NVM from now.
    The NVM is split into blocks of equal size, called clusters. You do not access this clusters directly but store your data in virtual slots.
    Such a slot is indicate by a number and can be placed in any of the clusters or also in more than one.

    Features

    Currently implemented:

    • Support for Arduino buildin EEPROM
    • Extendable to other EEPROM using own access class
    • Transactional write
    • Possibility to reserve some free clusters to ensure that data can always safely be rewritten
    • Possibility to enable wear leveling via random function
    • Low RAM usage
    • Up to 32KiByte EEPROM (128 clusters with 256 bytes or 256 clusters with 128 byte each)
    • Up to 250 slots
    • 1 to 256 bytes per slot (0 byte not allowed)
    • Possibility to reduce maximum slots to reduce RAM usage
    • Use you own 8 bit CRC function (no xor in/out or reflect out)
    • Possibility to disable CRC for more available user data

    Currently not implemented:

    • Flash memory
    • CRC xor in/out or reflect out (and will never implement?)
    • Non transactional write as optional fallback
    • Use more than 8 bits for slot data length

    Usage

    For AVR microcontroller based Arduino boards with integrated EEPROM you can use one of the following classes.

    • SlotNVM16noCRC<>
    • SlotNVM32noCRC<>
    • SlotNVM64noCRC<>
    • SlotNVM16CRC<>
    • SlotNVM32CRC<>
    • SlotNVM64CRC<>

    Excample code:

    // Include the header
    #include <SlotNVM.h>
    
    // Create an instance
    SlotNVM16CRC<> slotNVM;
    
    int starts = 1;
    
    void setup() {
      Serial.begin(115200);
      
      // Call begin() once
      slotNVM.begin();
      // Init random generator for better wear leveling
      randomSeed(analogRead(0));
    
      // Now you can use readSlot() and writeSlot()
      if (slotNVM.readSlot(1, starts)) {
        Serial.print(F("This is start no. "));
        Serial.println(starts);
      } else {
        Serial.println(F("This is the first start"));
      }
    
      if (starts < 3) {
        ++starts;
        slotNVM.writeSlot(1, starts);
      }
    }
    
    void loop() {
    }
    

    Transactional write is implemented by first write the new data and than delete the old one.
    Therefore you need some free space if you want to overwrite a slot. If you want to ensure that you can
    always rewrite data you can create a SlotNVM with reserved space. You are not able to use this reserved
    space to write in an empty slot.
    This feature is useful for configuration data. Otherwise you are not able to change your configuration
    if SlotNVM is full of other data.

    #include <SlotNVM.h>
    
    // struct for my configuration
    struct configuration {
      char name[10];
      int  age;
    };
    
    const char DEF_NAME[] PROGMEM = "Arduino";
    const int  DEF_AGE = 42;
    
    configuration myConfig;
    
    // Create an instance
    // This SlotNVM reserves some space to always
    // allow to rewrite slot data with the size
    // up to the same size like configuration.
    SlotNVM32CRC<sizeof(configuration)> slotNVM;
    
    const uint8_t CFG_SLOT = slotNVM.S_LAST_SLOT;
    
    void setup() {
      Serial.begin(115200);
      
      // Call begin() once
      slotNVM.begin();
      // Init random generator for better wear leveling
      randomSeed(analogRead(0));
    
      if (!slotNVM.readSlot(CFG_SLOT, myConfig)) {
        // No configuration stored, use default
        Serial.println(F("Default configuration used"));
        strcpy_P(myConfig.name, DEF_NAME);
        myConfig.age = DEF_AGE;
    
        // Note: Reservation works only for rewriting
        // a slot not for the first write.
        // If you want to ensure to change this
        // configuration you should write it
        // before there is no space left.
        slotNVM.writeSlot(CFG_SLOT, myConfig);
      } else {
        Serial.println(F("Configuration was loaded"));
      }
    
      // Use other slots for your business
      for (uint8_t slot = 1; slot < CFG_SLOT; ++slot) {
        if (slotNVM.isSlotAvailable(slot)) {
          // Do something with this slot
          Serial.print(F("Slot "));
          Serial.print(slot);
          Serial.println(F(" has some data."));
        }
      }
    }
    
    void loop() {
    }
    

    The following tables should help to choose the right class. As you can see smaller cluster allows more slots but reduces usable memory size.

    SlotNVM class CRC Bytes / cluster User data / cluster Usable data / %
    SlotNVM16noCRC<> no 16 11 68,8%
    SlotNVM32noCRC<> no 32 27 84,4%
    SlotNVM64noCRC<> no 64 59 92,2%
    SlotNVM16CRC<> yes 16 10 62,5%
    SlotNVM32CRC<> yes 32 26 81,3%
    SlotNVM64CRC<> yes 64 58 90,6%

    Arduino Nano Every 256 bytes EEPROM

    SlotNVM class Clusters Slots Usable size / bytes RAM usage / byte
    SlotNVM16noCRC<> 16 16 176 5
    SlotNVM32noCRC<> 8 8 216 3
    SlotNVM64noCRC<> 4 4 236 3
    SlotNVM16CRC<> 16 16 160 5
    SlotNVM32CRC<> 8 8 208 3
    SlotNVM64CRC<> 4 4 232 3

    Arduino Uno / Genuino, Nano, Leonardo, Micro with 1024 bytes EEPROM

    SlotNVM class Clusters Slots Usable size / bytes RAM usage / byte
    SlotNVM16noCRC<> 64 64 704 17
    SlotNVM32noCRC<> 32 32 864 9
    SlotNVM64noCRC<> 16 16 944 5
    SlotNVM16CRC<> 64 64 640 17
    SlotNVM32CRC<> 32 32 832 9
    SlotNVM64CRC<> 16 16 928 5

    Arduino Mega with 4096 bytes EEPROM

    SlotNVM class Clusters Slots Usable size / bytes RAM usage / byte
    SlotNVM16noCRC<> 256 250 2816 65
    SlotNVM32noCRC<> 128 128 3456 33
    SlotNVM64noCRC<> 64 64 3776 17
    SlotNVM16CRC<> 256 250 2560 65
    SlotNVM32CRC<> 128 128 3328 33
    SlotNVM64CRC<> 64 64 3712 17

    If non of the classes abouve fits you needs or if you use a non AVR microcontroller or you want to use external EEPROM
    you need to use the class SlotNVM. Also you need to implement an access class. As a template you can use NVMBase or ArduinoEEPROM.

    // Include the header
    #include <SlotNVM.h>
    #include <MyAccessClass.h>
    
    // Create an instance, with
    //   no provision
    //   default slot count (based on cluster count)
    //   no CRC
    //   default random function (rand())
    SlotNVM<MyAccessClass, 32> slotNVM;
    
    void setup() {
      Serial.begin(115200);
      
      // Call begin() once
      slotNVM.begin();
      // Init random generator for better wear leveling
      srand(analogRead(0));
    
      // ...
    }
    

    Install

    Just download the code as zip file. In GitHub click on the [Code]-button and select Download ZIP.

    In Arduino IDE select Sketch -> Include library -> Add ZIP Library ... to add the downloaded ZIP file.

    Links

    License

    SlotNVM is distributed under the MIT License.

    Visit original content creator repository
    https://github.com/FraMuCoder/SlotNVM

  • yoga_graph

    yoga_graph

    tl;dr: graph of yoga poses and transition

    This software is used to generate the website https://bhpayne.github.io/yoga_graph/

    introduction

    All styles of yoga feature poses and transitions between poses.
    A style is often differentiated by the poses practiced, the speed of transition, and the length of holding the pose.

    The poses from all styles of yoga form the superset contained in the database (yoga_db.py). The database includes the connections between poses. Thus, it is possible to construct a graph. This graph includes all styles of yoga.

    jargon

    • A pose is any body position held for a length of time. A pose is a node on the graph
    • A transition is a body movement between poses. A transition is an edge on the graph
    • A flow is a sequence of poses and transitions.

    Relative Difficulty

    Poses are of varying difficulty, but the level of difficulty depends on the practitioner. Thus, determining pose difficulty is subjective
    If you are in a pose, transitions to adjacent poses on the graph are of varying difficulty. Transitions are easier to compare
    Each edge is assigned a numerical score (positive integer) to measure relative difficulty of the transition.

    Example

    Suppose you are in plank. You can transition to low pushup, then to laying flat on stomach. Thus, plank, low pushup, and laying on stomach are nodes, connected by two edges (plant to low pushup, and low pushup to laying on stomach).
    It is not possbile to get from low pushup to happy camper directly without passing through a few other poses. Thus, no transition (edge on the graph) exists between “laying on stomach” and happy camper.

    previous work

    Many yogis observe that there is a library of poses and document this. Examples include Dharma Mitra’s poster of 908 poses and his book “608 Asanas”. Various websites, such as www.yogajournal.com, catalog pictures of poses and their description. Books specific to a style of yoga document their flow or flows

    format

    Books are commonly linear in layout, which is a good format for describing a flow. A large highly connected graph is easier to explore in elecronic (maleable) format.

    Python is an easy to use and widely used language.
    The networkx package makes working with graphs straight forward

    tasks

    • Include more poses
    • Include more transitions
    • Include difficulty rankings for transitions
    • Verify existing graph entries
    • document flows from various styles
    • output different graph formats (i.e., for Yed, GraphML)
    • save history to file — pickle
    • read in previous flow — pickle
    • replay previous flow
    • graph: two sided paths (symmetry_history)
    • is this similar to

    Visit original content creator repository
    https://github.com/bhpayne/yoga_graph