teleren/devto huggingface dataset:
What is proxy? Difference between forward proxy and Reverse Proxy 
Tags: computerscience, programming, networking
Published: 2021-04-08 07:47:46

By definition proxy means, 
>The authority to act on behalf of someone else. 

To understand the definition, we can refer to our college life, whenever we didn't want to attend a boring class, we setup a friend to give (proxy) attendance on behalf of ourselves. The phenomena is kind of similar. We have also proxy voting, where a person gives vote on behalf of some other person.

In computer science when people talk about proxy, most of the time they simply refers to "proxy server". 

Now let me explain what proxy server does. Let's say when you wants to to visit "https://dev.to/" from your bowser, your request doesn't directly go to that website. There is your ISP (Internet Service Provider) sits in between you and the website who takes your request and pass it to your desired website. Here your ISP is acting as a proxy for you. Your ISP is sending request on behalf of yourself and that what proxy generally does. This kind of proxy is also called forward proxy, where a proxy server takes request from client and forward the request to server (or some other proxy). 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3lpz3ng5v6kjfwhu5orr.png)

While forward proxy is for clients, reverse proxy is for servers. A reverse proxy accepts request from clients on behalf of servers and the pass that request to server. 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wdwk0kccbkx2tmnv5ttt.png)

Advantages of Forward proxy: 
* Send/ Block request

> Proxy can intercept your request and can make choice to pass the request and by this an ISP can block access to certain website ( eg. forbidden sites)

* Monitor request

> Proxy servers can log the sites visited by users. (ISP knows which website you visit by setting up proxy)

* Caching response

> Proxy can cache response for one request and then, when there are subsequent request to same site , they can send back the cached response instead of making a completely new request.

Advantage of reverse proxy

* Load Balancing

> A reverse proxy can evenly distribute request to all the available servers instead of just one server.

* DDOS protection

> By proxy a server can protects itself from Distributed Denial of Service attach by limiting the request or blocking the request patterns.


In summary, both types of proxy are almost same but the direction of information flowing.
The Differences Between Monolithic and Microservice Architecture
Tags: devops, aws, architecture, todayilearned
Published: 2021-04-19 03:47:29

Big words I know. First in order to determine the difference between the two let's define each one. 

####Monolithic 
Monolithic architecture in the tech industry are services that are completed in a single unit. Each part of the program is contained within one unit. A great and common example of this is drupal. Within a drupal site, you have a theme, template reprocessing, views, entity APIs, fields API, and more all making up the CMS. 

Amazon, Netflix, and Apple used to be a monolithic server but has since switched. The downside of having such a singular server was that amazon had to be sure the server capacity was able to handle all the traffic **possible**. This caused them to lose lots of money which no one wants. In addition, if a single part needed to be updated developers were required to rebuild and redeploy the entire server. 

Having a Monolithic server would be like having all the lights in your house be in a series circuit. You wouldn't be able to turn on just your bedroom light and instead would have to turn on all the lights in the house. This would make your electric bill very high and waste a lot of money. Not only this but if one light bulb in your house goes out then you can't use any lights in your house! Now I am not trying to say one bug will always bring down an entire monolithic server but you get the picture. 

####Microservice
Microservices were built as the solution to the tedious and inefficient monolithic architecture. 

A Microservice breaks down each component into a smaller set of independent components. Each component is in charge of carrying out whatever process they are in charge of as a separate service. This inherently means that each component has its own logic and functions. Each of these components is independently deployable and small. So to fix a bug or update a component developers no longer need to rebuild and deploy the entire server, just the part they are working on. Microservices allow the servers to scale to anticipated captities and limit themselves during downtime to save money. 

So back to the house example. Instead, our house electric is made up of parallel circuits so that you can scale to capacity (turn on as many lights as you need) and fix one problem without updating the whole system (change one light bulb while the rest are still on). 

I think this image does a great job of visually comparing the two. 

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dn68qjtnmhcfazi0q49k.png)

Check out these articles I used to help understand these topics: 

[Why Netflix, Amazon, and Apple Care About Microservices](https://www.leanix.net/en/blog/why-netflix-amazon-and-apple-care-about-microservices)

{% youtube qwFATW1ZHNc%}
Firebase Push Notification Laravel Tutorial
Tags: laravel, firebase, notification, webdev
Published: 2021-04-08 18:58:23

What is Push Notification?
Push notifications are clickable pop-up messages that appear on your user's browsers irrespective of the device they're using or the browser they're on. They serve as a quick communication channel enabling companies to convey messages, offers, or other information to their customers.

What is Firebase?
Firebase is a platform developed by Google for creating mobile and web applications. It was originally an independent company founded in 2011. In 2014, Google acquired the platform and it is now their flagship offering for app development.

Firebase is a Backend-as-a-Service (Baas). It provides developers with a variety of tools and services to help them develop quality apps, grows their user base, and earn profit. It is built on Google's infrastructure. Firebase is categorized as a NoSQL database program, which stores data in JSON-like documents.

What is Firebase Cloud Messaging (FCM)?
Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably send messages at no cost. Using FCM, you can notify a client app that new email or other data is available to sync. You can send notification messages to drive user re-engagement and retention.

https://techvblogs.com/blog/firebase-push-notification-laravel
Change The Theme in Android Studio
Tags: android
Published: 2021-04-08 19:09:40

After installing android studio for the first time, you will see the default theme. Which is white and the code is not easy to read. To enable the official dark theme on your android studio, follow the steps below:

Step 1: Go to ‘File’ and from the drop-down menu click on ‘Settings’

Step 2: Expand ‘Appearance & Behavior’ menu and click on ‘Appearance’

Step 3: Expand ‘Theme’ section and select ‘Darcula’

Step 4: Click on ‘Apply’ or ‘Ok’

In this way, you can switch between any of those 3-official themes. Here IntelliJ is the light theme and Dracula is the dark theme. Read the [article](https://tech.pathgriho.com/2021/03/how-to-change-theme-android-studio.html) about this
Selenium Java (Implicit & Explicit) Waits
Published: 2021-04-15 14:34:29

If you enter Websites, you usually wait a few seconds if you see the information. If click, based on your input, which first goes to the backend, you see changes. You have to wait till the changes are done. 
## Implicit Wait - globally declared
Declare globaly: 
"Hey Selenium, wait for n number of seconds before you throw exceptions!"
It listens to your DOM, if it displayed it will keep on. 
n is the maximum time Limit 

```java 
driver.manage().timeouts().implicitlyWait(5,limeUnit.SECONDS;
```
## Explicit Wait - targets a specific scenario 
Imagine a search Button. When you search a large amount of targets, it takes, sets say 15 seconds to load. 
Otherwise the Application should load faster. 
### WebDriverWait
Continuisly listen to DOM as well.
```java
WebDriverWait w = new WebDriverWait(driver, 5)
w.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("span.promoInfo")));
// or .elementToBeClickable .... 
``` 
[ExpectedConditions List](https://www.browserstack.com/guide/selenium-wait-for-page-to-load#toc2)
### Fluent Wait 
monitors at regular intervalls of time (Pollingtime has to defined) 
Example: if something is displayed,which you don't want to check. (after 3 sec "Card is accepted" - "Order is process" after 7 sec - .... ) 
```java
 Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
                .withTimeout(Duration.ofSeconds(30))
                .pollingEvery(Duration.ofSeconds(5))
                .ignoring(NoSuchElementException.class);

WebElement foo = wait.until(
//customised function - until methods returns webelement
new Function<WebDriver, WebElement>() {
 public WebElement apply(WebDriver driver) {
            if (driver.findElement(By.cssSelector("div#finishh4")).isDisplayed()){
             return driver.findElement(By.cssSelector("div#finish h4"));
            }
            else
            {
                return null;
            }
        }});
``` 

## Thread.Sleep
Part of Java, not specially Selenium 
waits the amount of time, without listening to DOM
JAVA - String and StringBuilder
Published: 2021-04-10 03:52:15

### String
1. Single copy of each String literal is maintained in String pool.
2. Since literals are immutable, they can be safely referenced by multiple variables. (interning)
3. Use variable.intern() to return the literal referenced by the String variable. E.g. 
```java
String str2 = str1.intern(); 
```
4. Initializing using "new" (not recommended as it will not reuse string pool literals) - E.g. 
```java
String str1 = new String("Hello"); // or 
String str2 = new String(charArray); // charArray is character array
```

### String Builder
1. Mutable.
2. Extra methods - append, insert, delete, reverse etc.
3. Instantiated using "new". E.g.
```java
StringBuilder sb = new StringBuilder(); //empty value
StringBuilder sb = new StringBuilder("Hello"); //value is hello
StringBuilder sb = new StringBuilder(10); //value is empty, default capacity(memory reserved) is 10
```
Capacity is elastic and will increase if more characters are added in the object.
Reading a character beyond current length(no. of characters stored) throws StringIndexOutOfBoundsException.
You can deploy your web app on Netlify using mobile!?
Tags: netlify, mobile, javascript
Published: 2021-04-22 08:03:02

Recently, one of my friend got into a rather frustrating situation. He doesn't have access to a  computer but he is really passionate about the whole web development thing. 

So, he asked me if it was possible to deploy/host a web app on Netlify using a mobile device.

While researching, I found quite a few people in the same situation asking the same question, *"is it possible?"*

And the answer is, **Yes, it is!! :)**


##So, how would we do it?

Well, there are two ways.

 - **(1)** The easy way :)

 - **(2)** The hard way (reasonably hard) :(

We will go with the easy way.

##Prerequisites 

 - A Github account. [Create one](https://github.com/join)

 - A Netlify account (duh!). [Create one](https://app.netlify.com/signup)

 - Download [SPCK Editor](https://play.google.com/store/apps/details?id=io.spck&hl=en_US&gl=US) from play store.

##Now the good parts

I was feeling lazy so I made a video instead ;)
Here is the video: 

{% youtube Nt8U3vtG6JM %}
Building Rails Applications in Docker
Tags: ruby, rails, docker, devops
Published: 2021-04-22 10:36:01

---
title: Building Rails Applications in Docker
published: true
description: Docker images provide a powerful interface for deploying rails apps.
tags: ruby, rails, docker, DevOps
canonical_url: https://blog.engineyard.com/building-rails-applications-in-docker?utm_source=Dev.to&utm_medium=Canonical-url
//cover_image: https://direct_url_to_image.jpg
---
By [Allan Espinosa](https://blog.engineyard.com/author/allan-espinosa)

Docker images can provide a powerful interface for deploying your Rails applications. Everything your application needs in order to run can be packaged inside a Docker image. The Docker images can then be deployed from your laptop, staging and to production. This greatly increases the parity between your development and production environments when making a Rails application.
However, always needing to create a Docker image just to test your code can be time consuming if you’re not careful. Consider the following Ruby application:

### config.ru:
<code>
app =  proc do |env|
  [200, {}, %w(hello world)]
end
run app
</code>

### Gemfile:
<code>
source 'https://rubygems.org'

gem 'rack'
gem 'nokogiri'
</code>

### Dockerfile:
<code>
FROM ruby:2.2.2

ADD . /app
WORKDIR /app
RUN bundle install

EXPOSE 9292
CMD rackup -E none
</code>

Everytime you make an update to your application in the config.ru file, Docker would have to install and recompile the nokogiri gem all the time to create your Docker image.

Since you don’t need to update the Gemfile compared to the rest of your application, you can move the installation of your Ruby dependencies (bundle install) to a separate layer in your Docker image. To do this, just update your Dockerfile as follows:
<code>
FROM ruby:2.2.2

ADD Gemfile /app/Gemfile
WORKDIR /app
RUN bundle install
ADD . /app

EXPOSE 9292
CMD rackup -E none
</code>
Now, everytime you update config.ru, Docker will use the layer generated by 'RUN bundle install'.

Doing this approach will optimize the time it takes to build your Docker images. There are other ways to optimize Rails and other web applications in Docker-based deployments. I talked some of it in my presentation in this year’s RailsConf. The presentation can be viewed here: {% youtube lpHgNC5bCbo %}
Chapter 2 of my book, [Docker High Performance](https://www.packtpub.com/networking-and-servers/docker-high-performance) also describes these optimizations in detail.

[Docker](https://blog.engineyard.com/topic/docker), [Containers](https://blog.engineyard.com/topic/containers)
Daily Developer Jokes - Thursday, Apr 22, 2021
Tags: jokes, dailydeveloperjokes
Published: 2021-04-22 12:00:24

---
title: "Daily Developer Jokes - Thursday, Apr 22, 2021"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
cover_image: "https://private.xtrp.io/projects/DailyDeveloperJokes/thumbnail_generator/?date=Thursday%2C%20Apr%2022%2C%202021"
published: true
tags: #jokes, #dailydeveloperjokes
---

Generated by Daily Developer Jokes, a project by [Fred Adams](https://xtrp.io/) ([@xtrp](https://dev.to/xtrp) on DEV)

___Read about Daily Developer Jokes on [this blog post](https://xtrp.io/blog/2020/01/12/daily-jokes-bot-release/), and check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/).___
### Today's Joke is...
![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e1258b4d7b44.png)

---
*Have a joke idea for a future post? Email ___[xtrp@xtrp.io](mailto:xtrp@xtrp.io)___ with your suggestions!*

*This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit.*

<!-- 
Joke text:
___Q:___ Why doesn't Hollywood make more Big Data movies?

___A:___ NoSQL.
 -->
dealing with async method calls
Tags: reactnative, help
Published: 2021-04-22 14:08:04

newNote is optional and if available should be pushed to notes colleciton via reducer using addProjectNotes function hook. The createProject methods seems called before the addProjectNotes completes execution and Notes collection is always blank. How can I call createProject only after addProjectNotes is fully executed?

'''
if (projectData.newNote) {
            addProjectNotes(addNote(projectData.newNote))
        }
        createProject(projectData, setIsSubmitting, submittedCallback);
'''
Sticky bubbles
Tags: practice, css, animation, javascript
Published: 2021-04-22 15:10:16

{% codepen https://codepen.io/helloCaptMomo/pen/BapvayN %}

## Attribution

### Sticky bubbles

Tutorial: 

[Frank's Lab - Sticky Bubbles Vanilla JavaScript Animation Tutorial | SVG Filters & ES6 Classes and HTML Canvas](https://www.youtube.com/watch?v=5575fjFzPT0)

### Glowing buttons

Source:

[@raulghm's pen](https://codepen.io/raulghm/pen/EjdwoO)
Javascript to convert binary to hex
Published: 2021-04-23 11:35:53

The numbering systems like binary, hexadecimal, and decimal are used by the electronic systems very heavily. All the computer motherboards and other electronic systems processors understand binary numbers only. If you want to communicate with the machine, then you need to send all the commands in binary numbers.

Here, in this article, I’m going to share the javascript code for binary to hex conversion. For one of my projects, I had to create a binary to hex converter to convert the binary values into hexadecimal and then store those values in the database.

When do you need to use a converter?

This converter is useful for the students. Along with students, if you are studying electronics or you are developing an internet of things the product or embedded system. I’m going to share the full code which you can just copy and paste and use in your project.

When I found out that I had to develop a converter, firstly, I had no idea about the numbering system. I wasted one-day understanding this and then I started developing the converter.
Code for binary to hex conversion:

```javascript
var bin = document.getElementById("text_value").value;
var binn = bin.toString(2).toUpperCase();
document.getElementById("ans").innerHTML = binn;
```

This is the code I found on StackOverflow. This code is great and it works well but there is a problem. This is good if you are looking to develop a tool for the students. If you want to develop a tool, then you need to make a few modifications to the code. You need to use a Javascript library called Bignumber.js. This library is used if you want to deal with large numbers.

When you are working with on an IoT product or an embedded system then you need to use the following code:

```javascript
var bin = document.getElementById("text_value").value;
    var m = new BigNumber(bin, 16)
    var binn = m.toString(2).toUpperCase();   
document.getElementById("ans").innerHTML = binn;
```

The Bignumber.js library is not an inbuilt library in Javascript. You need to import the script in the head tag. Just copy and paste the following code in the <head> tag.

```javascript
<script src="https://cdnjs.cloudflare.com/ajax/libs/bignumber.js/8.0.2/bignumber.min.js" integrity="sha512-7UzDjRNKHpQnkh1Wf1l6i/OPINS9P2DDzTwQNX79JxfbInCXGpgI1RPb3ZD+uTP3O5X7Ke4e0+cxt2TxV7n0qQ==" crossorigin="anonymous"></script>
```
And done! You have built the [binary to hex](https://binarytotext.net/binary-to-hexadecimal/) converter done. You can insert any binary number in the textbox and you will get the right hexadecimal result for the large numbers as well. If you made the converter with any other technique, then just share it by commenting below.
Paterna
Published: 2021-04-23 12:42:46

Paterna es un bonito pueblo ubicado en la comunidad Valenciana, más precisamente en la llamada Huerta Oeste; en la provincia de Valencia.
Cuenta con una gran variedad de atractivos para visitar, como son las Casas cuevas, que tienen su origen moro. Cabe destacar que en la actualidad se usan como originales galerías de arte, lo cual les ha valido para ser consideradas como Monumento de Interés Local.
Otros atractivos importantes que se pueden visitar son la Torre de Paterna, El museo municipal de cerámica, El gran teatro Antonio Ferrandis y el Espacio Cultural La Cova Gran entre muchos otros.
Este pueblo, al igual que en todos los de Valencia, festeja las fallas en el mes de marzo, y sus fiestas mayores en el mes de agosto.
Si quieres conocer más información sobre Paterna, puedes acceder a https://www.valenciaexiste.es/valencia/paterna/, donde encontrarás más información detallada sobre sus fiestas, su gastronomía y sus lugares de interés.
Work Time vs Home
Published: 2021-04-23 15:08:12

I've recently realized how short the hours at work are. On a workday we tend to think of tons of time available at work, and very little once we get home. However, if you've taken part of a workday to do non-work activity (e.g. read a book) you'll quickly realize how short the at-work time really is.

Each moment matters. The number of times you need to go to the bathroom maters. I'm not saying we should be paranoid about optimal time usage in every moment. In fact, we tend to greatly overestimate the time it takes to do the connective tissue tasks throughout the day. But we should be aware of where time is going at all times and try to not get lulled into a false sense of having lots of time to spare during the day.
Image Uploading with Shrine
Tags: ruby
Published: 2021-04-23 19:08:59

# My Experience With Ralis
​
![Goku](https://media.giphy.com/media/3otPoEvMyH2X0NTOWk/giphy.gif)

​
For my third project I choose to make a Real Estate web page. One of the features I wanted to include was the ability to upload pictures . This was a big learning experience, I have a new respect for uploading images.
​
# Getting Started
> Once I knew I wanted to upload images I stated to look around for different ways to do so. I came across a gem named shrine which can be found here `https://shrinerb.com/`. This is were the hard part came in. Aside from installing the gem like normal, there was a second step that needed to be done to allow images to be rendered. I needed to install  `https://imagemagick.org/index.php` ImageMagick onto my system. After this I was able to add images.
​
# Using Shrine
There was a slight learning curve to using this gem. There are pages upon pages of doucments on different ways to use this gem. To get started I follwed these steps : "Add Shrine to the Gemfile and write an initializer which sets up the storage and loads integration for your persistence library:"

```ruby
require "shrine"
require "shrine/storage/file_system"
 
Shrine.storages = { 
  cache: Shrine::Storage::FileSystem.new("public", prefix: "uploads/cache"), # temporary 
  store: Shrine::Storage::FileSystem.new("public", prefix: "uploads"),       # permanent 
}
 
Shrine.plugin :sequel # or :activerecord 
Shrine.plugin :cached_attachment_data # for retaining the cached file across form redisplays 
Shrine.plugin :restore_cached_data # re-extract metadata when attaching a cached file 
Shrine.plugin :rack_file # for non-Rails apps 
```
Next 
​`$ rails generate migration add_image_data_to_photos image_data:text`

Now you want to make an uploader class like such

```ruby
class Photo < ActiveRecord::Base
  include ImageUploader::Attachment(:image) # adds an `image` virtual attribute 
end
```

For the form you need 

```ruby
form_for @photo do |f|
  f.hidden_field :image, value: @photo.cached_image_data
  f.file_field :image
  f.submit
end
```
And in your controller you want to require photo and permit image
``` ruby
class PhotosController < ApplicationController
  def create
    Photo.create(photo_params)
		      end
 
  private
 
  def photo_params
    params.require(:photo).permit(:image)
  end
end
```

# Closing
After following these steps you should have a working image uploader. You can check out my project here. [Github](https://github.com/csdj92/real-estate-project)