teleren/devto huggingface dataset:
SQL Learning notes
Tags: sql
Published: 2021-01-28 03:10:35

* `sys.tables`, `sys.columns`, add new column to a table after checking if it's existing cross 2 tables
```SQL
IF EXISTS (
		SELECT *
		FROM   sys.tables [Table]
		JOIN   sys.columns [Column]
			   ON [Column].object_id = [Table].object_id
		WHERE  [Table].[name] = 'Table1'
		AND    [Column].[name] = 'Column1'
) BEGIN
	ALTER TABLE Table1
	DROP COLUMN Column1
END

ALTER TABLE Table1
ADD Column1 nvarchar(max) NULL
```
`sys.tables` returns a row for each user table in SQL Server.

`sys.columns` returns a row for each column of an object that has columns, such as views or tables. (Object types that have columns: Table-valued assembly functions, Inline table-valued SQL functions, Internal tables, System tables, Table-valued SQL functions, User tables, Views.)
`object_id` - int - ID of the object to which this column belongs.

More reading: https://www.sisense.com/blog/sql-cheat-sheet-retrieving-column-description-sql-server/




* `COALESCE`
Evaluates the arguments in order and returns the current value of the first expression that initially doesn't evaluate to `NULL`. 
```SQL
SELECT COALESCE(NULL, NULL, 'third_value', 'fourth_value');
-- Above query returns the 3rd value because it is the first value isn't null
```




* SQL Operators 
 - Arithmetic operators: `+`, `-`, `*`, `/`, `%`
 - Bitwise operators: `&` (Bitwise AND), `|` (Bitwise OR), `^` (Bitwise exclusive OR)
 - Comparison operators: `=`, `>`, `<`, `>=`, `<=`, __`<>` (Not equal to)__




* `[]` : used to delimit identifiers.
From [MSDN](https://msdn.microsoft.com/en-us/library/ms175874.aspx):
 
> #### Delimited identifiers
> Are enclosed in double quotation marks (") or brackets ([ ]). Identifiers that comply with the rules for the format of identifiers may or may not be delimited.

> ```SQL
> SELECT *
> FROM [TableX]         --Delimiter is optional.
> WHERE [KeyCol] = 124  --Delimiter is optional.
> ```

> Identifiers that do not comply with all of the rules for identifiers must be delimited in a Transact-SQL statement.

> ```SQL
> SELECT *
> FROM [My Table]      --Identifier contains a space and uses a reserved keyword.
> WHERE [order] = 10   --Identifier is a reserved keyword.
> ```


* `GO`

> __`GO` will execute the related sql commands `n` times.__

> The GO command isn't a Transact-SQL statement, but a special command recognized by several MS utilities including SQL Server Management Studio code editor.

> The GO command is used to group SQL commands into batches which are sent to the server together. The commands included in the batch, that is, the set of commands since the last GO command or the start of the session, must be logically consistent. For example, you can't define a variable in one batch and then use it in another since the scope of the variable is limited to the batch in which it's defined.

For more information, see http://msdn.microsoft.com/en-us/library/ms188037.aspx.
More reading: https://stackoverflow.com/questions/2299249/what-is-the-use-of-go-in-sql-server-management-studio-transact-sql
Side-project launch preparation: What did I achieve in two days? [Day 2/7] 🛫
Tags: showdev, startup, productivity, beginners
Published: 2021-01-28 02:49:16

# Short intro

This is the second part of my full week researching how to launch a product:

[iplan.to](https://iplan.to), a simple habit tracker, that you can use for free!

![Screenshot_2021-01-27 iplan to Set a 30 day goal ](https://dev-to-uploads.s3.amazonaws.com/i/sbpbaxpvwnf74isgw4gh.png)

**Disclaimer: This is just some kind of journal, don't expect a tutorial.**

# Some numbers

I'm finishing the second day, and I have a few results:

**Time spent:**
⌚ 9 hours spent on marketing so far
⌚ 72 hours took developing the app

**Results by community**
✅ 1 post and 7 interactions on DEV
✅ 6 posts and 4 interactions on Makerlog
✅ 3 posts and 2 new followers on Twitter
✅ 2 entries waiting for approval on Indie Makers
✅ 5 posts and on Reddit 52 interactions

**Total results**
📈 155 new users in 2 days
🤝 3 people sharing feedback and interested in collaborating in a future

# Some reflections

Still lot of things to learn and work to do. It's taking more time than expecting, but I would say it's working (just need to be patient and consistent...)

Reddit seems to be the winner for now, followed by DEV. It's not enough info to make conclusions tho, just initial impressions.

# Next in the list

* Quora
* Linkedin (I forgot about this one yesterday)
* Write an article and see where to submit it

# More cool resources

📑 [Guestra](https://guestra.io/): a community of guest authors helping each other grow audience and build stronger SEO through content marketing collaborations.

📑 [whentolaunch.app](https://whentolaunch.app/insights): check historical data to know when to launch your app on Product Hunt.


# Thanks!

I would love to hear your feedback, let me know if you have any suggestions 🙂
Configure Jest in Nuxt.js
Tags: nuxt, vue, jest, testing
Published: 2021-01-28 02:19:52

---
title: Configure Jest in Nuxt.js
published: true
description: If you already have a project created with Nuxt but without Jest configured, I'll show you how to do it
tags: nuxt, vue, jest, testing
cover_image: https://images.unsplash.com/photo-1600267185296-f7dc4efe939c?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80
---
If you already have a project created with Nuxt but without Jest configured, I'll show you how to do it.

> 💡 My Nuxt.js version is `2.14.12`.

# Steps
1. Install dependencies
    ```zsh
    npm i -D @vue/test-utils babel-core@^7.0.0-bridge.0 babel-jest jest vue-jest
    ```

2. Add command `test` in `package.json`.
    ```json
    {
      //...
      "scripts": {
        //...
        "test": "jest"
      }
      //...
    }
    ```

3. Add file `jest.config.js` in root directory
    ```js
    module.exports = {
      moduleNameMapper: {
        '^@/(.*)$': '<rootDir>/$1',
        '^~/(.*)$': '<rootDir>/$1',
        '^vue$': 'vue/dist/vue.common.js',
      },
      moduleFileExtensions: ['js', 'vue', 'json'],
      transform: {
        '^.+\\.js$': 'babel-jest',
        '.*\\.(vue)$': 'vue-jest',
      },
      collectCoverage: true,
      collectCoverageFrom: [
        '<rootDir>/components/**/*.vue',
        '<rootDir>/pages/**/*.vue',
      ],
    }
    ```
4. Add file `.babelrc` in root directory
    ```json
    {
      "env": {
        "test": {
          "presets": [
            [
              "@babel/preset-env",
              {
                "targets": {
                  "node": "current"
                }
              }
            ]
          ]
        }
      }
    }
    ```
5. Create `test` directory in root directory
    ```zsh
    mkdir test
    ```

6. Write your first test of your component `/test/YourComponent.spec.js`

    ```js
    import { mount } from '@vue/test-utils'
    import YourComponent from '@/components/YourComponent'

    describe('YourComponent', () => {
      test('is a Vue instance', () => {
        const wrapper = mount(YourComponent)
        expect(wrapper.vm).toBeTruthy()
      })
    })
    ```
💡 I recommend you to read:
- [Vue Testing (optional)](https://vuejs.org/v2/guide/testing.html)
- [Vue Test Utils (important)](https://vue-test-utils.vuejs.org/)


### Thank you for readme! see you soon 😉
Trading Bot Concurrent Markets
Tags: bitcoin, automatedtrading, coinbasepro, tradingbot
Published: 2021-01-31 07:23:03

---
title: Trading Bot Concurrent Markets
published: true
date: 2021-01-28 02:04:08 UTC
tags: bitcoin,automatedtrading,coinbasepro,tradingbot
canonical_url: https://medium.com/coinmonks/trading-bot-concurrent-markets-d19289bb9236
---

[![](https://cdn-images-1.medium.com/max/1280/1*mHka-pHO7RKO9pf7P88ybA.jpeg)](https://medium.com/coinmonks/trading-bot-concurrent-markets-d19289bb9236?source=rss----721b17443fd5---4)

Bitcoin, Bitcoin Cash, Ethereum, and Litecoin

[Continue reading on Coinmonks »](https://medium.com/coinmonks/trading-bot-concurrent-markets-d19289bb9236?source=rss----721b17443fd5---4)
Low Cost/Free Learning and Tools for Up and Coming Web Developers
Tags: webdev, learning, html, css
Published: 2021-01-28 02:03:51

---

**_Money._** It's something we all wish we had more of lying around. However, if you're not born into a wealthy family or you, oh I don't know, get incredibly lucky and hit the lottery, chances are you're living paycheck to paycheck. Whether it be more cash in your wallet or more money in the bank, we could all use a little extra moola hanging around. I know for a fact as  single free resource available to me and then some.</br>
</br>
So how does this relate to Web Development? When I very first made the decision to pursue Web Development it was back in August 2017. I was working a dead end retail job at a certain 3 lettered pharmacy chain, and was super unhappy with not only the job but the pay. So I applied for a scholarship to take the Intro to Programming nanodegree at Udacity, and somewhat surprisingly to me, got accepted. But let's be honest, if I didn't get that scholarship I would have never been able to do it. If it weren't for accessible resources, I would still be wandering around in retail purgatory.</br>
</br>
There are 3 main ways that developers learn to code. Some people go to college and major in Information Systems or Computer Science. If it weren't for my admittedly awful aptitude for math beyond College Algebra, maybe I would have majored in Computer Science while in college. There's also bootcamps, like Flatiron and Lambda but even with ISAs (Income Share Agreements) you don't pay anything while you're going through the bootcamp, but you end up paying for tuition 1 1/2 times over afterwards. The cheapest option (and the one I chose) is self-teaching. The barrier to enrollment in college and bootcamps can be too high for low-income individuals. In comparison, self-teaching can be accomplished with few resources and little to no money. There's books, YouTube videos, udemy courses, local communities, and more. Below I'll go over some of my favorite resources I've found useful in my own programming journey.</br>
</br>
**The best books I've found helpful for Web Development**
HTML & CSS: Design and Build Websites by Jon Duckett ($13.79)
Javascript & JQuery: Interactive Front-End Web Development by Jon Duckett ($22.99)
The Road to React: Your journey to master plain yet pragmatic React.js by Robin Wieruch ($27.65)
Python Crash Course, 2nd Edition: A Hands-On, Project-Based Introduction to Programming by Eric Matthes ($17.00)

**Some of the YouTube videos I've found helpful**
1. HTML/CSS/JS Crash Course by Colt Steele (Parts 1–4):
Part 1: https://www.youtube.com/watch?v=O9Uauq-Gd0c
Part 2: https://www.youtube.com/watch?v=d5HnAlAFt40
Part 3: https://www.youtube.com/watch?v=SkuHUUyCKIw
Part 4: https://www.youtube.com/watch?v=5OCrKVNqCcs

2. Full Stack Web Development Tutorial Course by WB Web Development Solutions (This one is a whole playlist containing 132 total videos)
Entire Playlist: https://www.youtube.com/playlist?list=PLwoh6bBAszPrES-EOajos_E9gvRbL27wz
Restructuring my learning
Published: 2021-01-28 01:30:21

I took advantage of some down time at work today to think about the trajectory and formatting of my learning thus far. I do like where it's going, and I think I have made some decent progress, but I've been floundering a bit recently.

My solution to this is to experiment with being more structured with my learning. On work days:

1hr Python Bootcamp
1hr A Cloud Guru AWS
30-60 mins flex time to continue/revisit either learning path, dependent on motivation, time, etc.

On my weekends (currently Monday & Tuesday):

+30-60 minutes for Python and AWS
+60-90 minutes for some sort of side project (Cloud Challenge, refactoring code I've written, etc.)

Being this structured is perhaps ambitious, but I think it will serve to keep me motivated and on-task a little more often, while still giving me a little bit of time to unwind each day.

I'll start this schedule tonight. Let's see how this goes!
Python Virtual Environment 101
Tags: python
Published: 2021-01-28 01:22:38

## Why do we care?

In any programming language, you'll inevitably be using code made by other people to make your life easier. These 3rd party chunks of code are referred to as packages, libraries, and frameworks. This brings two challenges...

- There needs to be an easy way to get these packages and use them in my code

- There needs to be a mechanism for me to replicate the setup I have on one computer on another

This is where the all might Package Manager comes in. In the world of Python programming that package manager is known as Pip. 

- Simply by running a ```pip install``` command can I install a python library or framework then use it in my code

- Standard practice is to output the results of ```pip freeze``` to a file called requirements.txt then I can re-download on another pc easily by running ```pip install -r requirements.txt```

## So what's the problem?

Well, pip freeze lists all libraries you've installed and doesn't know which packages below to which projects, or whether they need different versions. So if we just install requirements.txt we may be installing a lot of things we used for other projects when all I need is a subset for a particular project.

## The Solution?

In python, you create a virtual environment. A virtual environment essentially is an isolated copy of python and pip, so when working in the virtual environment the packages you installed are tracked separately so the results of pip freeze will be unique to that environment/project.

## How do we create a virtual environment?

There are two main tools for creating virtual environments

- Pyenv with Pyenv-Virtualenv extension

- virtualenv with virtualenvwrapper (the wrapper gives you super useful commands)

Although, this can be made much easier by using the IDE Pycharm which can build environments for you with your preferred tool making it easy to manage. Although below I'll cover the commands for both if you rather use a different IDE like VSCode or Atom.

## Creating a new virtual environment

**PYENV**

``` pyenv virtualenv <pythonversion> <envname> ```

``` pyenv virtualenv 3.9.0 djangoproject ```

**Virtualenv/VirtualenvWrapper**

``` mkvirtualenv <envname> ```

``` mkvirtualenv djangoproject ```

## Turn on an existing virtual environment

**PYENV**

``` pyenv activate <envname> ```

``` pyenv activate djangoproject ```

**Virtualenv/VirtualenvWrapper**

``` workon <envname> ```

``` workon djangoproject ```

## Turn off an existing virtual environment

**PYENV**

``` deactivate  ```

``` deactivate  ```

**Virtualenv/VirtualenvWrapper**

``` deactivate  ```

``` deactivate  ```

## See a list of existing environments

**PYENV**

```pyenv virtualenvs```

**Virtualenv/VirtualenvWrapper**

``` lsvirtualenv ```

## Removing a VirtualEnv

**PYENV**

```pyenv uninstall <envname>```

**Virtualenv/VirtualenvWrapper**

``` rmvirtualenv ```


## Conclusion

I know when I started with python, Virtual Environments and why they mattered didn't quite make sense to me, so hopefully, this has helped fill in the blanks for you!
[NextJS] smooth routing when SSR 
Tags: nextjs, react, webdev, node
Published: 2021-01-28 00:58:15

## heavy SSR makes TTFB longer

In NextJS, the heavy `getServerSideProps` method freeze user transition. For example, If sleep 5sec in `getServerSideProps`, the user need wait 5 sec after clicking a link.

```tsx
import Link from "next/link";

export default () => {
  return <Link href="about">heavy about</Link>;
};
```

```tsx
export default (props) => {
  return <div>this is about page: {props.id}</div>;
};

export async function getServerSideProps(context) {
  await sleepByPromise(5);
  return {
    props: { id: 1 }, // will be passed to the page component as props
  };
}

function sleepByPromise(sec) {
  return new Promise((resolve) => setTimeout(resolve, sec * 1000));
}
```

[Here](https://next-js-routing-inidicator-git-feature-badux.toybox2.vercel.app/) is bad UX demo. You should wait 5 sec after clicking a link. This will be bad experience for user.

## solution: use router.change

NextJS has a `Router.event('eventName', ()=>{})` method. This method can handle events of routing change. Especially `"routeChangeStart"` can handle the start point of change routing. Then if you toggle state which manages to show loading or not, you can show loader.

```tsx
import Link from "next/link";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";

export default () => {
  const [isLoading, setLoadingState] = useState(false);
  const router = useRouter();
  useEffect(() => {
    router.events.on("routeChangeStart", (url) => {
      setLoadingState(true);
    });
  }, []);
  return isLoading ? (
    <div
      style={{
        background: "rgba(0,0,0,0.8)",
        color: "white",
        display: "flex",
        justifyContent: "center",
        alignItems: "center",
        fontSize: 32,
        position: "fixed",
        top: 0,
        left: 0,
        width: "100vw",
        height: "100vh",
      }}
    >
      <marquee>loading</marquee>
    </div>
  ) : (
    <Link href="about">heavy about</Link>
  );
};
```

![loading](https://dev-to-uploads.s3.amazonaws.com/i/r0kaedmzvl3kpcfzwis5.gif)

here is [demo](https://next-js-routing-inidicator.vercel.app/).

## soure code 

https://github.com/ojisan-toybox/next-js-routing-inidicator
How to upgrade CDK to latest version
Tags: aws, cdk, iac
Published: 2021-01-28 00:45:15

**CDK is updating all the time**. Which is great, the tool is expanding, gaining more features. Take a look of the timestamps in their [GitHub releases page](https://github.com/aws/aws-cdk/releases). I wonder if [Matt Coulter](https://twitter.com/nideveloper) find a single weekend to chill.

I once made a quick Proof of Concept and after two days, I updated my current installed version and my PoC simply stopped work. Good grief is all remote these days. And for new projects I always want to use the latest stable version in the docs – but I also get:

![Upgrade recommended](https://dev-to-uploads.s3.amazonaws.com/i/xnbsgt7nrpwfbfexdqsa.png)

And somehow I forgot again and _again_ the command. After tried the usual suspects `cdk upgrade`, `cdk update` or `cdk --upgrade`, I had to research again. One. More. Time. I'm writing to help me remember.

The command to upgrade your CDK version is:

```bash
npm install -g aws-cdk@latest
```

Or if you are a Yarn folk:

```bash
yarn global upgrade aws-cdk
```
--------

**#AWSWhishlist**: Your buddy **Amplify CLI** has a `amplify upgrade` 👀 ... Your move.

---------
<span>Cover photo by <a href="https://unsplash.com/@thejmoore?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Jon Moore</a> on <a href="https://unsplash.com/s/photos/constructs?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a>. I searched for _contructs_ and this was the best I could find.</span>
Data Science or AI would be a better choice for a Master’s Degree
Tags: news, programming, artificialintelligen, datascience
Published: 2021-02-03 18:59:58

---
title: Data Science or AI would be a better choice for a Master’s Degree
published: true
date: 2021-01-28 00:30:00 UTC
tags: News,Programming,artificialintelligen,datascience
canonical_url: https://centocode.com/data-science-or-ai-would-be-a-better-choice-for-a-masters-degree/
---

Artificial Intelligence and data science both have emerged as a popular carrier choice. Not only do they are aspirant for large scale automation,

The post [Data Science or AI would be a better choice for a Master’s Degree](https://centocode.com/data-science-or-ai-would-be-a-better-choice-for-a-masters-degree/) appeared first on [CentoCode.com](https://centocode.com).
Day 296 : All The Time
Tags: hiphop, code, coding, lifelongdev
Published: 2021-01-28 00:20:50

_liner notes_:
- Professional : Whew what a day! Got up early so I could go through my presentation to make sure everything works like it should. Ran into a little snag, but got it working. Then we had our team meeting with a bunch of presentations. A lot of good info. Then right after that I had my presentation for a meetup in London. Everything was going great, then I realized I wasn't recording the audio. Started recording and that kind of threw me off. haha I make this mistake all the time. I meant to scroll horizontally but accidentally trigger a go to previous page action on Mac. So I basically exited out of my presentation. haha. The attendees seemed to like it, got a lot of thanks and some really good questions. People seemed pretty interested in Web Components. That's all I could ask for. Now, I'm trying to work out the audio issue.

- Personal : Basically spent last night fine tuning my slides and presentation. Went through a couple of tracks for this week's radio show. Then fell asleep.

![View of the green mountain tops of Brecon, United Kingdom at sunset](https://dev-to-uploads.s3.amazonaws.com/i/cdavfwypzsp2ded5nuuz.jpg)

Since the meetup, I've been trying to figure out this audio issue I'm running into with the recording. Luckily, the meetup organizer was live streaming to YouTube and I was able to get the audio I forgot to record. Joined the sections and uploaded. Great. Now I'm having an issue with lining up the audio with the speech recognition and slide triggers I recorded during the talk. I'll figure it out at some point. After that, going to work on the radio show.

Have a great night!

peace piece
Dwane / conshus
https://dwane.io / https://HIPHOPandCODE.com
{% youtube 8t2H1Ke4MXE %}
How to Check a File or Directory Exists in Python
Tags: python, basics
Published: 2021-04-07 12:58:29

---
title: How to Check a File or Directory Exists in Python
published: true
date: 2021-01-28 00:00:00 UTC
tags: python, basics
canonical_url: https://tech.serhatteker.com/post/2021-01/how-to-check-a-file-or-dir-exists-in-python/
---

If it doesn't matter it is a file or directory you can use `os.path.exists()`:

```python
# check_exists.py
import os

file = "/home/user/tmp/file"
dir = "/home/user/tmp/dir"

if __name__ == "__main__":
    print("File exists: ", os.path.exists(file))
    print("Dir exists: ", os.path.exists(dir))
```

__NOTE__:

> I'm using **if \_\_name\_\_ == "\_\_main\_\_"** notation. If you want to see more
information about this look this article: [**What does if name \_\_name\_\_ == "\_\_main\_\_" do in Python**](https://tech.serhatteker.com/post/2019-12/what-does-if-name-main-do/)


When you run the file you will see similiar output like below:

```bash
$ python check_exists.py

File exists: True
Dir exists: True
```

You may be a little bit confused, since In Unix-like systems — MacOs and Linux,script files don't have to need file extensions like `file.sh` or `file.py`. All you need is a [shebang] — `#!`. For instance this is the content of **/home/user/tmp/file**:

```bash
# /home/user/tmp/file
#!/bin/bash

# make a tmp/ dir at $HOME if not exists with verbose input
mkdir -pv ~/tmp
```

__NOTE__:

Using **~/** alias like **~/tmp/dir** doesn't work. You need to give absolute
path or expand the alias: **os.path.expanduser('~/tmp/file')**


## File

If you want to check a file exists and got *file type*:

```python
# check_file_exists.py
import os

file = "/home/user/tmp/file"

if __name__ == "__main__":
    print("File exists AND a file: ", os.path.isfile(file))
```

## Directory

You can check directory with `os.path.isdir` function:

```python
# check_dir_exists.py
import os

dir = "/home/user/tmp/dir"

if __name__ == "__main__":
    print("Dir exists AND a directory: ", os.path.isdir(dir))
```

## Bonus:Create If Not Exists

Also if you want to create one if this doesn't exist:

```python
# check_exists_or_create.py
import os

file = "/home/user/tmp/file"
dir = "/home/user/tmp/dir"

if __name__ == "__main__":
    # create dir if not exists
    if not os.path.isdir(dir):
        os.mkdir(dir)

    # create file if not exists
    if not os.path.isfile(file):
        open(file, 'w').close()

    # alternative to create file if not exists
    from pathlib import Path
    Path(file).touch()
```




All done!

[shebang]: https://en.wikipedia.org/wiki/Shebang_(Unix)