teleren/devto huggingface dataset:
indexed db
Published: 2023-06-16 02:22:09

```
// Open or create the IndexedDB database
const request = indexedDB.open('todo', 1);

// Handle database upgrade or creation
request.onupgradeneeded = function (event) {
  const db = event.target.result;

  // Create an object store
  const objectStore = db.createObjectStore('tasks', { keyPath: 'id', autoIncrement: true });

  // Create an index
  objectStore.createIndex('taskName', 'taskName', { unique: false });
};

// Handle successful database opening
request.onsuccess = function (event) {
  const db = event.target.result;

  // Perform database operations here
  // For example, you can add, delete, or retrieve data

  // Close the database connection (optional)
  db.close();
};

// Handle database opening errors
request.onerror = function (event) {
  console.error('IndexedDB error:', event.target.error);
};
```

```
// Open or create the IndexedDB database
const request = indexedDB.open('todo', 1);

// Handle database upgrade or creation
request.onupgradeneeded = function (event) {
  const db = event.target.result;

  // Create an object store
  const objectStore = db.createObjectStore('tasks', { keyPath: 'id', autoIncrement: true });

  // Create an index
  objectStore.createIndex('taskName', 'taskName', { unique: false });
};

// Handle successful database opening
request.onsuccess = function (event) {
  const db = event.target.result;

  // Start a transaction and get the object store
  const transaction = db.transaction(['tasks'], 'readwrite');
  const objectStore = transaction.objectStore('tasks');

  // Create a new task object
  const newTask = { taskName: 'Task 1', priority: 'High', completed: false };

  // Add the new task to the object store
  const requestAdd = objectStore.add(newTask);

  // Handle successful task addition
  requestAdd.onsuccess = function (event) {
    console.log('Task added successfully');
  };

  // Handle task addition errors
  requestAdd.onerror = function (event) {
    console.error('Error adding task:', event.target.error);
  };

  // Complete the transaction
  transaction.oncomplete = function () {
    // Close the database connection (optional)
    db.close();
  };
};

// Handle database opening errors
request.onerror = function (event) {
  console.error('IndexedDB error:', event.target.error);
};
```
Solving the "It Works on My Machine" Problem with Docker
Tags: docker
Published: 2023-06-16 02:07:19

One of the most frustrating issues in software development is the "It works on my machine" problem. This occurs when a developer creates an application that runs perfectly on their local machine but fails to work properly when deployed to other environments.

[Docker](https://docker.com) has emerged as a solution to this problem. Docker allows developers to package an application and its dependencies into a container that can be run on any system that supports Docker. This ensures that the application runs consistently across different environments, eliminating the "_It works on my machine_" problem.

![Docker, we will ship your machine - meme](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/392m3govsca3l3gd3jo3.png)

So if your image runs correctly on your development machine, it's highly likely it will also run correctly somewhere else. Docker essentially provides a "it works on my machine" environment that you can ship.

With Docker, developers can easily create a container that includes all the necessary dependencies and configurations for their application. This container can then be shared with other developers or deployed to different environments without worrying about compatibility issues.

In addition to solving the "It works on my machine" problem, Docker also offers other benefits such as improved scalability, easier deployment, and faster development cycles. By using Docker, developers can focus on building and improving their applications rather than worrying about the underlying infrastructure.

In conclusion, Docker is a powerful tool that can help developers solve the "It works on my machine" problem and streamline their development processes. Its ease of use and compatibility with different environments make it an essential tool for modern software development.

_Start shipping your machine with [docker🚢](https://docker.com)_
After iPhone 14's 16.5 update, our Magento site was crashing saying 'A problem repeatedly occurred on' mentioning our url
Published: 2023-06-16 01:47:44

After couple of days digging Nipun (nippa) our js expert identified that it was actually a styling issue. 

> 
> So, the bottom line is that this issue is related to how Safari 16.5 loads the current .less files. It's possible that the site's .less files are large, and the new Safari version might have a bug that messes with memory or struggles with handling such large styling files. so adding the new change to a new file have fixed it.
> 

Initially we checked by disabling the custom modules, we checked the site on BrowserStack (BS) for iphone 14 - 16.5 update locally. There's a method in BS to check the local site on BS by tunneling. Then we enabled modules that we think aren't affecting a site crash like this. site was working fine. Then enabled a couple of modules I suspected. And it was the Algolia search customization module that seemed to be causing the issue. Then Nipun took over and carried on to identify exactly what causes the issue.

This is his update on that:

"Initially, I spent a lot of time debugging the JavaScript code, but nothing seemed to be the culprit. However, as you remember we discovered that removing the Algolia autocomplete code and disabling autocomplete Algolia, fixed the problem.

To address the issue, we manually moved the new Algolia code (the new update from Algolia themselves), which initially seemed to work. But we ran into some UI element breaks during the process. After fixing them, the issue popped up again. After more digging, we realized that removing the UI changes actually fixed the issue again, so as long as UI was broken site is working again

it was the UI fix, not the JavaScript fix, that resolved the problem. after removing all JS changes Adding the same UI fix to the existing .less file also broke the site, but same fix when added to a new styling file fixes the issue again without any JS changes 

We also found some clues suggesting that the Safari crashing issue might be related to an iOS memory problem. Similar bugs with the same error message pointed to a potential memory issue.

So, the bottom line is that this issue is related to how Safari 16.5 loads the current .less files. It's possible that the site's .less files are large, and the new Safari version might have a bug that messes with memory or struggles with handling such large styling files. so adding the new change to a new file have fixed it.

all my js code changes have been removed , only a slight UI fix is now available on staging please test it."
7 things you should care about to build a highly effective system
Tags: programming, softwareengineering, systems, devjournal
Published: 2023-06-16 01:32:00

7 things you should care about to build a highly effective system:

1. Extremely low maintenance

2. Low cost

3. High reliability

4. Robust security

5. Readiness to scale

6. Ease of hiring

7. Support for high-speed development



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


Thanks for reading this.

If you have an idea and want to build your product around it, schedule a call with [me](https://calendly.com/pragyanatvade).

If you want to learn more about DevOps and Backend space, [follow me](https://dev.to/pragyanatvade).

If you want to connect, reach out to me on [Twitter](https://twitter.com/pragyanatvade) and [LinkedIn](https://www.linkedin.com/in/pragyanatvade/).
Publishing Fake AWS API Keys on My Site
Published: 2023-06-18 00:32:10

---
title: Publishing Fake AWS API Keys on My Site
published: true
date: 2023-06-16 00:00:00 UTC
tags: 
canonical_url: https://nelson.cloud/publishing-fake-aws-api-keys-on-my-site/
---

I recently discovered [canarytokens.org](https://canarytokens.org), which helps detect if your infrastructure has been breached through various methods. For example, [canarytokens.org](https://canarytokens.org) lets me generate fake AWS API keys and receive an email notification when they are used. So I did exactly that just to see what would happen.

I published the fake AWS API keys to my site under [https://nelson.cloud/.env](https://nelson.cloud/.env). I chose `.env` because this is a file that is commonly scanned for by scripts/bots due to accidental uploads. I knew someone would find the credentials eventually and I was curious how quickly and frequently they would be accessed.

At the time of writing this blog post, this is what the `.env` file contains:

```shell
$ curl https://nelson.cloud/.env

AWS_ACCESS_KEY_ID=AKIA2OGYBAH6TDQ3GH4E
AWS_SECRET_ACCESS_KEY=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
REGION=us-east-2
```

Around 2 minutes after deploying out this file, I received my first email notification from [canarytokens.org](https://canarytokens.org). That was fast! It just goes to show that people are constantly scanning for credentials on the internet. Within an an hour or so I had ~10 notifications.

The notification emails from canarytokens.org provide useful details about the attackers using the AWS API keys. Here’s an example notification I received:

![canarytokens.org notification showing python usage](https://nelson.cloud/putting_up_fake_aws_keys/notification.png)

We can see based on the user agent that whoever used these AWS keys was doing this automatically using Python.

I also got another notification that shows that the attacker was using Powershell:

![canarytokens.org notification showing powershell usage](https://nelson.cloud/putting_up_fake_aws_keys/notification2.png)

It’s worth noting that **User Agent strings can be spoofed** , so take these screenshots with a grain of salt.

There is a guide here if you’re interested in trying this out for yourself:

- [https://docs.canarytokens.org/guide/](https://docs.canarytokens.org/guide/)
Strimzi: Apache Kafka on Kubernetes in Minutes!
Tags: database, bigdata, kubernetes, devops
Published: 2023-06-15 22:58:46

Hi everyone,

Today I came to share with you a summary about Strimzi, a super interesting option to configure and use a Kafka cluster in a container environment like Kubernetes(AKS, EKS, GKE, anthos, OpenShift, and others).

To know more:

https://jlgjosue.medium.com/strimzi-apache-kafka-on-kubernetes-in-minutes-394bbc2420f2

Thanks for reading; share this post! :)
N+1 in Ruby on Rails
Published: 2023-06-15 22:52:14

# How to detect N+1 

## Prosopite

### Install

```bash
gem install prosopite
```

```bash
bundle add prosopite
```

```ruby
# Gemfile
gem 'prosopite'
```

### Configure

Controller
Add the following to `ApplicationController`
```ruby
class ApplicationController < ActionController::Base
  unless Rails.env.production?
    before_action do
      Prosopite.scan
    end

    after_action do
      Prosopite.finish
    end
  end
end
```

Enable logging
```ruby
# config/environments/development.rb

config.after_initialize do
  Prosopite.rails_logger = true
end
```


### Spec
```ruby
# config/environments/test.rb

config.after_initialize do
  Prosopite.rails_logger = true
  Prosopite.raise = true
end
```

```ruby
# spec/spec_helper.rb

config.before do
  Prosopite.scan
end

config.after do
  Prosopite.finish
end
```

Now everytime you run the test, you will be able to see any error about N+1 queries.

Note: It won't raise any exception if only one association.

For example

```ruby
class Teacher < ActiveRecord
  has_many :students
end
```

```ruby
class Student < ActiveRecord
  belongs_to :teacher
end
```

### No exception
```ruby
teacher = Teacher.create(name: 'John')
teacher.students.create(name: 'Tom')

Teacher.first.students do |student|
  puts student.name
end
```

### Throw exception about N+1
```ruby
teacher = Teacher.create(name: 'John')
teacher.students.create(name: 'Tom')
teacher.students.create(name: 'Jerry')

Teacher.first.students do |student|
  puts student.name
end
```


```bash
Prosopite::NPlusOneQueriesError:
       N+1 queries detected:
         SELECT `students`.* FROM `students` WHERE `students`.`id` = ? LIMIT ?

```
Introduce Myself | Outreachy Internship | QEMU
Published: 2023-06-15 22:45:55

Hello everyone! My name is Yeqi Fu, and I am currently a Software Engineering student at Peking University. This year, I have the opportunity to participate in the outreachy Internship program, where I am interning with QEMU. My project focuses on "implementing native library calls for QEMU user mode emulation".
Among the Core Values List, three words have deeply resonated with me: "Curiosity," "Meaningful Work," and "Learning."
"Curiosity" has always been the driving force that propels me forward. Exploring new things brings me great joy and satisfaction.
"Meaningful Work" is a concept I frequently contemplate. I believe that the most meaningful tasks are often the most challenging and difficult to accomplish. This is why I have developed a keen interest in kernel, low-level, and binary-related topics.
"Learning" is a lifelong pursuit that I hold dear. I firmly believe in the importance of continuous learning throughout one's life.
Regarding the application process, I have always been fascinated by QEMU due to its low-level nature and complexity. When I came across the qemu community's recruitment of interns for a project that seemed perfectly suited to my abilities on the outreachy homepage, I knew I couldn't miss this opportunity. During the contribution period, I focused solely on contributing to the QEMU community. I went through a round of interviews and eventually received acceptance. Throughout the project, my mentor demonstrated exceptional technical expertise and patience, from which I gained valuable knowledge. I am immensely grateful to my mentor, qemu community, and outreachy for providing me with this remarkable opportunity.
Dev Environment with docker, php and Xdebug3!
Tags: php, docker, javascript, webdev
Published: 2023-06-15 22:39:24

> “If I had eight hours to chop down a tree, I’d spend the first six of them sharpening my axe.”
― Abraham Lincoln

I love that quote! known well our tools allow us to be more productive and because I love that too today Im going to share  my personal docker image which has been helping day by day to keep my axe shaped! 

I wrote other post about some topic years ago, but it needs some update here is it. 

The final product of this guide will be a docker image with a nginx webserver with php-fpm, x-debug and some other hints to support you day-to-day web development using node, queues, redis etc...

In the next lines you will find a introduction about how to use this image, but if you prefer [you can just watch my explanation video](https://youtu.be/PsrhFUkxpJAX)

## The dockerFile and The docker-compose.yml

Lets save our time... so please [visit my repository on git](https://github.com/getJv/php-webserver/tree/mac-system) to checkout, build and use this as local environment to your purposes. The README file will offer extra instructions to you.

## Project scaffold and usage

![Project scaffold. Next section descripes each entry](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l195n9wrvgt39zea6ogc.png)

```
php-nginx/ -> Main Project folder
   config/ -> Config shared between host and container
      nginx -> Hold ngnix configuration
         default.config -> each file here maps a host
   docker-compose.yml -> manager your containers
   dockerFile -> Recipe to build your dev environment
   workspace -> Place to add your projects
      -> default/ -> Project defaults, mapped by ngnix.   
```

The idea is simple like this, each new project should be added into workspace/ folder and each one should have a new nginx file to set it own hostName and documentRoot. Of course remember to set/map your hostName into your local hosts files. Again, all the steps are fully described in the README file

> It is important to remember this a a image to local development purposes, so to production and pipeline environment you should create another images.

Please like it, comment and share. 
If you have any question just write it in the comments.
Welcome to (yet) another dev blog
Tags: website, java, aws, route53
Published: 2023-11-17 20:57:40

---
title: Welcome to (yet) another dev blog
published: true
date: 2023-06-15 22:24:56 UTC
tags: Website,Java,AWS,Route53
canonical_url: 
---

# Intro

This site is intended as a repository of dev attempts, mainly dedicated to aws. Please enjoy the journey!

# About

The blog is a completely static website hosted on Amazon AWS S3, served by Cloudfront. The domain name is registered on Route53, and the configuration is (almost) on a CloudFormation template, which is resembled in the cover of this post

# Two domains

There are two different domains in two different AWS accounts, one having the Route53 hosted zone to marcoaguzzi.it, and the other one pointing to dev website.  
The certificates are generated by AWS certificate manager, and there’s a trick to generate a valid one also for the dev url. You can find more information [here](https://advancedweb.hu/how-to-test-with-a-live-domain-name-for-free/)
Convert object to Yaml by loading js lib
Published: 2023-06-15 22:08:57

## Convert object to Yaml

```js

$.getScript('https://unpkg.com/js-yaml@4.1.0/dist/js-yaml.min.js');
copy(jsyaml.dump(myObject));
```


## Convert object to JSON

```js
copy(JSON.stringify(myObject));
```
Day 763 : Mush
Tags: hiphop, code, coding, lifelongdev
Published: 2023-06-15 21:52:31

_liner notes_:
- Professional : Whew...what a day to wake up not feeling well. haha To start, I was a few minutes late to the first of 3 back to back meetings. Then I got tagged in an error with something on the documentation site. I helped create a proof of concept for an existing tool but with some new features like last year. Apparently, it was added to the new updated site. Didn't know that, but cool. So, I was asked to take a look and see what went wrong. Basically spent all day trying to trouble shoot things because whoever add the tool to the new site changed up the code I wrote slightly. The tool is written in Vue and maybe there were changes in the way to write Vue code since the past 8-9 months since I wrote the original POC, who knows. Narrowed it down to a Vue component that wasn't functioning the same way the Vue component that was available to me worked. Tried a couple of other components and those didn't work either. So basically, I just rewrote the component using regular HTML elements and got everything working. Ran into some issues where it looks like the site's styles overwrite the HTML elements and mess them up and I had to overwrite the overwrites to get the elements looking and working properly. Cleaned up the code and created a pull request so it can be reviewed and merged into the site. Of course it wouldn't be that easy because there were a bunch of random linting errors that popped up. Stuff like one element should go in front of another element and in the CSS, it should be single quotes, but everywhere else double quotes were fine. I don't know if it's specific to Vue, but a lot of the rules made no sense to me. haha I got it working so someone else can make it look nice.

- Personal : Last night I went through some tracks for the radio. I got all the non-library needed stuff working for the adding a session in my side project. I also added a tool to help generate the value needed for one of the environment variables to make it easier for the user. The good news is that the part that requires a third party library is similar to another side project so I think I can pull from that for this side project. Still didn't watch any anime. haha.

![View of a mountainous landscape of Austria with green and yellow pine trees in the foreground and snow covered mountains in the distance](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mgmcap535caa6raos7ay.jpg)

Pretty drained and my brain is mush from the day, so I'll probably take it easy and just pick up some albums on Bandcamp and get my Tweets ready for tomorrow. If I feel up to it, I'll start to put together tracks for Saturday and maybe get the library integrated into my side project so I can start saving sessions. We'll see. May be a good night to watch some anime before going to bed. We'll see.

Have a great night!

peace piece
Dwane / conshus
https://dwane.io / https://HIPHOPandCODE.com
{% youtube nV4DxYYVFnM %}
What are facades and how to use it on ruby
Tags: ruby, architecture, rails, facades
Published: 2023-06-15 21:33:18

To understand the usage of facades on real-life projects, let's imagine that we'll implement an integration with a third-party SDK like Stripe to allow payments on our system. All cool, right?

## Ok but... What is the problem with this?

Since we need to implement this SDK, the first thing that we can think of is to install the gem and just use it on our controller methods, right? Let's imagine that this gem provides the following class:

```ruby
class AwesomeStripeSDK
  def identify_user; end
  def register_card_for_user; end
  def pay; end
  def refund; end
  def apply_discount; end
  def cancel_payment; end
  def call_the_cops; end
  ....
end
```

Can we agree that this is a big class with an unknown number of parameters, right? 

Although it's easy to just [read the docs](https://pt.wikipedia.org/wiki/RTFM) and implement the correct methods with the correct parameters on our controller, it can become a little monster pretty easily, simply because we don't have much control over this whole `AwesomeStripeSDK` class. 

This gem could provide multiple classes that need to be used together for a single action or even provide a very confusing and messy set of method names, parameter structures, etc.

## The solution ? Facades!

Now that we understand the problem, it's pretty simple to propose a solution: just create another class!

The idea behind a facade is to simplify the implementation of a library or framework and also control the general structure of this service class.

For example, given the example `AwesomeStripeSDK` third party class, we can define a facade like the following:

```ruby
class PaymentFacade
  def self.pay(price:, card:, user:)
    # identify our user
    AwesomeStripeSDK.identify(user)

    # register the payment method
    AwesomeStripeSDK.register_card_for_user(user, card)
   
    # apply a fixed discount
    AwesomeStripeSDK.apply_discount(40)

    # pay the bill
    AwesomeStripeSDK.pay(price)
  end
end
```

Now on our controller, we just need to call the `PaymentFacade.pay` passing the correct parameters, and we can ensure that the payment is going to be made correctly without  worrying about the specific SDK API.

Another obvious advantage of this is that we can use the same facade on multiple classes in separate contexts and also write great tests since the scope is isolated. Cool, right?
Handling request methods: Golang http library
Tags: go
Published: 2023-06-15 21:07:29

Handling request methods in Golang's `net/http` library isn't as intuitive as you'd expect.

In the request, library there's a `Method` field that allows you to see what method a request uses.

```golang
func hello(w http.ResponseWriter, req *http.Request) {
  fmt.Fprintln(w, "Hello, world")
}
```

Starting with the example above, if you want the method to only respond to `GET` requests, add a conditional statement to make the request respond to only `GET` requests, and reject non-`GET` requests.

Take a look at an example of how the code will look after doing this:

```golang
func hello(w http.ResponseWriter, req *http.Request) {
  if req.Method == "GET" {
    fmt.Fprintln(w, "Hello, world")
  } else {
    w.WriteHeader(http.StatusMethodNotAllowed)
    fmt.Fprintf(w, "Cannot %s %s", req.Method, req.URL)
  }
}
```

You can apply this technique to any other type of request method, and you'll achieve the result you want.