teleren/devto huggingface dataset:
When continuous deployment isn't possible
Tags: continuousdelivery, continuousdeployment
Published: 2022-09-21 16:53:54

---
title: When continuous deployment isn't possible
published: true
date: 2022-09-19 00:00:00 UTC
tags: continuousdelivery,continuousdeployment
canonical_url: https://jhall.io/archive/2022/09/19/when-continuous-deployment-isnt-possible/
---

Last Thursday I made the case for continuous delivery at [Agile Tour Vienna 2022](https://agiletourvienna.at/). And one of the people in attendance brought up a concern:

Sometime’s it’s impossible to deploy frequently.

Yes. Yes it is.

But that doesn’t mean you can’t do continuous _delivery_!

What’s the difference?

[Continuous Delivery](https://jhall.io/glossary/#cde) is the practice of continuously and automatically delivering a software package so that it is ready to release on demand.

In contrast, [Continuous Deployment](https://jhall.io/glossary/#cd) takes things one step farther, and also deploys the software into production.

It is my belief that continuous _delivery_ makes sense for practically all software projects. I’ve yet to find a situation where it’s not technically feasible.

However, there are many times when it doesn’t make sense (either technically, logistically, or from a business standpoint) to _deploy_ continuously. Here are a few:

- You sell a mobile application. Users don’t want to download 300 updates per day.
- You sell any software that users install. Users tend to like the option to do upgrades at a time they choose.
- Zero-downtime upgrades aren’t technically possible. OS updates, ROM flashing, or a handful of other scenarios can make upgrades inherently disruptive.
- You are contractually obligated to do updates during a specific maintenence window.
- Your software is installed on equipment with poor or no network connectivity. Microcontrollers in a manufacturing plant, or a rover on Mars, could be examples.

Even in the most extreme examples here, continuous _delivery_ still makes sense to me. And in fact, continuous deployment to a production-like test environment usually makes sense, too.

Bottom line: Don’t let “our customers don’t want 300 updates per day” be a reason not to operate a perfect continuous delivery process.

* * *
_If you enjoyed this message, [subscribe](https://jhall.io/daily) to <u>The Daily Commit</u> to get future messages to your inbox._
Application Controllers for Beginning Ruby Developers
Tags: programming, ruby
Published: 2022-09-18 23:46:51

## What are Application Controllers?

When beginning to build your API you will need to set up the controllers that allow you to fetch your API data. Here is where you set up what data you want to be grabbed when you use a specific tag in the fetch. 

### How do the Application Controllers work??

Well instead of using the initial def in ruby, you are going to use what ever method that you are going to be using. You also must create a function that will generate that information. 

## Get

```Ruby
=begin
table with data: schools
includes: 
name
grades
principal
rating
=end

get "/schools" do
variable = School.all
variable.to_json
end

```

Above you can see that I created a get request by the method initiation being `get`. What I did above allows me to grab all the data associated to the _schools_ table. The fetch URL for me would look like `http://localhost:9000/schools`. 

##Post

```Ruby
=begin
table with data: schools
includes: 
name
grades
principal
rating
=end

post "/schools" do 
variable = School.create(
name: params(name),
grades: params(grades),
principal: params(principal),
rating: params(rating)
)
variable.to_json
end
```

Same as before, the method is initiated with the fetch request that I am creating for API. In this method, you can see that I used the `.create` attribute that allows me to create a new element to be added to my table.

##Patch

```Ruby
=begin
table with data: schools
includes: 
name
grades
principal
rating
=end

patch "/schools/:id" do 
variable = School.find(params(id)
variable.update(
:principal => params(principal)
)
variable.to_json
end
```
The patch method, I use a `.find` to find the particular object that I'm trying to make adjustments to. Then I call `.update` on that object to update a specific part on the object. Above I choose to do the principal because that was the most likely part of the object to be updated. The fetch URL for this particular call would be `http://localhost:9000/schools/:id`. Then you would interpolate the id of the school into the URl. 


##Delete

```Ruby
=begin
table with data: schools
includes: 
name
grades
principal
rating
=end

patch "/schools/:id" do 
variable = School.find(params(id))
variable.destroy
variable.to_json
end
```
Like the patch request, the fetch URL stays the same. In the method you can see that I'm finding the object in which I intend to remove, and then calling the `.destroy` attribute in order to remove that idea from my database and the site.

This is the simple base on the building the CRUD controllers on an API. Feel free to use [Active Record Basics](https://guides.rubyonrails.org/active_record_basics.html) to help with any extra questions I didn't cover.
No-brainer Dark Mode for Next.js
Tags: nextjs, react, tailwindcss
Published: 2022-09-18 22:57:45

TIL: [@pacocoursey](https://twitter.com/pacocoursey) `next-themes`. I've been pretty happy using [@tailwindCSS](https://twitter.com/tailwindCSS) and letting the system render the right theme for the user, but if you do want to add UI controls. Give this no-brainer a shot, here's how I did mine.

Set the provider and attribute to display the active theme as a class. This will enable all `dark` classes present in the HTML tree. Don't forget to declare this in your [@tailwindCSS](https://twitter.com/tailwindCSS) config file: `module.exports = { darkMode: 'class' }`:

```typescript
import { ThemeProvider } from "next-themes";
import type { AppProps } from "next/app";

function MyApp({ Component, pageProps }: AppProps) {
    return (
        <ThemeProvider attribute="class">
                <Component {...pageProps} />
        </ThemeProvider>
    );
}
```

To consume and toggle the UI, use their `useTheme` hook. To avoid hydration errors, return a loading state of your choice until fully mounted:

```typescript
import { useState, useEffect } from "react";
import { useTheme } from "next-themes";

import { SunIcon, MoonIcon } from "@heroicons/react/outline";

export default function ThemeToggler() {
    const { resolvedTheme, setTheme } = useTheme();
    const [mounted, setMounted] = useState(false);

    useEffect(() => { setMounted(true) }, []);

    if (!mounted) return <></>;

    return (
        <button
            onClick={() => {
                setTheme(resolvedTheme === "dark" ? "light" : "dark");
            }}
        >
            {resolvedTheme === "dark" ? <SunIcon /> : <MoonIcon />}
        </button>
    );
}
```

It is that simple. It has 74,528 weekly npm downloads and if it's good enough for [@leeerob](https://twitter.com/leeerob), it's good for me too. Get creative with your loading state and toggle button (or not && KISS). Check out their `next-themes` [GH repo](https://github.com/pacocoursey/next-themes) for more info.

Originally published: [No-brainer Dark Mode for Next.js](https://hectorsosa.me/blog/no-brainer-dark-mode-for-next.js-EPNTw)
Deleting an Item in an Array at a Specific Index
Tags: javascript, webdev, tutorial, typescript
Published: 2022-09-18 22:26:22

In a previous article, [I covered how to insert items into an array at a specific index](https://fjolt.com/article/javascript-how-to-insert-at-index-array), so now let's look at how to **delete** items. Arrays, which are common data structures in Javascript, look a little like this:
```javascript
let myArray = [ 'some', 'array', 'content' ];
```
They are a way to store data, which is commonly used throughout Javascript. If we want to delete items from an array, we can use the `splice` method that all arrays have. Let's look at how it works.

## Deleting Items from an Array

If you just want to delete an item from an array, you only have to use `splice` with two arguments. The first is the index you want to start from, and the second is how many items you want to delete. For example, if we want to delete 2 items, starting at index 0 from our array, we'd do the following:
```javascript
let myArray = [ 'some', 'array', 'content' ];

myArray.splice(0, 2);

// Will return [ 'content' ]
console.log(myArray);
```

As you might've noticed, `splice` actually alters the original array. So be careful when doing this, as a copy of the original will not be made! Here are some other examples to consider:
```javascript
myArray.splice(3, 1); // Removes one item, at index 3
myArray.splice(0, 5); // Removes 5 items, at index 0 (i.e. from the start of the array);
```

## Deleting Items from an Array by Value
In a similar vein, we can also delete an item from an array by value, but this is a little bit more tricky. We have to use both `indexOf` and `splice` for this to work:
- First, we get the index of the item we want to delete by value, using `indexOf`.
- Then, we use that number to delete the array item.

Here's an example. We want to delete the item **ravioli** from our array below. First, we get the index of that item, using `arr1.indexOf('ravioli')`. This will return `2`, since that is the index of **ravioli** in our array. Then, we use that number to splice out one element at that index using `splice(itemIndex, 1)`. Now, **ravioli** is removed from our array!

```javascript
let arr1 = [ 'potato', 'banana', 'ravioli', 'carrot' ];
let itemIndex = arr1.indexOf('ravioli');

// Returns [ 'potato', 'banana', 'carrot' ], since ravioli has an index of 2
arr1.splice(itemIndex, 1);
console.log(arr1);
```

## Delete the last item from an Array
If all you want to do is delete the last item from an array in Javascript, use `pop`. The `pop()` method is an easy way to delete only the last element in an array. Just like `splice`, it mutates your original array, so a copy of your original array will not be kept:
```javascript
let arr1 = [ 'potato', 'banana', 'ravioli', 'carrot' ];

// Returns 'carrot'
console.log(arr1.pop()); 

// Returns  [ 'potato', 'banana', 'ravioli' ]
console.log(arr1);
```
SurrealDB looks nuts, right?
Tags: surrealdb, sql, graphql, rest
Published: 2022-09-18 22:26:13

I literally just discovered this platform as a means of getting in contact with the two brothers responsible for this apparent revolution in database query languages. Saw a Fireship video about it, spun it up on localhost with their nifty little CLI tool, followed their dead simple docs straight through a painless node client setup, and watched the magic. I had a buggy mess of a backend automations demo that I had to remove from my website the other day, but I'm pretty sure that once cloud hosting for SurrealDB is available, I will be able to replace about three different platforms I was trying to integrate with it. Here's a FigJam map describing what I'm talking about:

[Link](https://www.figma.com/file/OQQ501uPOmjXoTH9qgWjoG/Untitled?node-id=0%3A1)
React - Hooks as Optional Parameters
Tags: javascript, webdev, react, programming
Published: 2022-09-18 22:15:31

You can put hooks as parameters, but should you? And why would you want to do that?

---

Here’s a Sandbox with me playing around:

[https://codesandbox.io/s/hooks-as-params-1wt4bm](https://codesandbox.io/s/hooks-as-params-1wt4bm)

{% codesandbox 1wt4bm %}

But basically, it’s like this:

```jsx
function WeirdComponent({
	hook = useHook(),
	hook2 = useAnotherHook(hook),
}) {
	return (
		<div>
			<div>{hook}</div>
			<div>{hook2}</div>
		</div>
	)
}

function useHook(){
	return "hook!"
}

function useAnotherHook(value){
	return value || "default value"
}
```

And this will work exactly as if you would add the hooks inside the component.

---

## But why would you do it?

Back when I realized it was possible, I used it as a way to simplify unit testing of some components.

This let me just pass the values I wanted without having to mock the hook.

Another surprising thing you can do is to inject a different hook depending on whatever you want and change a component compartment changing only the hook.

---

## Should you?

Probably not. 

Maybe there’s some niche use of this, but whatever you can do this way, you can do it in another way.

(If you have an idea for a use case of doing this I would love to know about it.)

---

Cover Photo by [Grant Durr](https://unsplash.com/@grant_durr?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/hook?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)
MQTT Series: Authentication & Authorization
Tags: mqtt, iot
Published: 2022-09-18 21:53:47

## Authentication

Mosquitto 2.x is now more secure by default and requires users to make an active decision about how to configure security on their broker, rather than possibly relying on the previous very permissive behavior, as well as remove privileged access more quickly.

When Mosquitto is run without a configuration file, or without configuring any listeners, it will now bind to the 127.0.0.1 and/or ::1 loopback interfaces. This means that only connections from the local host will be possible.

Running the broker with a listener defined will by default bind to 0.0.0.0/:: and thus be accessible from any interface.

All listeners now default to allow_anonymous false unless explicitly set to true in the configuration file. This means that when configuring a listener, the user must configure an authentication and access control method, or set allow_anonymous to true.

Edit the configuration file
```
sudo nano /etc/mosquitto/mosquitto.conf 
```

Edit the file adding the following content
```
# Setup listener port
listener 1883
# Set log type
log_type all
log_timestamp true
# Set the usser password file
password_file /etc/mosquitto/passwd
```

Restart the service

```
sudo systemctl restart mosquitto
```

Create MQTT users setting the password file defined before and replace **mqtt-user1** for your desire username

```
sudo mosquitto_passwd -c /etc/mosquitto/passwd mqtt-user1
```

Restart the service again
```
sudo systemctl restart mosquitto
```

At this point you're ready to test the publish and subscribe commands. 
In one terminal session run the following command:
```
mosquitto_sub -h <BROKER_IP> -t "mqtt/mytopic" -u mqtt-user1 -P password
```
In other terminal session run the following command:
```
mosquitto_pub -h <BROKER_IP> -u mqtt-user1 -P password -t mqtt/mytopic -m "Hello World!"
```


## Authorization on Mosquitto Broker
The created users have access to all the topics, to limit the access permissions you have to configure the ACLs (Access Lists).
Create the ACLs file
```
sudo nano /etc/mosquitto/aclfile
```
and put the following content
```
# This only affects clients with username 
user  mqtt-user1
topic readwrite #
topic read $SYS/#

user mqtt-user2
topic readwrite mytopic/#
topic read readponly/#

# This affects all clients.
pattern write $SYS/broker/connection/%c/state
```

Edit the mosquitto configuration file
```
sudo nano /etc/mosquitto/mosquitto.conf
```
and add the following line
>acl_file /etc/mosquitto/aclfile 

Restart the service
APIs
Tags: webdev, programming, javascript, productivity
Published: 2022-09-18 21:45:55

**APIs** which stand for Application Programming Interfaces is a communication intermediary between th eclient and server and this enables sending of requests and fetching of responses.
An **API documentation** cointains information on how developers should structure requests and responses.

There are different types of APIs some of which include:
**SOAP API**- Simple Object Access Protocol . This enables the client and server exchange images via XML.This type of API is less flexible.
**RPC APIs**- Remote Procedure Calls. The client executes a funcyion or procedure in the server while the server send sthe output back to the client.
**REST API**- This API is frequently requested and used in the web today. Client sends data request to the server and the server  uses client data to perform intenal actions and sends the output back to the client.
**WebSocket API**- Uses JSON objects to pass data. Supports two way communication between client and server. Server can send callbacks to more than one client.
**Private APIs**- Used to connect data and servers within the company.
**Public APIs**- Open to use by everyone.
**Patner APIs**- Only accessible to developers to facilitate inter-business partnerships.
**Composite APIs**- Combine two or more APIs to deal with complex system requirements.


## REST API.
Stands for representational State Transfer.uses HTTP requests like GET,POST,PUT and delete to get data from the server.
**GET**- Used to retrieve data from the server.
**PUT**- Used to create a resource or overwrite it.
**POST**- Used to update resources in the server.
**DELETE** - Used to delete resources from the server.

## Advantages of Rest Apis.

**It is independent**. This means that the data storage is seperate from the server and the UI.
**It is lightweight**. It relies on the HTTP standard.This enables it to be fast.
**It is scalable and flexible**- Intergration can be done without alot of work and it is easily scalable because of the difference between the client and the server.


**API endpoint**- The final point of contacts in the API system. They are very important because of security reasons.

## How to Create an API
Provide a blueprint for your API whisldt thinking about the different API use cases.
Create prototypes using reusable codes. Once ready test and customise depending to the needed API specifications.
Test to avoid bugs and defects.This also protects from malicious attacks.

## Uses of API.

**Data Sharing**: When a program is needed to get data from a third party source, an API is used to retrieve the data.
**App Intergration** Used in the working of two or more applications.
**Embedded content**: To incorporate a piece of unhosted content in a company.
**Internal Systems**: APIs can not only be used externally within businesses and companies.

##Places to find APIs
RapidAPI.com.
ProgrammableWeb.
Public APIs.
API List.
API For That.
APIs. guru OpenAPI Collection.
Google APIs Discovery Service.
Inserting an Item into an Array at a Specific Index in Javascript
Tags: javascript, webdev, tutorial
Published: 2022-09-18 21:38:54

[Arrays are common data structures found in Javascript](https://fjolt.com/article/javascript-arrays-introduction), which typically look a bit like this:
```javascript
let myArray = [ 'some', 'data', 'here' ]
```

They act a lot like arrays found in other languages, and are relatively easy to define. Above, we have an array consisting of three items, which we've stored within our array, which is conveniently called `myArray`.

Sometimes, though, we want to insert a new item into an array at a specific point. For example, maybe we want to insert the word `new` after `some`. This is known as inserting an item into an item at a specific index, and today we're going to look at how you do that in Javascript.

## Inserting an Item into an Array at a Specific Index

In Javascript, this turns out to be quite an easy operation to perform. We use the `splice` method, which is a simple function that takes 3 arguments - which also lets us delete items too. Splice accepts 2 arguments if you want to delete items from your array, or 3+ if you want to add items. 
```javascript
splice(startIndex, deleteCount, newItem1, newItem2, newItem3...)
```

**Only the first option is required** - and the rest are optional. So splice can take the following formats:
```javascript
let myArray = [ 'some', 'data', 'here' ]

myArray.splice(0); // does nothing
myArray.splice(0, 2); // Deletes two items, starting at index 0. So 'some' and 'data' are deleted
myArray.splice(1, 0, 'new'); // Deletes zero items. Adds 'new' at index 1. 
myArray.splice(2, 0, 'is', 'cool') // Deletes zero items. Adds 'is', and 'cool' at index 2.
```

As you can see, you can add an infinite number of new items to your array using this method. It manpulates an array - so the original array is changed by this function. You don't have to delete any items using `splice`, but you can if you want. Either leaving the delete count as 0, or empty, will mean no items are deleted from your array. Any data inserted in the third argument (or any argument after the third argument) is added to the array at the specified index.

Here is another example, where we insert 'broccoli' into an array at index `2`:

```javascript
let arr1 = [ 'potato', 'banana', 'ravioli', 'carrot' ];

// Inserts broccoli at position 2, after deleting 0 items
arr1.splice(2, 0, 'broccoli');
    
// Returns [ 'potato', 'banana', 'ravioli', 'brccoli', 'carrot' ]
console.log(arr1);
```
Piotr Drozd Open Source Release 0.1
Published: 2022-09-18 21:21:50

In my previous blog i talked about the lab 1 in my open source course which was about working with someone else in my class to review my Static Site Generator. Now it is complete for the first release of the Assignment.

# What is my SSG

https://github.com/P-DR0ZD/pdrozd-ssg

pdrozd-ssg is the ssg or Static Site Generator I created, it is made with Python 3. Originally I wanted to use C++ or JavaScript as that was a language i have a lot of experience with however i decided i wanted to try something new so i wanted to use python. My only experience with python is my introduction to computer science class in high school where I first learned programming. So i didn't have much experience working with it. After using it for this assignment I feel more confident learning new things as after working with so many languages at Seneca i feel like I am a way better developer than when i started off.

# Optional Features

The Optional Features i included were

1. Parsing a title from the files then i would create a header inside the HTML from that title

2. Recursively searching directories so i can find Text files

3. Generate a Index File from the created documents

# How to use

after installing python 3 and cloning the directory to your machine use the below command with any of the following options options
```py .\ssg.py [options]```

##### Options
* -h or --help this will display to the user the options they have

* -v or --version this will display to the user the current verison of pdrozd-ssg

* -i or --input this with a combanation of file or directory will output your files as a Static Site
  to use put in the format py ssg.py -i or --input [file.txt] or [directory\]