Escher

repository·master·Indexed 20 days ago

https://github.com/gocircuit/escher

A language for programming in pure metaphors using a syntax for representing generic labeled graphs called 'circuits'. Escher aims to unify algorithm and data to enable the control of large-scale distributed systems through a single programmatic view, conceptualizing its runtime as a "backend browser" for manipulating data centers.

Tokens
5.5K
Snippets
24
Records
35
Agent score
72%

What's inside escher

  1. What is Escher?

    master

    Escher is a syntax for representing generic labeled graphs, referred to as circuits. It is designed to achieve linguistic uniformity between algorithm and data: Escher circuits can be used as executable code to manipulate other Escher circuits representing data.

    This paradigm is intended for controlling large, heterogeneous distributed systems with failing components and connections, allowing a developer to view an entire technology stack (backend services, mobile apps, cloud apps, etc.) within a single program.

  2. The Escher Runtime concept

    master
    The Escher Runtime is conceptualized as a "headless browser" or "backend browser". Just as a browser allows JavaScript to manipulate the DOM of a webpage, the Escher Runtime allows developers to manipulate entire data centers using the same semantic and syntactic approach used for the circuits themselves.
  3. Organize BDD-style tests with Ginkgo

    master

    Ginkgo allows you to structure tests expressively using a Behavior-Driven Development (BDD) approach. Key building blocks include:

    • Containers: Use Describe and Context blocks to create nestable groups for organizing specs.
    • Setup/Teardown:
      • BeforeEach and AfterEach: Run setup or teardown logic around every spec in the current scope.
      • JustBeforeEach: Separates creation from configuration (the 'subject action pattern').
      • BeforeSuite and AfterSuite: Run global setup and teardown for the entire test suite.
    • Specs: Use It blocks to hold your individual assertions.
  4. Install and set up Ginkgo

    master

    To use Ginkgo for BDD-style testing in your Go projects, you need to install the ginkgo CLI and the gomega matcher library.

    Follow these steps:

    1. Install the CLI and matcher library using go get.
    2. Navigate to your target package.
    3. Run ginkgo bootstrap to initialize a new Ginkgo suite.
    4. Run ginkgo generate to create a sample test file which you can then edit to add your own specs.
    5. Run your tests using either go test or the ginkgo command.
    # Install the ginkgo CLI
    go get github.com/onsi/ginkgo/ginkgo
    
    # Fetch the matcher library
    go get github.com/onsi/gomega
    
    # Setup a new suite in your package directory
    cd path/to/package/you/want/to/test
    ginkgo bootstrap
    ginkgo generate
    
    # Run tests
    ginkgo
  5. Handle errors and rate limiting

    master

    Errors from the Twitter API are returned as an ApiError type, which implements the standard Go error interface.

    Rate Limiting: Anaconda automatically handles Twitter's rate limits by retrying queries once the X-Rate-Limit-Reset period has passed. Because of this automatic retry mechanism, if a function returns an error, it is likely a different type of error (which can be inspected via the ApiError struct fields).

    To change this behavior and return rate limit errors instead of retrying, call ReturnRateLimitError(true).

  6. Implement rate-limiting with tokenbucket

    master

    The tokenbucket package implements the Token Bucket algorithm in Go, which is useful for rate-limiting, traffic shaping, or scheduling based on bandwidth constraints.

    To use it, you create a bucket with a specific capacity and refill rate, then use the SpendToken method to regulate actions. SpendToken returns a channel that blocks until the requested number of tokens are available. This bucket instance should be shared across all functions or goroutines that are subject to the same rate limits.

    // Create a new bucket
    // Allow a new action every 5 seconds, with a maximum of 3 "in the bank"
    bucket := tokenbucket.NewBucket(3, 5 * time.Second)
    
    // To perform a regulated action, we must spend a token
    // RegulatedAction will not be performed until the bucket contains enough tokens
    <-bucket.SpendToken(1)
    RegulatedAction()
  7. Authenticate with the Twitter API using Anaconda

    master

    To use Anaconda, you must provide your consumer key, consumer secret, and your user's access token and access token secret. Use anaconda.SetConsumerKey and anaconda.SetConsumerSecret for the application credentials, and anaconda.NewTwitterApi to initialize the client with user-specific credentials.

    anaconda.SetConsumerKey("your-consumer-key")
    anaconda.SetConsumerSecret("your-consumer-secret")
    api := anaconda.NewTwitterApi("your-access-token", "your-access-token-secret")
  8. Iterate over database content

    master

    Use db.NewIterator to traverse the database.

    Important: The slices returned by iter.Key() and iter.Value() are only valid until the next call to Next(). You must call iter.Release() when finished to prevent memory leaks, and check iter.Error() to ensure the iteration completed successfully.

    iter := db.NewIterator(nil, nil)
    for iter.Next() {
    	// Note: key and value are only valid until the next Next() call
    	key := iter.Key()
    	value := iter.Value()
    	_ = key
    	_ = value
    }
    iter.Release()
    err := iter.Error()