teleren/devto huggingface dataset:
How to configure Rails, ActiveJob, Grape to use JSON log
Tags: ruby, rails, activejob, grape
Published: 2022-08-24 09:06:18

---
title: How to configure Rails, ActiveJob, Grape to use JSON log
published: true
description: In this article we will take a look of this topic and provide a working solution.
 
tags: ruby, rails, activejob, grape
# cover_image: ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uy7to72m80jyy75x0izt.jpeg)
 
# Use a ratio of 100:42 for best results.


---
Rails, activejob, grape all JSON format logging

Nowadays, most logging service eg: ES and SLS has better support for JSON format log. 
In the Ruby + Rails eco system there was a number of solutions(gems) providing such ability but most of them are outdate. 
In this article we will take a look of this topic and provide a working solution.  

In my case there are 4 logging sources
1. Rails app log
2. Sidekiq log
3. ActiveJob log
4. Grape log


Rails log is the simple one, add this gem and configure it as below:
gem "lograge"
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mo3yjcqkn86tphvl5mhh.png)
 

Sidekiq log and ActiveJob log are duplicate. In my case I only want to keep the ActiveJob log.
BTW: Sidekiq log has a JSON fomatter， you can follow the link below to configure it： https://github.com/mperham/sidekiq/wiki/Logging#output-format

In order to format ActiveJob log in JSON format you need to add the gem logist and configure your application as below. 

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


Last,  Let configure Grape log.  My goal is to merge grape log and Rails log then log both of them in JSON. In order to do so you need to add another gem and configure it as below:

gem 'grape_logging'
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ri6bi9xukgaypiyx14o1.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tagjm30t9ukrny2m1qyw.png)
  


As shown above, we take advantage of ActiveSupport instrument by which we connect grape log to Rails then we convert it into JSON format


PS: 
There is another solution, if you don't need to handle grape and ActiveJob you can check this gem, it may take less effort. 
https://github.com/reidmorrison/semantic_logger
Linking to a Giphy gif
Tags: giphy, gif, link, markdown
Published: 2022-08-24 09:04:03

---
title: Linking to a Giphy gif
published: true
description: Get a link to an actual gif from giphy
tags: giphy, gif, link, markdown
# cover_image: https://media.giphy.com/media/ETV4MRojrqsve/giphy.gif
# Use a ratio of 100:42 for best results.
---
Once you've found the gif you want, e.g. ⬇️ the [Platypus gif page](https://giphy.com/gifs/video-siz-platypus-ETV4MRojrqsve).
![Giphy image page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/72x9yipwzi9knxlw5jin.png)

Chances are you've tried right clicking on the image and opening it in a new page, or copying the url only to find you end up not with the image but [another web page with the platypus gif on it](https://media2.giphy.com/media/ETV4MRojrqsve/giphy.gif?cid=ecf05e47zf20o03fjfsfgbjjgwewhi2l61q69qg6dghvvtjg&rid=giphy.gif&ct=g).
![another web page with the platypus gif on it, but not the image itself](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mhdqnsyvedxpnu21xngg.png)

So to get a link to the gif itself go back to the first link, the [Platypus gif page](https://giphy.com/gifs/video-siz-platypus-ETV4MRojrqsve)'s URL is `https://giphy.com/gifs/video-siz-platypus-ETV4MRojrqsve` and the bit we need is the code on the end after the final `-`, i.e. `ETV4MRojrqsve`.
Put that code in to the url `https://media.giphy.com/media/{code}/giphy.gif`
and voila, you have a link to an actual gif that can be downloaded or embedded in markdown, html, etc.
e.g. 
[https://media.giphy.com/media/ETV4MRojrqsve/giphy.gif](https://media.giphy.com/media/ETV4MRojrqsve/giphy.gif) links to ⬇️
![an actual gif](https://media.giphy.com/media/ETV4MRojrqsve/giphy.gif)
Top 10 Github Repositories to Learn JavaScript.
Tags: javascript, github, git, programming
Published: 2022-08-24 09:02:25

1. 30 Days Of JavaScript - [http://ow.ly/wk3L50IL3nK]

2. JavaScript Questions - [http://ow.ly/H1h150IL3nL]

3. Awesome JavaScript Learning - [http://ow.ly/KlSZ50IL3nR]

4. JavaScript Algorithms and Data Structures - [http://ow.ly/ev4c50IL3nJ]

5. Clean Code JavaScript - [http://ow.ly/SSfc50IL3nN]

6. Awesome JavaScript - [http://ow.ly/2hPv50IL3nS]

7. Node.js Best Practices - [http://ow.ly/Hm8T50IL3nP]

8. Airbnb JavaScript Style Guide - [http://ow.ly/747550IL3nM]

9. 33 Concepts Every JavaScript Developer Should Know - [http://ow.ly/FmHj50IL3nQ]

10. Computer Science in JavaScript - [http://ow.ly/x8Zh50IL3nO]
How do you deal with Bad Interviewers? Rant
Tags: faang, interview, rant, badinterview
Published: 2022-08-24 08:59:34

---
title: How do you deal with Bad Interviewers? Rant
published: true
description: How do you deal with Bad Interviewers? Rant
tags: #faang #interview #rant #badinterview
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
---
I had an interview today at one of the FAANGs. I am good at coding and design but not best and I know that. 

My First interview was good. 

My Second Interview was bad. Even though I did average and I know i will not make it into Next Round, that was never my concern. 

Interviewer was bad. 

Not in an obvious swearing angry manner but in a subtle way which annoys you and makes you feel bad. 

He was like a passive aggressive ex with whom you are forced to work with. 

“Lets see if you can 'even' finish this”. 

“You don’t have 'that much' knowledge”. I didn't ask for his feedback. He told me this in the middle of discussions. 

These are not really something that i can flag to recruiter. But still, it is not Okay. 

I have interviewed with many startup CTOs and other people and I never faced this when I performed badly.

Now, I am wondering if it is the actual culture of that FAANG company. If it is, it is deal breaker for me. Many startups pay the equivalent amount who are better in culture and communication. 


So, yeah. That was my rant and Thanks for reading.
qwdwdaqd
Published: 2022-08-24 08:48:00

```
did_something = False
for element in elements:
    if element.something:
        do_something()
        did_something = True
        break

if not did_something:
    do_something_else()
```
`
did_something = False
for element in elements:
    if element.something:
        do_something()
        did_something = True
        break

if not did_something:
    do_something_else()
`
4 steps to render HTML file in React
Tags: programming, webdev, javascript, react
Published: 2022-08-24 08:42:56


## 01

I am using the Next.js repository so you need to install that, if you are new to it, [here is the link to get started](https://www.youtube.com/watch?v=Mmamf4_It9c).

https://medium.com/nerd-for-tech/you-really-need-to-migrate-to-next-js-ee646a9982ab

---

## 02

Once the repository is installed, we will deal with serverless functions(If new), followed by adding the following code to the serverless function.
I am creating a sample hello API inside the pages/api directory that will return an HTML file in response.

```
import fs from "fs";
const filename = "/portfolio/index.html";
module.exports = async(req, res) => {
 res.setHeader("Content-Type", "text/html, charset=utf-9");
 res.write(await fs.readFileSync(filename, "utf-8"));
 res.end();
};
```

---

## 03
Adding an HTML file is the third step.
pages directory in the root directory is the location for all static files in the next.js repository.
Add the HTML code to the profile.html file.

```
<html>
    <head>
        <title>Example</title>
    </head>
    <body>
        <p>This is an example of a simple HTML page with one  paragraph.</p>
    </body>
</html>
```

--

## 04
This is a crucial step, we will now tell next.js to show render the HTML code inside the index.html file and return them in the api/profile page.
When the user opens the profile page, api/profileendpoint will get the request to render the profile HTML file on the website.
We will tell next.js to configure the request using the proxy URL concept and that will be achieved by adding followed code in the next.config.js file in the root directory.

```
module.exports = () => {
 rewrites: async () => [{
  source: "/public/portfolio/index.html",
  destination: "/pages/api/portfolio.js",
 },],
}
```

Now our profile.html route will simply render an HTML file.

---

## 05
That's it for today, until next time, have a good, day.
Our website [iHateReading](www.ihatereading.in)
Animations — Hate & Love story #Shorts
Tags: programming, javascript, tutorial, beginners
Published: 2022-08-24 08:38:30

Animations - Everyone loves animations in website but when it comes to developing it’s a pain in the ass, i know. But I found this 2 interesting libraries called framer-motion and react spring. Both the libraries are easy to learn and integrate and use when it comes to developer experience. 

[Animations Inspiration]
(https://www.youtube.com/shorts/LrSERpyGP0A)

Conclusion
Until next time, have a good day.

Keep developing!!
Our website [iHateReading](www.ihatereading.in) || [Youtube](https://www.youtube.com/channel/UC6I-Tz6QwYbJpoIK7l0NtXA) || [Twitter](https://twitter.com/treyvijay)
Getting Started with the React Bullet Chart Component
Tags: react, webdev, reactnative
Published: 2022-08-24 08:36:41

Learn how easily you can create and configure the Syncfusion React Bullet Chart using the create-react-app command. This video also explains how to configure a few of the control’s basic features like setting a value and target, adding title, subtitle, value bar, target bar, dimensions, and tooltips. 

_Product overview_ : https://www.syncfusion.com/react-ui-components/react-bullet-chart

_Download an example from GitHub_: https://github.com/SyncfusionExamples/getting-started-with-the-react-bullet-chart-component

_Documentation_: https://ej2.syncfusion.com/react/documentation/bullet-chart/getting-started/

_Demo_: https://ej2.syncfusion.com/react/demos/#/bootstrap5/bullet-chart/default

{% youtube 9dKUZMD6_hk %}
What is SVM or Support Vector Machine?
Tags: svm, machinelearning
Published: 2022-08-24 08:30:23

---
title: What is SVM or Support Vector Machine?
published: true
description: Support Vector Machine is an elegant and easy to understand supervised learning algorithm
tags: svm, ml
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/te3pzrpn4xumdmy0ay7t.jpg
---

In machine learning, one of the most repeated tasks is classifying objects to certain criteria, into multiple categories.

# Examples of Classification problems
- is this email spam or not?
- is this a dog or a cat?
- is the stock going up or down?

# How SVM works?
![SVM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eev65bm3x672eebqn9g6.jpg)

Each object you want to classify is represented as a point on plane or let's call it an n-dimensional space
where each coordinate is a feature of the classification process.

SVMs handles the classification tasks by drawing a line dividing the dataset into two groups
![SVM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mu6gycaedmhqfur9nq99.png)

and if it's a 3 dimensional plane. it draws a plane like this
![2D SVM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xsg66whm4f47v1tm6trr.png)

and since there are many possibilities to draw a line or a plane that divides the data, SVM tries to find the most fitting line.

![3D SVM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4j8gr2efjjj8remqj8r8.png)

SVM create a margin which is a space around the dividing line.
to maximize the distance to points in either categories. and the points that fall on the margin are called the supporting vectors.

SVM needs a dataset which is labeled, that's why SVM is supervised learning algorithm. which means it requires both X (Features) and Y (Output) Values.

SVM solves a convex optimization problem which is also known as a **Cost Function**

# SVM pros & cons
SVM is simple, easy to understand and interpret, easy to use and implement. it also can perform well with small datasets.

yet its simplicity is not always the best.
not all data can always be split by a plane.

![Plane doesn't fit](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fhxthls3wefsa3wx61ja.png)

A common workaround to this problem is called the **Kernel Trick**
![Kernel Trick](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/evliiu7yyvikq3qumg0z.png)

we can augment data with some nonlinear features that are computed from the existing ones. then find the seperating hyperplane.

you can now start implementing SVM models using scikit learn.
opening a lot of doors for a variety of ML applications.
12-Factor Apps
Tags: devops, methodology, development
Published: 2022-08-24 08:27:00

The twelve-factor application is a methodology for Software as a Service (SaaS) or web applications or software deployed in the cloud. 
It tells us about the characteristics of the output expected from such applications. It essentially is just outlining necessities for making well-structured and scalable cloud applications:


Codebase: We maintain a single code base here for each microservice, with a configuration specific to their own environments, such as development, QA, and prod. Each microservice would have its own repository in a version control system such as Git, mercurial, and so on.

Dependencies: All microservices will have their dependencies as part of the application bundle. In Node.js, there is package.json , which mentions all the development dependencies and overall dependencies. We can even have
a private repository from where dependencies will be pulled.

Configs: All configurations should be externalized, based on the server environment. There should be a separation of config from code. You can set environment variables in Node.js or use Docker compose to define other variables.

Backing services: Any service consumed over the network such as database, I/O operations, messaging queries, SMTP, the cache will be exposed as microservices and using Docker compose and be independent of the application.

Build, release, and run: We will use automated tools like Docker and Git in distributed systems. Using Docker we can isolate all the three phases using its push, pull, and run commands.

Processes: Microservices designed would be stateless and would share nothing, hence enabling zero fault tolerance and easy scaling. Volumes will be used to persist data thus avoiding data loss.

Port binding: Microservices should be autonomous and self-contained.

Microservices should embed service listeners as part of service itself. For example— in Node.js application using HTTP module, service network exposing services for handling ports for all processes.

Concurrency: Microservices will be scaled out via replication. Microservices are scaled out rather than scaled up. Microservices can be scaled or shrunk based on the flow of workload diversity. Concurrency will be dynamically maintained.

Disposability: To maximize the robustness of application with fast startup and graceful shutdown. Various options include restart policies, orchestration using Docker swarm, reverse proxy, and load balancing with service containers.

Dev/prod parity: Keep development/production/staging environments exactly alike. Using containerized microservices helps via build once, run anywhere strategy. The same image is deployed across various DevOps stage.

Logs: Creating separate microservice for logs for making it centralized, to treat as event streams and send it to frameworks such as elastic stack (ELK). 

Admin processes: Admin or any management tasks should be packed as one of the processes, so they can be easily executed, monitored, and managed. This will
include tasks like database migrations, one-time scripts, fixing bad data, and so
on.
Wednesday Links - Edition 2022-08-24
Tags: java, bytecode, renovate, gradle
Published: 2022-08-24 08:24:29

Gradle plugins to work with java modules are now 1.0 (30 sec)🧃
https://twitter.com/jeoj/status/1560233664914628608

Renovate, a Dependabot alternative (5 min)🔧
https://blog.frankel.ch/renovate-alternative-dependabot/

Java Bytecode Simplified: Journey to the Wonderland (5 min)🧭
https://foojay.io/today/java-bytecode-simplified-journey-to-the-wonderland-part-2/

SQLite is not a toy database (7 min)🧸
https://antonz.org/sqlite-is-not-a-toy-database/

Testing Feature Flags (8 min)🏁
https://reflectoring.io/testing-feature-flags/
GeoJSON, PostGIS and the Right-Hand Rule
Tags: postgis, geojson, gis
Published: 2022-08-24 08:21:00

GeoJSON expects `Polygon` and `MultiPolygon` features are required to be "right-hand wound". I understand this to mean that the order of the coordinates that make up the polygon should move in a specific direction.

Unsurprisingly, exactly _which_ specific direction is somewhat ambiguous. The [GeoJSON spec](https://www.rfc-editor.org/rfc/rfc7946#appendix-B.1) says:

> Polygon rings MUST follow the right-hand rule for orientation (counterclockwise external rings, clockwise internal rings).

So, obviously, a simple 12-point `Polygon` in the shape of a circle and following the right-hand rule starts at, say, noon and the next point will be at, say, position 11 on the clock face. 

In my book the primary direction of travel in that case above is, well, left. So "right-hand rule" means "goes left".

So why are my polygons failing on [GeoJSONlint.com](https://geojsonlint.com/)? I produce my polygons by exporting them from my Postgres database using PostGIS.

PostGIS has a function to force polygons to follow the right-hand rule. The documentation for [`ST_ForceRHR`](https://postgis.net/docs/ST_ForceRHR.html) states:

> Forces the orientation of the vertices in a polygon to follow a Right-Hand-Rule, in which the area that is bounded by the polygon is to the right of the boundary. In particular, the exterior ring is orientated in a clockwise direction and the interior rings in a counter-clockwise direction.

So "right-hand rule" in PostGIS-land means... exactly the opposite of the same rule in GeoJSON land. And also matches my intuitive interpretation of "right-hand rule" as applied to polygons. 

To create correctly "wound" polygons in GeoJSON when exported from PostGIS, the solution is (obviously) to apply [ST_ForcePolygonCCW](https://postgis.net/docs/ST_ForcePolygonCCW.html) when exporting polygons as JSON from PostGIS.

## References
- This Stack Overflow comment was key to understanding all of the above: https://gis.stackexchange.com/questions/306567/postgis-geojson-query-not-validating#comment496061_306571
Importance of removing Dead codes
Tags: beginners, node, javascript, webdev
Published: 2022-08-24 08:11:00

#### Importance of removing Dead codes

I went through the old project that I created when I started my coding journey and discovered a lot of dead code. I did some research and came across the Dead-code elimination theory (DCE).

_DCE is a compiler optimization that removes code that has no effect on the program's output._

**Removing such code has several benefits:**
it shrinks program size, an important consideration in some contexts, and it allows the running program to avoid executing irrelevant operations, which reduces its running time.
It can also enable further optimizations by simplifying program structure.

---

**The following pictures illustrate how you can remove dead codes using visual studio code**

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

---

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


---

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

---

##### Final result
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p9kmg3jty4anyfpvybzh.png)
   
#### Conclusion
I hope this post was helpful. Thanks for reading
Enjoy Programming-Themed Humor? Here's today's daily developer joke!
Tags: jokes, dailydeveloperjokes
Published: 2022-08-24 08:00:22

---
title: "Enjoy Programming-Themed Humor? Here's today's daily developer joke!"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
published: true
tags: #jokes, #dailydeveloperjokes
---

Hi there! Here's today's Daily Developer Joke. We hope you enjoy it; it's a good one.

![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e1258a3e5534.png)

---

For more jokes, and to submit your own joke to get featured, check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/). We're also open sourced, so feel free to view [our GitHub Profile](https://github.com/dailydeveloperjokes).

### Leave this post a ❤️ if you liked today's joke, and stay tuned for tomorrow's joke too!

_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 did the developer ground their kid?

___A:___ They weren't telling the truthy
 -->