teleren/devto huggingface dataset:
Logging with Python
Tags: python, log
Published: 2019-07-05 12:52:57

---
title: Logging with Python
published: true
description: python, log
tags: python, log
---
<img src="https://proxy.duckduckgo.com/iu/?u=https%3A%2F%2Fmetvcdn.metv.com%2F1JMWa-1461171702-3463-list_items-computers_voyage.gif&f=1">

Blinking lights don't really help for solving problems. What does each light mean? In case of error, you can not find the bug that way. 

Logging helps to debug your program if something goes wrong. More data means you can analyze better.

### Log with Python

Python comes with the `logging` module. You can write a log message like this:
 
    logger.info("Hello World printed")

The simple program below logs to a file. The log file can then be used for analysis.

    #!/usr/bin/python3
    import logging
    
    logging.basicConfig(level=logging.INFO, 
                        filename='my_app.log', # log to this file
                        format='%(asctime)s [INFO] %(message)s') # include timestamp
    
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)

    def main():
        logger.info("Program started")
        print("Hello World")
        logger.info("Hello World printed")
        logger.info("Program finished")
    
    main()

<img src="https://proxy.duckduckgo.com/iu/?u=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Ft4aBVelzr49qw%2F200.gif&f=1">

### formatting

By default the logger module does not include the time. Time helps to find your bugs as you can see when things happened.

The log file then contains something like this:

    2019-07-05 14:44:02,052 [INFO] Program started
    2019-07-05 14:44:02,053 [INFO] Hello World printed
    2019-07-05 14:44:02,053 [INFO] Program finished

One of the first lines formats the log messages, in case you want to change that:

    #!/usr/bin/python3
    logging.basicConfig(level=logging.INFO, 
                        filename='my_app.log', # log to this file
                        format='%(asctime)s [INFO] %(message)s') 

Learn Python:
* https://pythonbasics.org
* https://pythonprogramminglanguage.com
* https://python.org
React tldr; React Native 0.60
Tags: reactnative, react, android, ios
Published: 2019-07-05 12:38:37

- Many improvements to the accessibility APIs

- React Native's start screen has been updated

- React Native has been migrated over to AndroidX

- CocoaPods are now part of React Native's iOS project

- WebView and NetInfo are out of the React Native repository

- "Upgrade Helper" is a new toool to make the upgrade process simpler

- No more manual library linking thanks to "autolinking"

Source: https://facebook.github.io/react-native/blog/2019/07/03/version-60
While (!cantNoMore){ ride() } 🤠🐴
Tags: jokes
Published: 2019-07-05 12:22:16

```js
let cantNoMore = false

function ride () {
  console.log("take my horse to the old town road")
  console.log("ride")
  cantNoMore = true
}

while (!cantNoMore) {
  ride()
}

const horses = {
  location: "back",
  tack: "attached"
}

const me = {
  hat: "matte black",
  boots: "black to match",
  ridingOn: "horse"
}

const you = {
  whip: "Porsche",
  beenOfPorch: false
}

const cantTellMe = null

me.life = "movie"
me.cowboyHat = "Gucci"
me.booty = "Wrangler"

cantNoMore = false

while (!cantNoMore) {
  ride()
}

const BillyRay = {
  living: "like a rockstar",
  spentMoneyOn: "brand new guitar",
  stress: false,
  like: "Marlboro man"
}

cantNoMore = false

while (!cantNoMore) {
  ride()
}
```

I don't have a soundcloud but plz subscribe 2 this new tag.

{% tag jokes %}
Virtual environments in Python
Tags: python
Published: 2019-07-05 12:10:45

---
title: Virtual environments in Python
published: true
description: python
tags: python
---
<img src="https://proxy.duckduckgo.com/iu/?u=http%3A%2F%2Fimages5.fanpop.com%2Fimage%2Fphotos%2F30500000%2FPandora-s-Box-silent-movies-30540095-500-340.gif&f=1">

Python **installs modules system wide**. This is unlike other programming languages where you need to import modules.

System wide installs of modules can create conflicts, you want **virtual environments**.

### on Ubuntu Linux

Setup virtual environment
On Ubuntu 18.x:

    sudo apt-get install python3-venv

On other systems, you need another command to install. It's highly likely its installed by default on Mac and Windows.


### Create Virtual Environment

Create Virtual Environment in the command line.
To create a new virtual environment:

    python3.6 -m venv test

or

    pyvenv test


### Activate Virtual Environment

After creation, you need to activate virtual environment.
To activate the virutal environment

    cd venv
    source bin/activate

Then modules are only installed in the virtual environment, not conflicting with other python programs.

Learn Python
* https://pythonbasics.org
* https://pythonprogramminglanguage.com
* https://python.org
Discontinued Mobile Browsers
Tags: tutorials
Published: 2019-07-06 15:12:21

---
title: Discontinued Mobile Browsers
published: true
tags: Tutorials
canonical_url: https://vuild.com/discontinued-mbrowsers
---

As people increasingly move towards an almost exclusively mobile experience online, the [list of mobile browsers](https://dev.to/vuild/giant-list-of-mobile-browsers-57kl-temp-slug-6426290) will continue to expand. As will our upbeat graveyard for mobile browsers. This page may be short now, but as the mobile browser wars start to heat up we expect to watch this list grow too.

[Download as PDF](https://vuild.com/discontinued-mbrowsers?pdf=1)
1. Deepfish
2. IE Mobile
3. Iris
4. Mercury
5. MicroB
6. Skweezer
7. Steel
8. Teashark
9. Xpress Browser
Let us know if we missed any dead mobile browsers.

This data is from [Vuild’s discontinued mobile browsers list](https://vuild.com/discontinued-mbrowsers). Please visit [vuild.com](https://vuild.com) for more.
Do you need to understand Machine Learning?
Tags: discuss, machinelearning, deeplearning
Published: 2019-07-05 11:50:32

While most programmers are able to utilize a simple machine learning or deep learning library/module ([scikit-learn](https://scikit-learn.org/) for instance) in their code, many are unaware of how these libraries work behind the scenes, why do they work etc.

It is clear that if a software developer wanted to pursue a career in Data Science he would need to study the algorithms and models (and relevant math).
But, what about the average programmer that *occasionally* needs to implement face recognition/dog detection/you name it in his web app?

Do you think that he needs to **understand** the models he uses, and if so, to what extent? Or just understanding the outputs of the algorithms is good enough?
freeCodeCamp's Drum Machine project built in Elm
Tags: elm, freecodecamp, webdev
Published: 2019-07-05 11:41:14

---
title: freeCodeCamp's Drum Machine project built in Elm
published: true
description: 
tags: elm, freecodecamp, webdev
cover_image: https://thepracticaldev.s3.amazonaws.com/i/wxxhpus4hwdkh7k5x8mo.png
---

This [Drum Machine](https://learn.freecodecamp.org/front-end-libraries/front-end-libraries-projects/build-a-drum-machine/) project was a satisfying one to complete.

At times I doubted whether or not I would get everything to work the way I wanted. But in the end it all worked out and the project came together  quite nicely.

Here's my [demo](https://dwayne.github.io/elm-drum-machine/) and the [source code](https://github.com/dwayne/elm-drum-machine).

Whether you choose to just read the code or to build the project you will learn the following:

1. How to [play audio](https://github.com/dwayne/elm-drum-machine/blob/1c17d9f41af5a4f56b5817f0e05f520f3579c3da/src/Main.elm#L138).
2. How to write a [custom decoder](https://github.com/dwayne/elm-drum-machine/blob/1c17d9f41af5a4f56b5817f0e05f520f3579c3da/src/Main.elm#L179) for key up and down events.
3. How to use [Process.sleep](https://package.elm-lang.org/packages/elm/core/1.0.2/Process#sleep) to do the equivalent of JavaScript's `setTimeout`.
4. How make Elm output special HTML characters like [non-breaking space](https://github.com/dwayne/elm-drum-machine/blob/1c17d9f41af5a4f56b5817f0e05f520f3579c3da/src/Main.elm#L283).

I challenge you to build something, anything, in Elm. It's the best way to learn the language.
React & Meteor Developer
Tags: node, meteor, react, javascript
Published: 2019-07-05 11:27:51

We're looking for a developer with heaps of experience in React, Node (Meteor) and MongoDB. To help us build new features and fix bugs.

For more information and to apply please visit: https://www.plutio.com/careers

Plutio is an all-in-one business management platform designed for freelancers and small businesses. Everything you need from projects and tasks to proposals and invoicing, all in one intuitive and deeply customizable platform. No more multiple subscriptions and juggling between apps.

The business is powered by freelancers from all around the world, not employees. We don't follow the conventional 9-to-5 office routine. You choose how you want to work as long as the work gets done, we're easy to please.
Your API Sucks – The ‘default’ API : REST and repeat
Tags: development, api, code, ux
Published: 2019-07-05 10:18:04

---
title: Your API Sucks – The ‘default’ API : REST and repeat
published: true
series: your-api-sucks
tags: development,api,code,ux
canonical_url: https://craignicol.wordpress.com/2019/07/05/your-api-sucks-the-default-api-rest-and-repeat/
---

I’ve recently got a Fitbit, and I use the website for logging food. I noticed something about the URL scheme that I’ve seen elsewhere and it made me think about how to design default points in URL schemes.

On Fitbit, ‘/foods/log’ opens the page for today’s food, and there are controls to navigate to yesterday and beyond, when the URL changes to ‘/foods/log/{date}’. So far, so simple. But when I navigate back to today, the URL still contains the date. My browser is set to reload pages from last time, so the first URL always gives me today. The second, doesn’t.

Should we set defaults that can change based on context? Or should the default redirect to the appropriate context? Or should we always be explicit? Should default URLs automatically redirect?

If I load the page before midnight but submit after, the screen and the URL indicate different dates. What is the right date?

UPDATE: The new Fitbit logging page, which appears occasionally at `/foods/log` takes the date as an explicit parameter (it’s a drop-down on the page), so no longer has a default. This is a much better strategy for submitting data
The keys to giving IAM users access to AWS C9
Tags: cloudide
Published: 2019-07-05 12:55:00

---
title: The keys to giving IAM users access to AWS C9
published: true
tags: Cloud IDE,cloud IDE
canonical_url: https://kevinhq.com/the-keys-to-giving-iam-users-access-to-aws-c9/
---

This is my story when I need to give IAM users on same AWS account, access to open and work on existing AWS Cloud9 workspace. The AWS docs did provide the detailed guides to do this.  However, when I had created the IAM user I needed, and I had attached it to a Group, and… 

[Read More »The keys to giving IAM users access to AWS C9](https://kevinhq.com/the-keys-to-giving-iam-users-access-to-aws-c9/)
Python Unit Testing
Tags: python
Published: 2019-07-05 11:06:20

---
title: Python Unit Testing
published: true
description: python
tags: python
---
<img src="https://media.giphy.com/media/26u6bnal23NhnIoZG/giphy.gif">

Coders write much code. How do you know that code does what it's supposed to do?

One way is to do "unit tests". A unit test tests a method and tests if the inputs matches the outputs.

## Unit Test with Python

Hockey dockey professori. Want to see that in Python?

Start with a simple program:

    #!/usr/bin/python3
    # program.py
    def inc_by_one(x):
        return x + 1

Then test that with the unittest module (test.py).

    #!/usr/bin/python3
    import unittest
    import program
    
    class MyModuleTest(unittest.TestCase):
    
        def test_inc_by_one(self):
            assert(program.inc_by_one(2) == 3)
    
    if __name__ == '__main__':
        unittest.main()

<img src="https://proxy.duckduckgo.com/iu/?u=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fgw3IWyGkC0rsazTi%2F200.gif&f=1">

Pay attention to this line:

            assert(program.inc_by_one(2) == 3)

It tests if the input (2) matches the output (3).

If you run the program the test will be run:

    .
      ------------------r----------------------------------------------------
    Ran 1 test in 0.000s
    
    OK

Holy ravioli, the test passed!

Learn Python:

* https://pythonbasics.org
* https://pythonprogramminglanguage.com/
* https://python.org
Traveler's Style Guide

Tags: shirtingfabric, shirtfabric
Published: 2019-07-05 10:58:55

Vagabond and clueless? Sure are you likely to reach them although enough the hills are calling? Fitness is here to remain. This isn't a fad but a lifetime calling. It's a force that can't be tamed or controlled and here we'll help you out.
Look fab with cool travel shirts and buy best <a href="https://www.bombayshirts.com/how-to-select-a-custom-shirt-fabric">shirt fabric</a> at Bombay Shirt Company.
Trekking or hiking or finding the Gorgeous wild Isn't a kid's play. It entails several nights in which you rough out it morning sunlight with hard earned gorgeous and breakfasts sights in the price of hygiene. This lifestyle is paired with the design that was perfect. This guide will provide you a helping hand not merely function as component but also to look the part!

Here's a head to toe experience style manual.
You can't carry new set of trousers for every day and expect them to be washed clean with every speck of dust you run into. We start with the pair of denims. It goes without saying that you need a pair of jeans. Dark wash jeans may seem. The'filthy' will be 'effortless' in shadowy denims. Black or blue? That is up for you. Decide on a pair that lived in's comfy and contains pockets that are !
The top will trust the weather condition of your experience. But a soul will not hurt. Ensure that you carry the coat that is perfect. It ought to have a great deal. . A great deal and did we say. . A whole lot of pockets? Suggestion -- Your coat should fit your own boots.

Which brings us boots! What is an experience without the pair of boots? Cozy and demanding. The pair does not disappoint you and suits you and tear come rain come shine. Since it is a life investment It'll be perfect to invest in a set! And you may be abandoned by boots ! Suggestion -- Use boots with laces. You want your feet remain occasionally and to breathe occasionally. Laces are helpful.
The ideal attire is incomplete without the perfect watch and belt.You desire a belt which will not hurt or workout from extreme weather. Keep it casual with a belt. Watch ought to be standard. One which remain tight or will not crack simple. As leather can tear out metal watch is going to be favored but it will return to your comfort. Some men choose to carry pocket watches to maintain the wrist apparent.

An ideal tote is going to be two shoulder strap. For shorter excursion, nevertheless, messenger bags with approximately 25 pockets (exaggeration, if you don't find one that really has 25 pockets) should do. Prefer to take all time tote along. Take a pencil on you constantly. A ball point a journal and pen. Mobiles give up along with no power is needed by the journal !
Threads with Python
Tags: python
Published: 2019-07-05 10:51:37

---
title: Threads with Python
published: true
description: python
tags: python
---
<img src="https://media1.tenor.com/images/fbc7738df493bb67d902d714a420746e/tenor.gif">

A Thread is the smallest unit that can be scheduled in an operating system.  In practice, threading is used when multiple things need to happen "at the same time".

For instance, while you click "download" in your web browser, you should be able to continue surfing the web while its download. It needs to happen "at the same time".

In reality computers use a scheduler, that give a tiny amount of time to each thread.

### Python Threads

Can you use threads with Python? Yes, please!
To create a thread in Python

    #!/usr/bin/python3
    # threading example, https://pythonbasics.org/
    import threading
    
    # function that prints hello world and current thread
    def task():
        print("Hello World: {}".format(threading.current_thread()))
    
    # create a thread and start it
    thread1 = threading.Thread(target=task)
    thread1.start()

Because the thread finishes immediately, it only shows "Hello world". You can put a loop in a thread, to create "parallel running processes".

    #!/usr/bin/python3
    # threading example, https://pythonbasics.org/

    import threading
    import time
    
    # function that prints hello world and current thread
    def task():
        for i in range(0,10):
            print(" thread " + format(threading.current_thread()), end=''),
            print(" = " + str(i))
            time.sleep(1)
    
    # create a thread and start it
    thread1 = threading.Thread(target=task)
    thread1.start()
    
    # create a thread and start it
    thread2 = threading.Thread(target=task)
    thread2.start()

This then runs *thread1* and *thread2* at seemingly the same time. Both threads only count upwards.

    thread <Thread(Thread-1, started 140453722031872)> = 0
    thread <Thread(Thread-2, started 140453713639168)> = 0
    thread <Thread(Thread-1, started 140453722031872)> = 1
    thread <Thread(Thread-2, started 140453713639168)> = 1
    thread <Thread(Thread-1, started 140453722031872)> = 2
    thread <Thread(Thread-2, started 140453713639168)> = 2
    ...

Threads can be waiting for each other and block indefinitely. That is named a dead lock

<img src="https://media.giphy.com/media/z4mhcGKzg1fb2/giphy.gif">

Learn Python:

* https://pythonbasics.org
* https://pythonprogramminglanguage.com/
* https://python.org
OverTheWire Bandit Level 1 Level 2 walk-through
Tags: security, infosec, ctf, beginners
Published: 2019-07-05 09:10:54

Challenge page => https://overthewire.org/wargames/bandit/bandit2.html

This challenge also involves reading a file to get the password, but it has a tricky file name. 

***

**Hint 1**: Your `cat` command did not work, did it? :D It's ok. That's what this challenge is about.

Technically the cat command is working fine. As for why it did not read the file "-", once again the hints have been provided by the designers in the form of links for further reading.

> [Google Search for “dashed filename”](https://www.google.com/search?q=dashed+filename)
> [Advanced Bash-scripting Guide - Chapter 3 - Special Characters](http://tldp.org/LDP/abs/html/special-chars.html)


***

**Hint 2**: The first result of the Google search, which leads to a Unix Stack Exchange post explains the problem and gives you the answer as well.

***

###Solution

No more hints as you already have the answer :)

By now you've figured out that cat is treating "-" as a synonym for stdin. 

As for what exactly cat is doing, [go to the second link](http://tldp.org/LDP/abs/html/special-chars.html), and Ctrl+F for "*redirection from/to stdin or stdout [dash]*". It will lead you to a section that explains `cat`'s behaviour, and other scenarios where the "-" is used by other commands

I would also recommend browsing the same article for info on the other special characters mentioned there.

As was shown in the Unix Stack Exchange post, the solution is to simply use the full path to the file like below, which ensures cat does not treat it as stdin

![bandit3](https://thepracticaldev.s3.amazonaws.com/i/vkge6n306is45vnajh2p.png)
Bash consoles for windows: Hyper vs Gitbash (my experience so far)
Tags: discuss, webdev
Published: 2019-07-05 08:55:51

Hi there!

Since a month ago I started working with the command line. I am a windows user (I do not intend to create a debate on Win/iOS) so I went for the two most relevant options I could find:
* [GitBash cmd](https://gitforwindows.org/)
* [Hyper] (https://hyper.is/)

Pros:

* GitBash: simplicity overall. It allows all UNIX commands, including the drag and drop folders to catch the URL directly.
* Hyper: highly customizable regarding format, font color, font size, etc in a relatively easy way. It is cross-platform so it allows you to work under any OS. It also supports multi-tab structure so you don't have to open new apps. There are also several plugins for it.</li>

Cons:

* GitBash: it does allow [some customization](https://alanbarber.com/post/how-to-customize-the-git-for-windows-bash-shell-prompt/) although not as easy as Hyper does. It does not support multi-tab so, whenever you run a server and need to keep working, you need to launch again the app.
* Hyper: In my case, it keeps on suddenly closing. Which is a bit tricky when you need to quit processes before closing such a mongod. It forces you to find a workaround to close the server, etc.
On the other hand, I found hyper to be more memory-consuming even in rest.
Hyper also works and needs gitbash, so you will end up with both apps installed. And it needs to be configured previously in order to make it work as a bash console and not just as a Windows cmd.

Conclusion:

I am sure there is a lot more involved. My use of the console is quite basic so far. However, I found the self-closing issue of Hyper very annoying, which makes me prefer to work with gitbash. It also is less memory consuming and more stable, at least on my computer.
However, I must recognize that I like Hyper so bad! It is flexible, customizable and way more visually attractive than gitbash. But right now I have chosen to work more often with gitbash.
If you do not experience these self-closing issues and are not in a memory hurry, then I would definitely recommend Hyper.

Please feel free to share your experience with these apps, and also if you know other apps that could be used as bash consoles for Windows.

Thank you for reading!
Explain How I Secure my First Web-Application Like I Am Five
Tags: security, explainlikeimfive, help
Published: 2019-07-05 08:47:05

---
title: Explain How I Secure my First Web-Application Like I Am Five
published: true
description: I am your 5 year old child and want to publish my first self-coded web-application. What security measures do you want to teach me before I go live?
tags: #security #explainlikeiamfive #help
---

Yes, I am your super nerdy child and proudly present you my first self-coded web application. Of course I want to publish it live and show it to all my kindergarden-friends. You are super proud, but you also want to prevent me from a security-nightmare with my first running web-application. Your child wouldn't be such a lovely nerd if it had not already duckduckgone some security-related terms. Now it is your turn to explain what it means, what it prevents from and how it works (super basically):

* HTTPS
* Input Validation
* Authentication (oauth, JWT, more?)
* Autorization
* Security Headers
* CSRF
* CORS
* CSP
* Captcha
* Honeypot

... and maybe you are missing some very basic random stuff that is important to know before I go live?