teleren/devto huggingface dataset:
Clojure 101 / atom
Tags: clojure, tutorial, functional
Published: 2020-07-04 06:44:33

Most of the data structures you encounter in Clojure are immutable. When you `conj` to a list, or when you `assoc` to a map, you end up with a brand list and map respectively. Sometimes, though, you will have to mutate data. This is where an atom comes in.

Suppose you are keeping track of a player's state - namely mana and health, and because we have many "components" that subscribe to the player's state, we need to mutate the state instead of simply returning one like we're used to.

To update the value of an atom, we can use the `swap!` function.

```clojure
(def player (atom {:health 100
                   :mana 50}))
```

Let's say we just got a mana boost.

```clojure
(swap! player update :mana + 10)

(get @player :mana) ;; 60
```

You might be wondering: what's with the @?
Think of an atom as a reference type. To get the value of an atom, you must deference it with @.

If you know C++, it can help to think of atoms as like pointers in C++. To get the value pointed at by a pointer variable, we use `*ptr` in C++. In Clojure, we use `@atom`.

I hope you got the point. I'm out.

Warmly,
DH
React Hooks: (0 , _customhooks.default) is not a function
Tags: help, react
Published: 2020-07-04 06:35:07

**[Update]:** *I have forgotten to include the CustomHooks component and the error has disappeared. Now the problem is the input values are not rendering in MyJobList component.*

**The issue**
In my React project, I'm getting `TypeError
(0 , _customhooks.default) is not a function` error when I pass the props to the components. It is possible that I am passing the data incorrectly, or perhaps I am missing some bits of codes.

Here are the codes (I have minimized the codes to highlight the main problem. You can view my full codes in the link below):

newlist.js
```js
const NewList = () => {
  const [inputState, setInputState] = useState({});
  const onSubmitList = () => {
    setInputState({
      positionTitle: `${inputs.positionTitle}`,
      companyName: `${inputs.companyName}`,
      jobLink: `${inputs.jobLink}`
    });
  };

  const { inputs, handleInputChange, handleSubmit } = CustomForm(onSubmitList);
```

myjoblist.js
```js
const MyJobList = inputs => (
  <div>
    <h3>{inputs.positionTitle}</h3>
    <p>{inputs.companyName}</p>
    <p>{inputs.jobLink}</p>
  </div>
);
```

navbar.js
```js
const Navbar = inputState => (
  <Router>
    <Switch>
      <Route path="/my-list">
        <MyJobList inputs={inputState} />
      </Route>
    </Switch>
  </Router>
);
```
**What do I expect?**
In the `NewList` component, I can create a new job list by entering the inputs and when I submit it, the input values should be rendered on the `MyJobList` component.

**What's actually happening?**
I am getting `TypeError
(0 , _customhooks.default) is not a function` error message on the web page and the console is pointing to the `NewList` component. In my local environment, I don't have this error, however, nothing is rendering when I submitted the input entry.

**Things I tried**
I tried to remove the object restructuring (curly braces, in other words) in the parameters. I also tried googling the problem but it does not lead me to the solution.

Any help and guidance provided are greatly appreciated!

Here's a link to complete code: [Code Sandbox](https://codesandbox.io/s/inputform-with-hooks-147xr?file=/src/navbar.js)
Examples of the power of Unit Testing
Published: 2020-07-04 06:34:12

---
title: Examples of the power of Unit Testing
published: true
description: 
tags: 
//cover_image: https://direct_url_to_image.jpg
---
I would love to hear your examples of times tests have improved your workflow. Even just simple but satisfying times that having good tests showed you that the effort was worth it.
Instagram flaw
Tags: security
Published: 2020-07-04 06:25:38

There is a security flaw in instagram in updating the email Id. Here is how you can exploit.
1. Create a instagram account, use your genuine email Id
1. Once the signup is complete, log off
1. Now go to instagram and say forgot password.
1. Instagram will send a mail to the email and in bottom there is a link to 'Remove your email from this account.'
1. Click on that link
1. Now your instagram account is delinked with the email address
1. Now again Try to log into account using your instagram Id, now provide the password.
1. In next screen you will be asked to provide the email Id to link.
1. In above step you can provide any email Id (if not used in instagram), there is no verfication required!!
Clojure 101 / threading macros
Tags: clojure, tutorial, functional
Published: 2020-07-04 05:55:55

When you have deeply nested functions or transformations, it might help you to consider a thread macro which helps the readability of your code.

#### `(-> x & forms)`

`->` is the thread-first macro. It evaluates one form and passes it as the first argument into the next form.

```clojure
;; these two are equivalent
(.toUpperCase (first ["chicken" "egg"]))
(-> ["chicken" "egg"] first .toUpperCase)

;; and so are these
(assoc {} :key 24)
(-> {} (assoc :key 24))
```

#### `(->> x & forms)`

`->>` is the thread-last macro. It evaluates one form and passes it as the last argument into the next form.

```clojure
;; these two are equivalent
(apply + (map (fn [x]
                (* x 2)) [1 2 3]))

(->> [1 2 3]
     (map (fn [x] (* x 2)))
     (apply +))

;; and so are these
(reduce +
     (filter even? [1 2 3 4]))

(->> [1 2 3 4]
     (filter even?)
     (reduce +))
```

Here is a dad joke in case you need a laugh:

> The spool of the thread asked the needle, "How you doing?" The needle replied, "sew sew."

I'm out.

Warmly,
DH
Bitcoins- Explain like I'm 5
Tags: webdev, react
Published: 2020-07-04 05:55:29

Its, not such a new term,but whenever in the parties this discussion came up, I used to feel like 
![bc-4](https://media3.giphy.com/media/hKNPxrffFH0GY/giphy.gif?cid=ecf05e4763e4576f3bb7041e7ec74af2667ac16e891b7b7c&rid=giphy.gif)

So, Here is the gist what I learnt from various blogs/videos in a most simplified manner. We all want to invest in a way to get high returns, this is said to be one of the risky but worthy options. First, let's know a few things.
![bc6](https://storage.pixteller.com/designs/designs-images/2020-07-04/08/anniversary-post-template-anniversary-1-5f001808b8691.png)

**What Is A Bitcoin?**
Bitcoin comes from the word "bit" smallest unit of data. We’re talking digital money, a form of currency that’s not backed by any raw material like gold or silver. It was released during the financial crisis in 2008 by Satoshi Nakamoto(said so)  

**What Is A Bitcoin Wallet?**
This is the very first step before you can use bitcoins ,  This is just like "Paypal/Paytm" wallets; digital form of our leather wallets. It has a unique Bitcoin address that keeps changing per transaction to add on the security.
  

**How To Get Bitcoins?**
1. Get or do Payments in bitcoins rather than conventional currency.
2. Purchase Bitcoins on Exchanges (yes! there are)

3. Bitcoin Mining: This is the toughest way to get them, solve complex mathematical problems using highly computable machines like ASIC (Application Specific Integrated Circuit) which are designed specifically for bitcoin mining operations. Generally, it takes a whole team to do the mining, after which they divide their share of rewarded bitcoins. WOW!
![bc-3](https://media2.giphy.com/media/kcfWl5KbrqLZVbFBoo/giphy.gif?cid=ecf05e47a6fae2eb73f676fd93e9d1d8fabc2a8ecbcee034&rid=giphy.gif)

**Price Of 1 Bitcoin Into USD/INR**
while I'm writing, it's 1 bitcoin = 9,089.58 $ or 678,432.18 INR.
![bc2](https://media3.giphy.com/media/QjrrSbYaqgi1q/giphy.gif?cid=ecf05e475ed06cc15903c689b99adca642e4e4de15ebc2a8&rid=giphy.gif)

**Drawbacks of Bitcoin**
First, Bitcoin fluctuates very high. Also, Bitcoin transactions are highly secured and can't be tracked thus highly used in the black market.

**How To Buy or Trade With Bitcoins?**
There are many websites that allow you to buy bitcoins in just minutes.
![bc1](https://user-images.githubusercontent.com/66199202/86505576-6e74d900-bd7b-11ea-9c27-7a9c86e1f286.png)


There are many platforms where you can buy or sell bitcoins just like stock markets utilizing the volatility of the market to sell in and out of trades by being sometimes investors, sometime trader.
YouTube Video | Create App using unsplash API in ReactJS — 3
Tags: react, webdev, showdev, youtube
Published: 2020-07-04 05:10:55

I had recently started my YouTube channel — The Web Dev. I had decided to start putting all my blogs into the YouTube channel.

We will create an web app from scratch using ReactJS, which will consume the Unsplash API. We can search for any image from unsplash.com and it will show them.

Here is the third part of the series.

{% youtube Wgdb4QxpfP4 %}

Please do like it and [Subscribe](https://www.youtube.com/channel/UCRf7mazcufqZxd2pR3oQJuQ?sub_confirmation=1) to my channel for more videos.

You can also read the complete blog here -

https://thewebdev.tech/image-search-unsplash-react-3
Clojure 101 / ! and ?
Tags: clojure, functional, tutorial
Published: 2020-07-04 04:49:11

One thing I really liked about working with Ruby was the fact that core methods sometimes had a `!` or a `?` in the end. The bang methods in Ruby, by convention, indicate that the method mutates the object. Methods that end with a question mark (boolean methods), also by convention, return a boolean.

I found both conventions to be super helpful in terms of readability. For example, a boolean method such as `empty?` reads like a question: "Hey is this thing empty?" Without a question mark, it could be confusing. Am I declaring that something is empty or asking if something is empty?

The bang operators in methods such as `downcase!` and `filter!` also help readability. You want those methods to run so forcefully that you want their effects to be permanent (mutating).

All of this is to say that I was pleasantly surprised that Clojure also adopted a similar naming convention.

```clojure
(contains? #{ :jets :eagles } :jets)
;; does the set contain :jets?

(even? 4)
;; is 4 even?

(empty? [100 400])
;; is [100 400] empty?
```

```clojure
(def player (atom {:score 0
                   :name "Charlie"}))
(swap! player update :score + 5)
;; increase player's score by 5
```

As you can see, the function names in Clojure are just as nice as those of Ruby's. The addition of `?` and `!` is the cherry on top. Speaking of cherry, I need to finish that Cherry Coke I had opened two hours ago...

Warmly,
DH
Clojure 101 / logical true or false
Tags: clojure, tutorial, functional
Published: 2020-07-04 04:05:43

A `falsy` value is a value that is considered false when encountered in a boolean context (i.e. if...else).

In JavaScript, there are 8 types of falsy values. This is from MDN.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/w4ddq28g5izapgxi0eav.png)

In Clojure, it's dead simple. Everything except `false` and `nil` is `true` in the boolean context. 

```clojure
(if nil
  "NIL IS TRUTHY"
  "NIL IS FALSY")

;; "NIL IS FALSY"
``` 

Isn't that nice? No more guess work :)

Warmly,
DH
How to Deploy a Flask app on Heroku.
Tags: tutorial, codenewbie, python, heroku
Published: 2020-07-04 03:51:17

{% youtube ozB-mU5P2Ps %}

Hello Friends, In this article I will show you how to deploy a flask app on Heroku. Follow the below steps to deploy your python flask app on Heroku.

**Prerequisite:**

1. You must have installed **Git** in your system.
2. You must have installed **Python** in your system.

**Step-1: Install Heroku CLI** 

```
% brew tap heroku/brew && brew install heroku
```
Above command is for Mac, for other systems you can [click here](https://devcenter.heroku.com/articles/heroku-cli)

**Step-2: Create Python Virtual Environment**

```
% python3 -m venv foldername
% source foldername/bin/activate
% cd foldername
```

**Step-3: Install Flask & Gunicorn**

```
% pip3 install flask gunicorn
```

**Step-4: Create an app folder and simple python app**

```
% mkdir app
% cd app
% vi main.py
```
**main.py**
```
from flask import Flask
app= Flask(__name__)
@app.route('/')
def index():
  return "<h1>Welcome to CodingX</h1>"
```

**Step-5: Create an entry point to the application, wsgi.py**
```
% cd ../
% vi wsgi.py
```
**wsgi.py**
```
from app.main import app
if __name__ == "__main__":
  app.run()
```
**Step-6: Run the application in your local system**

```
% python wsgi.py
```
**Step-7: Create requirements.txt and Procfile file**

```
% pip3 freeze
% pip3 freeze > requirements.txt
% vi Procfile
```
**Procfile**
```
web: gunicorn wsgi:app
```

**Step-8: Create an app in Heroku**

![Heroku new app](https://dev-to-uploads.s3.amazonaws.com/i/ilijs0rw1tjg567oxau8.png)

**Step-9: Deploy your app to heroku**

```
% heroku login
% git init
% heroku git:remote -a codingx-python
% git add.
% git commit -am "First python app"
% git push heroku master
```
**Step-10: Open your application on browser**

https://app-name.herokuapp.com


It's done!

Please Subscribe to my Youtube Channel https://youtube.com/c/codingx
Clojure 101 / operator precedence
Tags: clojure, tutorial, functional
Published: 2020-07-04 03:34:20

Surprise! I tricked you (😆). There is no operator precedence in Clojure because there are no operators - only functions and arguments.

All functions evaluate left to right and inside out. Function first, then args.

```clojure
(/ 1 2)
(/ 500 20)
(= "foo" "bar")
(not true)
```

Ok, that seems trivial. How about something more complicated?

```clojure
(defn leap-year? [year]
  (or
    (and
      (= (rem year 4) 0)
      (> (rem year 100) 0))
    (= (rem year 400) 0)))
```

I'm telling you this is such an underrated feature of using Clojure. I can focus on memorizing the important stuff - not horrendously lengthy precedence tables such as this:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/0qfk5jtbfn82tw3sy43c.png)

Now can you figure out what this does in JavaScript?

```js
3 > 2 && 2 > 1
```

Apparently, it returns `true`. I love you JavaScript, but we need a break... truly...

Warmly,
DH
Ravelry, high contrast & seizures
Tags: a11y, seizures, ravelry, wcag
Published: 2020-07-03 12:43:16

Recently Ravelry was rebranded and the website redesigned to suit their new brand. Apart from meeting Google Lighthouse scores, it appears that accessibility was not considered as core to the redesign.

The Ravelry community are speaking out against the lack of inclusive design decisions and some people have been experiencing seizures when using the website.

The seizures appear to be triggered as part of the high contrast redesign colours and patterns, as Countess Ablaze describes:
> "I suspect for me it was the glaring white, sensory overload of a lot of colours, flickering and high contrast black lines. I can't speculate anymore than this and now I've had one seizure (I've been seizure free since Nov 2018) I'm at higher risk for another."
https://www.countessablaze.com/blogs/news/seizure-warning-ravelry

I personally didn't know that high contrast ratios and patterns have the risk of causing physical reactions and seizures. As per [WCAG 2.3.1](https://www.w3.org/TR/WCAG21/#seizures-and-physical-reactions) I knew that flashing content was wrong, but not in the sense that colours could be perceived to be flickering without any flickering mechanism of the website.

Reading further on seizures and physical reactions from the [MDN docs](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Seizure_disorders), it's not just flashing animations, but patterns of light and dark straight lines. It gets quite mathametical and complicated! 

As part of our advice in building better websites, I think we need to be aware of the too-high contrast boundaries. We already know the minimum contrast ratios as per [WCAG success crition 1.4.3](https://www.w3.org/TR/WCAG21/#contrast-minimum), but I don't think the maximum contrast ratios are clear. Is it just that it's too subjective? Or is [success criterion 1.4.6](https://www.w3.org/TR/WCAG21/#contrast-enhanced) the gold-standard and maximum contrast ratio? Maybe these are too simple questions to solve a complex problem. 

Would anyone know of other reading material on the subject?

Diclaimer: I am not a Ravelry member, but I have been watching discussions in the accessibility community and I'm taking notes on how not to rebrand.
Exploratory Data Analysis With 2 Lines Of Python Pandas
Tags: machinelearning, datascience, python
Published: 2020-07-04 03:12:32

In this post, I will talk about how to do data analysis using Python Pandas. The purpose of this post is not to introduce Pandas. There is already ton of tutorials and wikis on Pandas. I would suggest following links If you want to learn about the basics of Python Pandas...

https://pandas.pydata.org/
https://www.nbshare.io/

This post is about introducing a Pandas package which would make the data analysis much faster. 

<h2>Requirements</h2>
1. Python 3.5+
2. Jupyter Notebook
3. Pandas-Profiling

For the example, I have downloaded the covid-19 US data from following github link...

https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-states.csv

Let us first read the above CSV and read in to our Pandas dataframe.
```python
import numpy as np
import pandas as pd
df = pd.read_csv('us-states.csv')
```
Now our data frame is ready. Let us now do some initial data analysis. Pandas has describe() function which gives us nice summary. But in this post, I will introduce Pandas library Pandas-Profiling which is kind of extension to describe() utility but with lot more data analysis and information with just one line of code. 
Note: Pandas-Profiling will work in the Jupyter-notebook, it will embed a interactive widget.
Let us import the Pandas-Profiling and run the exploratory analysis.
```python
from pandas_profiling import ProfileReport
profile = ProfileReport(df, title='Pandas Analysis', explorative=True)
profile.to_notebook_iframe()
```
Once you run the above code, you would see lot of information. Below is few of the snapshots that I have put together to give you a glimpse of output which you would see after running the above code.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/sndqltsku483jq1mcnj7.png)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/12sa3mextgg0jxd3bncy.png)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/732wyv9unla4pmufl1lb.png)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/l0oh0dne67x7atigwzq2.png)

Remember all the above snapshots are widgets and in your notebook, you would be able to interact and choose different options too. Before i wrap up this post, I want you to look at few more pandas packages which are excellent addons to have. 
https://nbshare-io.github.io/top-pandas-packages/
Kth Smallest Element in a BST, solving Netflix Interview question.
Tags: computerscience, tutorial, javascript, career
Published: 2020-07-04 03:01:25

Question: Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.

You may assume k is always valid, 1 ≤ k ≤ BST's total elements.

Eg : Input: root = [5,3,6,2,4,null,null,1], k = 3

```javascript
       5
      / \
     3   6
    / \
   2   4
  /
 1
```
Output: 3

Let's solve this. 

First, we need to traverse the tree, but how? 

Looking at the question we can see that it's a BST it a Binary Search Tree. 

A binary search tree has the following properties : 
1 > All the elements on the left subtree of a node have values less than the current node.
2 > All the elements on the right subtree of a node have values greater than the current node.
3 > Performing inorder traversal on a Binary search tree will result in a sorted list.

Since we want to find the kth Smallest node, performing inorder traversal on the tree would make sense since we will get a sorted list and it will be easier to determine the kth smallest element.

<h2>Inorder travesal Algorithm</h2> 
In Inorder traversal, we first process all nodes in left subtree of a node, then process the current node, then visit all the nodes in right subtree.

Visually : ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/cgm2xbvwhta3olpkzs5n.gif)

Let's work on the next part ie determining the kth smallest element, one way could be to store all the node values in an array and determine the kth smallest, another space-saving way will be to keep a counter, keep on increasing it, and when the counter hit's <strong>k</strong>, return the node value. 

Visually : ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/u760fddrlwrffsc0htmp.gif)

Converting coffee to code :

```javascript
var kthSmallest = function(root, k) {
    let val;
    function inorder(root){
        if(root == null) {
            return;
        }

        inorder(root.left);
        k--;
        
        if(k == 0) {
            val = root.val;
            return;
        }
        
        inorder(root.right);
    }
    inorder(root);
    return val;
};
```

If you've made it till here, comment on the expected time complexities in the best case, the average case, and worst-case scenarios.  

I hope you liked my explanation. If you know a better way then please share it with us :) 

Github : https://github.com/AKHILP96/Data-Structures-and-Algorithms/blob/master/problems/kthSmallestInaBST.js
Convert Charles Proxy log to Proxyman
Tags: proxyman, charles, ios, android
Published: 2020-07-04 02:59:24

---
title: Convert Charles Proxy log to Proxyman
published: true
description: Charles to Proxyman
tags: proxyman, charles, ios, android
//cover_image: https://direct_url_to_image.jpg
---

It's the mini blog on how to convert [Charles](https://www.charlesproxy.com) log (*.chls) to [Proxyman](https://proxyman.io).

It's a handy feature if you have a bunch of error log that you've already captured from Charles and would like to investigate or migrate to the Proxyman app.

## How it works
Fortunately, Charles has a built-in command that allows us to convert the CHLS file to the HAR format that Proxyman can understand. Thus, please make sure that you have this app on your machine.

FYI: We can manually convert by executing this command on Terminal
```
./Applications/Charles.app/Contents/MacOS/Charles convert ~/Desktop/input.chls ~/Desktop/output.har
```

## How to use
\1. Export Charles Session: We can export the current session in two ways:

- Right-click on the selected requests -> Export Session -> Select *.chls format -> Save
- or File menu -> Export Session as... -> Select *.chls format -> Save

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/uosmv3lnxs4eoagzqsqt.png)

\2. Drag and Drop to Proxyman app

You can drag and drop the file to Proxyman app

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/cehu1lsvzb8godr3b02n.png)

\3. At the first time you've used this feature, Proxyman would prompt the warning to make sure you're aware that Proxyman will use Charles to convert automatically.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/k03en8wg3brxpx5ufgvx.png)

If Charles app doesn't install on your Mac, Proxyman would prompt the alert.

\4. All done

At this step, Proxyman will find the default Charles app path and trigger the command to convert the file.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/sab21pfsvqueqj6oh6pv.png)

From here, we can:
- Repeat & Edit the request for testing
- Set rule for Map Local & Breakpoint

----------------------------
Proxyman is a high-performance macOS app, which enables developers to view HTTP/HTTPS requests from apps and domains on iOS devices, iOS Simulator, and Android devices.

Get it at https://proxyman.io