teleren/devto huggingface dataset:
Apama Advent Calendar - 09 Dec 2021 - Apama and automated testing
Tags: apama, iot, cumulocity, streaminganalytics
Published: 2021-12-10 12:36:26

---
title: Apama Advent Calendar - 09 Dec 2021 - Apama and automated testing
published: true
date: 2021-12-09 18:51:28 UTC
tags: apama, iot, cumulocity, streaminganalytics
canonical_url: https://tech.forums.softwareag.com/t/apama-advent-calendar-09-dec-2021-apama-and-automated-testing/253829
---

_This is Day #9_ _of a short series of brief tips, tricks, hints and reminders of information relating to the Apama Streaming Analytics platform, both from Software AG as well as from the community._  

Read about Apama automated testing of solutions and sub-modules of solutions in the original article in the [Software AG Tech Community](https://tech.forums.softwareag.com/t/apama-advent-calendar-09-dec-2021-apama-and-automated-testing/253829). Learn how " **PySys**", a free Open Source project from the community, written in Python, for the purpose of generic System testing makes testing Apama solutions even easier.

_Note that some posts may be published a day or two early or late (e.g. Mon-Fri) so you may find you have bonus days with more than one post!_
[Binary Search]Leaves in Same Level
Tags: algorithms, java, 100daysofcode, programming
Published: 2021-12-09 18:26:47



# [Description](https://binarysearch.com/problems/Leaves-in-Same-Level)

Given a binary tree `root`, return whether all leaves are at the same level.

# ## Constraints:

- `n ≤ 100,000` where `n` is the number of nodes in `root`

---



### **Intuition**

BFS by Queue, you need to a variable (isLeafLevel) to check if you arrive the leaf level(if a node doesn’t have right subnode and left subnode, it calls a leaf)

### **Implementation**

- store all nodes in same level

```java
**int** number = nodes.size();
**for** (**int** i = 0; i < number; i++) {
    Tree node = nodes.poll();
    **if** (node.left != **null**) {
        nodes.offer(node.left);
    }
    **if** (node.right != **null**) {
        nodes.offer(node.right);
    }
}
```

- at same time, you need to check `isLeafLevel`

```java
if (node.left == **null** && node.right == **null**) {
    isLeafLevel = **true**;
}
```

- if `isLeafLevel` is `true` and there still are some node in queue, return `false`, because all leaves aren't in same level.

### 代码

```java
import java.util.*;

/**
 * public class Tree {
 *   int val;
 *   Tree left;
 *   Tree right;
 * }
 */
class Solution {
    public boolean solve(Tree root) {
        Queue<Tree> nodes = new LinkedList<>();
        nodes.add(root);
        boolean isLeafLevel = false;
        while (!nodes.isEmpty()) {
            int number = nodes.size();
            for (int i = 0; i < number; i++) {
                Tree node = nodes.poll();
                if (node.left != null) {
                    nodes.offer(node.left);
                }
                if (node.right != null) {
                    nodes.offer(node.right);
                }
                if (node.left == null && node.right == null) {
                    isLeafLevel = true;
                }
            }
            if (isLeafLevel && nodes.size() > 0) {
                return false;
            }
        }
        return true;
    }
}
```

### 复杂度分析

- time: O(*n*): you need to check all nodes if the answer is true;
- space: O(log*n*): you only need to store the nodes on same level
static has only one meaning
Tags: c, cpp
Published: 2021-12-09 18:17:54

`static` can be confusing with the wrong definition. Here's a simplified example:

The task is to write a `counter` function that takes no arguments and returns a different number each time, starting at `0` and adding `1` each time.

```c
int current_counter = 0;
int counter(void) {
    return current_counter++;
}
```

Now imagine someone is using this library. They write a function called `counter` just for testing. But when they try to link their code, it fails, telling them that `counter` is being redefined. But no worry, We are C programmers and we have `static` at our disposal!

Many believe static to have multiple meanings in C. 
- static functions are not exported globally
- static local variables are hidden globals
- static global variables are not exported globally
What could have caused this mess of keyword overloading?

The answer lies in a shift of perspective. **`static` means compilation unit local**. A compilation unit in C is just the files given to the c compiler (gcc, clang, msvc, etc) and what they `#include`.

 Using this definition we can say the following.
- static functions are owned by the compilation unit
- static global variables are owned by the compilation unit
- static local variables are owned by the compilation unit

Using this knowledge, we can rewrite the counter function to not leak `counter` into the API. 

First, move `current_counter` into a static in `counter`
```c
int counter(void) {
    static int current_counter = 0;
    return current_counter++;
} 
```

This will make `current_counter` not collide with anything else named current.

Next is to make `counter` a static function
```c
static int counter(void) {
    static int current_counter = 0;
    return current_counter++;
}
```

This will make `counter` not visible to files not in the same compilation unit.

Now things are fixed! The `counter` function and `current_counter` variable cannot be used in files not in the same compilation unit. 

I hope this helped someone.
Hacking: Local File Inclusion
Tags: programming, linux, webdev, security
Published: 2021-12-09 18:00:02

[Linux](https://www.linux.com/what-is-linux/) is a widely popular system for hosting web apps. It's users often think that by using Linux on a server, that it is secure.

But, just because you use Linux on your server and are good at the [shell](https://bsdnerds.org/what-is-linux-shell/) commands, does not mean your web app is secure. Sure you may know how to use [vim](https://vim.is), but neither that will stop a hacker. 

LFI (or File Inclusion) is a common vulnerability in web appps that provides access to files on the server in question. This allows an attacker to read files and sometimes to create or modify files on the target web server. 

In this article I will explain a vulnerability known as local file inclusion (LFI) and how this hack is carried out.

## LFI explained

With many server side programming languages, you can include files. In php that is often done with:

- include
- require
- include_once
- require_once

Lets say a web app has a parameter that lets you specify the file. The web app url can look like this:

`http://webapp.dev/forum.php?file=myCV.pdf`

And the code like this:

```php
<?php
    include($_GET["file"]);
?>
```

By changing the url parameter file, the attacker can open different files on the server. 

### Give me an example

An attacker might change the url and read different files. These can include system files:

```bash
http://webapp.dev/forum.php?file=/etc/passwd
http://webapp.dev/forum.php?file=../../../../../etc/passwd
http://webapp.dev/forum.php?file=/etc/shadow
http://webapp.dev/forum.php?file=/etc/issue
```

So what, the attacker can read system files?

The attacker can get your username from /etc/passwd and your hashed password from /etc/shadow.

The hashed password can be cracked using [crackstation](https://crackstation.net/), giving them full access to the server.

To prevent this as coder, always check and test user input (especially GET and POST variables)

The LFI vulnerability can also exist on other operating systems, but they store system files elsewhere.

To learn more about web hacking, you may like [this course](https://www.udemy.com/course/ethical-hacking-web-app-hacking/)
Using github api with react
Tags: github, webdev, javascript, react
Published: 2021-12-09 17:31:51

So you might have some experience of working with api. Its pretty fun and helps you a lot to build you skillset, and if you dont have any experience then after reading this blog, you will surely have.

In this blog we gonna build a github user searcher website. You can search for github users and it will display their info. You can choose what information you can display.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ng595h4qvp9a0zkq5t8l.jpg)

### [Donations are Very much appreciated](https://ko-fi.com/vikstack)

so this is how our User Interface will look. I am not gonna teach to make the UI as its pretty simple and easy. You can copy the css file from [the github repo](https://github.com/vikstack/github-user-searcher).

For this tutorial you wont need any libraries.

```js
import {useEffect, useState} from 'react';
```
We are importing useEffect and useState as it is necessary in this case.

```js
const [githubData, setGithubData] = useState([])
const [githubUser, setGithubUser] = useState("vikstack")
```
right here we are simply defining githubData ( this is an array ) so we can store out data returned from our api. The second useState is for the user we are searching for, we will change it later, you can define a default value, like I did as my github username.

```js
const fetchData = () => {
  return fetch(`https://api.github.com/users/${githubUser}`)
    .then((response) => response.json())
    .then((data) => setGithubData(data));
}
```
A simple function to get the json data from our api `https://api.github.com/users/[username] // you can open and check whats in this url` and then setting githubData and the response data from our api.

```js
useEffect(() => {
  fetchData()
}, [])
```
Well everyone knows what does this do, but for the beginners, we are just calling fetchData function inside a useEffect so that when a user enters our website, it will fetch the api.

```js
// these code are inside return()
<input type="text" placeholder="Search for User" onChange={(e) => setGithubUser(e.target.value)} className="input_search" />
<button onClick={fetchData} className="search_button">Search Github</button>
```
This code just set the githubUser as the user we want to search for and from the button we will fetch the api again for the new user.

```js
<img src={githubUser.avatar_url} height="100" width="100" />
<p>{githubUser.name}</p>
```
and now just explore the url `https://api.github.com/users/[username]` and replace `{githubUser.name}` to `{githubUser.[something in the url]}` like `{githubUser.location}`

It is easy, isnt it?

Now explore other api and try to do the same with those.

Its all for this blog.
#### [Following me on twitter will help us both](https://twitter.com/vikstack)

Thanks for reading it till here and I appreciate your feedback 😀
Outdoor Enthusiast platform gets Stuck in the mud!
Published: 2021-12-09 17:31:44

We are working on a platform for outdoor enthusiasts, it is beyond our passion. We have run into some snags and out of funds too.  Was hoping to speak to someone that knows pHp, Dart, Laravel and could talk to us! We are so close and yet so far from finishing!!! Sooo frustrating !!!!!
Thx,
Joseph Leaphart
CEO
Discoveries in Ruby(and Rails): String#squish
Tags: rails, ruby
Published: 2021-12-09 17:26:12

How many times have you had a string that has some extra whitespace in the start/mid/end of a string. To remove them you would have to use `strip` that would successfully remove the whitespace at the end of a string. Let's see

```ruby
"   Hello,    World     ".strip
 => "Hello,    World" 

```

It has successfully removed the whitespaces at the start and end. But what about the middle ones?. Usually you would have to write a regex for that 

```ruby
"   Hello,    World     ".strip.gsub(/[[:space:]]+/, " ")
 => "Hello, World" 
```

When using Rails. This method is available as `String#squish`
which does the same thing!

```ruby
"Hello,      World    ".squish
 => "Hello, World" 
```


Resources
- [String#squish](https://apidock.com/rails/String/squish)
- [String#strip](https://apidock.com/ruby/String/strip)
THR33 'S'
Tags: aws, devops, beginners, cloud
Published: 2021-12-09 17:13:16

## You Probably have guessed till now
I'm going to discuss about **Three S** wait what !!
### Well yes **Simple Storage Service** or **S3** 
As its name suggest "simple", According to me it is the most simple service of AWS which is very crucial to know about when learning about AWS service. 

You may ask why? 
Answer to that is **Data**, most crucial object of anything. Let's take an example about you, your photographs, video that you captured a long time ago, your favourite songs, movies anything that is close to your heart, you might wanna save them for a very long time and for that S3 is your best friend.

You might ask why?
So this is because S3 offer **11 9's of durability** that your data will not corrupt or be lost, with 99.99% availability, what's the difference between them?
I was confused too but, Now I'm clear with it so **durability means your data will be present in the storage facility** after you have uploaded it whereas **availability means how easily you can access your data from the storage facility**. 

NOTE: This figure changes according to the storage class of S3 you choose so be careful [click here](https://aws.amazon.com/s3/) to know more.

### So How does it work?
Well this blog is not a How to blog so I'll keep it simple without going into details, firstly you create a bucket yeah bucket then you put your folder or file into it.

## Now I'm coming to the Billion dollar question 
What is the maximum size of this **"BUCKET"**?
**It's unlimited** yes it's unlimited we can store any amount of data in this S3, but there's limit on the size of single object that is from 0 byte to 5 terabytes with single PUT request of 5 gigabytes,
### The point is you can upload 5 terabyte of single object after slicing it into 5 gigabyte file, I know it's confusing but I hope you get it. 
So why I'm emphasizing on this, real story 

I was giving interview for DevOps and the interviewer ask me what is the size of S3 Bucket I said unlimited, he denied and told me I was wrong with making a face 🙄🙄 at that point of time I was sure not to join this company.

But if you face anyone like this you can show them this screenshot👇👇
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0pywbw6lebbjw5g556es.png)
 link of the above page is [here](https://aws.amazon.com/s3/faqs/).

## And Some technical Stuffs about S3 storage.

- S3 have different storage classes as I have mentioned it earlier depending upon the use case, learn more about it [here](https://aws.amazon.com/s3/features/).

- The Bucket that you will create need to have a unique name.

- You can host static website on S3 bucket.

- Can store anything without the fear of loosing it.

### And one more piece of information
S3 is a type of storage that we call **Object storage**.

I'll discuss about the **storage type** in some other blog
Till then,

## Stay safe Stay healthy 

### Thank you for reading such a long article❤❤☺☺
Documenting E-Payment Development
Tags: go, fintech, epayment
Published: 2021-12-09 17:09:40



## Introduction & Motivation

Since I started learning programming, I've been very interested in the fintech industry. Having a solid accounting experience and coming from MBA into software, I decided few weeks ago to start building my demo e-payment solution. And I will be documenting it here.

I know this is probably going no where. But I am building it for myself rather than to make it into production. But I will try as much as possible to keep it solid.

My hope is one day I can engage in the Fintech industry and contribute to it.

## The Tech Stack

I am going to use Golang for the backend, React Native for the mobile app and React for the web app.

I will use Figma for the UI design and branding.

Please let me know if you are interesting to see the progress and the result. This will give me some motivation.

In the next post I will post about the scope, design and branding.

See you then.
HTML CSS full project
Tags: html, webdev, beginners
Published: 2021-12-09 17:05:12


![Shaif's Cuisine](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d9jd8d248jczeqjzrd2u.png)

## Shaif's Cuisine 👨‍🍳

**Live preview: [https://shaif-s-cuisine.netlify.app/](http://shaif-s-cuisine.netlify.app)**

**Watch on YouTube: [https://youtu.be/4y-_3Ayiauw](https://youtu.be/4y-_3Ayiauw)**

**Source Code: [https://github.com/ShaifArfan/shaif-s-cuisine](https://github.com/ShaifArfan/shaif-s-cuisine)**

---

## Project Description

A `HTML, CSS` project. Made with ♥ by the `web cifar community`. There will be 5 pages in the website (HomePage, MenuPage, AboutPage, ContactPage, BookingPage). In this project we gonna learn how we can create a website using simple `HTML, CSS`. The main purpose of the project is to get more used to with HTML, CSS. Although we used a few lines of JavaScript in the project for necessary cases. Later on, in this project, we gonna learn how we can deploy this site using `Netlify`. Also, we gonna learn the process from the zero to end and make the website ready for live production.

## What we are going to learn

- HTML, CSS
- CSS Grid
- Scroll Animation
- Netlify Deployment
- Netlify Form functionality
- More. . .

## Starter files

You can find all the starter files in `starter_files` branch. You can to go to the `starter_files` branch and `download zip` the starter files, or You can clone the project and git checkout to `starter_files` branch.

## Requirements

- Basic HTML, CSS

## Tools Used

1. icons - (flat & Feather icons)
2. illustration - [https://storyset.com/](https://storyset.com/)
3. UI Design: Figma
4. Code Editor: VS Code

## FAQ

### How can I get started?

You can get started by following the YouTube tutorial of this project. Here is the full tutorial video link: [coming soon].

### What I need to start the project?

Just open your favorite code editor and follow along with the `YouTube Tutorial`[coming soon].

### Who the project is for?

The project is for the people who wanna get more skilled in HTML & CSS.

## Similar Projects

Here are some Similar projects that you might be interested.

- [Amy's Portfolio - HTML, CSS Project](https://github.com/ShaifArfan/AMYs-Portfolio)
- [Ayan's Portfolio - React JS Project](https://github.com/ShaifArfan/AYANs-portfolio)

## Feedback

If you have any feedback, please reach out to us at [@web_cifar](http://instagram.com/web_cifar)

## Support

For support, join our [Community Group](http://facebook.com/groups/webcifar).

## License

[MIT](https://choosealicense.com/licenses/mit/)
Installing Erlang & Elixir on M1 Macs
Tags: erlang, elixir, macos, homebrew
Published: 2021-12-09 16:59:26

This week I have a new macbook pro M1, an amazing computer. After several times install erlang and elixir with but dont have any luck. Then I have a solution is install erlang by brew, then reshim to asdf, this solution was suggested by this [comment](https://github.com/asdf-vm/asdf-erlang/issues/221#issuecomment-958621514) on GitHub

I assume you have installed asdf already, but here is the full installation command I use 

```
brew install asdf autoconf wxmac openssl@1.1 fop coreutils automake libyaml readline libxslt libtool unixodbc unzip curl
```

Please note that you should install and using openssl@1.1 because Erlang doesn't support openssl 3 yet. If you already install the latest version, please try unlink and link version openssl@1.1 

```
brew unlink openssl@3 
brew link openssl@1.1
```

Next is add plugin erlang asdf 

```
asdf plugin add erlang https://github.com/asdf-vm/asdf-erlang.git
```
Now you are ready to install Erlang 24 and Elixir 1.12.3 using brew and reshim to asdf 

```
brew install erlang@24 
cp -r /opt/homebrew/opt/erlang@24/lib/erlang ~/.asdf/installs/erlang/24.1.7
asdf reshim erlang 24.1.7
asdf global erlang 24.1.7 
asdf install elixir 1.12.3-otp-24
asdf global elixir 1.12.3-otp-24
```

to install another version ( 23 for me ) 

```
brew unlink erlang@24 
brew install erlang@23 
cp -r /opt/homebrew/opt/erlang@23/lib/erlang ~/.asdf/installs/erlang/23.3.4.9
asdf reshim erlang 23.3.4.9
asdf global erlang 23.3.4.9 
asdf install elixir 1.10.4-otp-23
asdf global elixir 1.10.4-otp-23
```

Please remember switch version erlang before install elixir 

after these step, you can use asdf to switch version erlang instead of using brew 

PS: you could check detail version erlang install brew at [this](https://formulae.brew.sh/formula/erlang)
PS: you could try update to Mac Monterey, it will fix some issue with rosetta
OLAP Cubes
Tags: olap, database, data, productivity
Published: 2021-12-09 16:36:54

## WHAT
An OLAP cube is an aggregation of a fact metric on a number of dimensions. CUBE refers to a multi-dimensional dataset.

The advantage of OLAP cubes is that they are easy to communicate to business users. 

The data should be stored at the finest - atomic - level of the data. 

## OPERATIONS
### ROLL-UP
Aggregate or combine values and reduce number of rows or columns.
Example: Sum up sales of each city by country.

### DRILL-DOWN
Decompose values and increase number of rows or columns
Example: Decompose sales of a city into sales of districts.

### SLICING
Reducing N dimensions to N-1 dimensions by restricting on dimension to a single value.
Example: Taking out all data for one month.

### DICING
Same dimensions but computing a sub-cube by restricting some of the values of the dimensions.

## QUERY OPTIMIZATION
Business users want to slice, dice, roll-up and drill-down. Every combination will most likely go through all the facts table. This is not very performant.

We can use **GROUP BY CUBE(groupme, andme, andmetoo)**. This will make *1 pass* through the facts table and aggregate all possible combinations. This output is most of the time enough to answer all aggregations from business users, _without processing the whole facts table_. It also has the advantage that it is faster and easier to read than to write several queries and use **UNION** three times to get them together.

```
SELECT dimDate.month, dimStore.country, sum(sales_amount) as revenue
FROM factSales
JOIN dimDate on (dimDate.date_key = factSales.date_key)
JOIN dimStore on (dimStore.store_key = factSales.store_key)
GROUP by cube (dimDate.month, dimStore.country);
```

Example output: 
total, total by month, total by country, total by month and country

## TECHNOLOGY
### MOLAP
Pre-aggregate the OLAP cubes and save them on a special purpose _Non-relational database_.

### ROLAP
Compute the OLAP cubes _on the fly_ from existing _relational databases_ where the dimensional model resides.

#### [Code examples in Python notebooks] (https://github.com/BarbaraJoebstl/data-engineering-nd/tree/master/data-warehouse/lesson2-OLAP-cubes)

#### Sketchnote
To have all the above information in one view, I made a sketchnote.

![sketchnote OLAP cubes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zb62d3i3bx7ydoi93fhf.jpg)