teleren/devto huggingface dataset:
Don't underestimate your setup, learners
Tags: productivity, workstations, beginners
Published: 2020-02-19 02:58:26

## How to make your life living hell

If someone asked me how to design my work environment as uncomfortable as possible, I wouldn't have had good answers until recently. I started tutoring coding on [wyzant](https://is.gd/zoA0hS) about a month ago and have had students ranging form "I am almost there" to "I am completely lost". What I noticed was that the biggest frustration comes with not being able to operate one's tools.

## IDE

Use it, modify it, set it up, learn it. I cannot emphasize enough how the time not using your IDE to the fullest will add up. Those shortcuts for the geeks alone? They'll save me an hour a day, five hours a week, over 250 hours a year. [Introduction video](https://youtu.be/a0VpQS4dcGc)

## Touch typing

Pecking at your gaming keyboard? Within a week you can train yourself to be a touch typist. My kids love [typing club](https://www.typingclub.com/), but there are countless options.

## Version control

Those version-control-evangelists aren't wrong: after getting used to it, you will never ever accept a different form of development. Take your time to think about a strategy. Don't just learn the few commands and wonder what all the fuzz is about; use it to save yourself from the biggest threat to your code: you. [Considerations](https://git-scm.com/book/en/v2/Git-Branching-Branching-Workflows)

## Conclusion

I know you are progressing fast. You are super busy jumping from one topic into the next and right after you thought you got the hang of CSS they throw Sass at you. But believe me: an hour spent on your abilities to work on your skills when it comes to tooling is an hour well invested. It will make the difference between a healthy future and carpal tunnel in your late 20s. The difference between being frustrated that repetitive processes take forever and having the time for that Side-Project you keep dreaming about.
Render HTML-marked text Received from Server
Tags: react, javascript
Published: 2020-02-19 02:18:48

---
title: Render HTML-marked text Received from Server
published: true
description: dangerously or regexp
tags: react,javascript
---

Sometimes we need to render HTML-marked strings from server, with React. However, React can **usually** only render UI written in JSX or `createElement`.

So, let's use unusual methods. I have two ideas💡.

1. Use `dangerouslySetInnerHTML` 🚨
2. Use RegExp and Split

{% codesandbox react-dynamic-markup-fjhdb %}

## Use `dangerouslySetInnerHTML` 🚨

This is easy but VERY DANGEROUS method ([as the documentation says](https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml)).

```js
const marked = "This sentense has <b>a bold text</b> and <b>another one</b>.";

return <div dangerouslySetInnerHTML={{ __html: marked }} />;
```

Okey, run it.

![result of dangerous method](https://dev-to-uploads.s3.amazonaws.com/i/2n55ce75jtfqe3isrh7n.png)

Great!😈

But, but, this method carries a significant risk🧨 against XSS attacks.

## Use RegExp and Split

As a safe way, split the string and re-markup it.

Here is the sample.

```js
const BoldableText = ({ text }) => {
  // shortest match for marked text with <b> tag
  const re1 = /<b>(.+?)<\/b>/g;
  // for removing tags included in the string matched by re1
  const re2 = /<b>(.+)<\/b>/;

  // strings to re-markup with JSX
  const matched = text
    .match(re1) // ["<b>a bold text<b>", "<b>another one</b>"]
    .map(s => s.match(re2)[1]); // ["a bold text", "another one"]

  // split strings to re-markup
  const texts = text.split(re1); // ["This sentense has ", "a bold text", " and", ...]

  const markedJsx = texts.map((s, index) => {
    if (index === 0 || index === texts.length - 1) {
      // first and last item is not the target to re-markup
      // because "<b>foo bar</b> buz..." generates ["", "foo bar", " buz"...]
      return s;
    }

    if (matched.includes(s)) {
      return <b key={s}>{s}</b>; // re-markup!!
    }

    return s;
  });

  return markedJsx;
};
```

And use it as below.

```js
const marked = "This sentense has <b>a bold text</b> and <b>another one</b>.";

return <BoldableText text={marked} />;
```

Okey, run it.

![result of split method](https://dev-to-uploads.s3.amazonaws.com/i/wpbu4v2ob9xfanbjue0x.png)

I did it!!!🎉🎉🎉🎉🎉

## Memo

* Do I really have to use two regular expressions?
* How about nested tags?
* [rehype-react](https://github.com/rehypejs/rehype-react) is more easy way? (thx [@_sunnyone](https://twitter.com/_sunnyone/status/1229957538994515968))
How's your 2020 going?
Tags: discuss, watercooler, codenewbie, motivation
Published: 2020-02-19 02:17:20

I took this past weekend to breathe. 

Instead of getting a head start on a major blog post, I did what I regretted **not** doing in 2019, in 2018 and in 2017– I hung out with friends and let the weekend pass me by.

For me, this signified what will hopefully be a seismic change in priorities.

When there's still so much to learn, it's difficult to justify skipping one day, let alone three. But then 2020, which used to seem so far away, rolled in. And with it came the realization that in the same way you learn bit by bit, relationships need to be nurtured deliberately day-by-day.

So with that in mind, my 2020 has been going much better! I'm happy to have let myself take off three days and ecstatic to still have friends to spend that time with. Surprisingly, the world did not end.

How is your 2020 going? Did 2020 bring about any major self-realizations?
Update jsonb Columns Using The Rails Active Record Native Methods
Tags: rails, postgres, jsonb, activerecord
Published: 2020-02-19 01:36:44

While building a Rails API backend for a recent project I came across a challenge when updating jsonb columns.

You see as a pure Rail'ist (Is that a thing...?) I try to stay away from writing *SQL* strings in my app when I could use *Active Record* native methods, but since I had defined some columns as *Jsonb* it seemed like I would need to use *SQL* since all the tutorials were making use of *jsonb_set SQL* method as follows:

```sql
sql = 'UPDATE users SET preferences = jsonb_set(
options, \'{email_opt_in}\', \'false\', FALSE) WHERE id = 1;'

c.execute(sql)
```

But as a Rail'ist I was looking for something more like `user.update(params)`.

So...
This is what I came up with:
1. First get the current column value which Active Record returns as a Ruby hash:
`user = session_user`
`currentKeys = user.api_keys`

2. Convert *post params* to a hash and extract the nested values which were nested under *keys*:
`hashedParams = user_params.to_h[:keys]`

3. Use the Ruby hash merge method to merge my *post params* and current user column data:
`newKeys = currentKeys.merge(hashedParams)`

4. I could now use the Rails object update method as usual:
`user.update(api_keys: newKeys)`

Here is the complete code:
```Ruby
    user = session_user
    currentKeys = user.api_keys
    hashedParams = user_params.to_h[:keys]
    newKeys = currentKeys.merge(hashedParams)

    if user.update(api_keys: newKeys)
        Bla, bla, bla...
```

Ok, now here's the thing: I need validation if the above is acceptable as a Rail'ist(you heard it here first) so please If I'm missing anything(method, convention, irk etc.) comment below :)

Thanks For Reading!
Introducing HTTP types
Tags: javascript, python, api, opensource
Published: 2020-02-18 14:48:00

---
title: Introducing HTTP types
published: true
description: A standard for recording HTTP requests and responses
canonical_url: https://meeshkan.com/blog/introducing-http-types/
tags: javascript, python, api, opensource
---

At Meeshkan, we've recorded millions of HTTP transactions. In doing so, we've noticed that there's no standard format for recording them.  Even within our own company (which only has 10 people!) we managed to create competing standards for recording HTTP traffic.

To fix this, we've created an open standard for storing HTTP transactions.  With it, we hope to achieve one of two outcomes:

- `http-types` evolves into an ISO standard, or
- Someone smarter than us will either make something better or point us to a better standard.

In the absence of either of these things for the time being, we're happy to announce [`http-types`](https://github.com/Meeshkan/http-types)!

# The format

The top-level type in `http-types` is the `HttpExhange`, an object with two keys:

- `request`: the incoming request, and
- `response`: the outgoing response


The following is an example of a request and response stored in the `HttpExchange` format:

```json
{
  "request": {
    "method": "get",
    "protocol": "http",
    "host": "example.com",
    "headers": {
      "accept": "*/*",
      "user-agent": "Mozilla/5.0 (pc-x86_64-linux-gnu) Siege/3.0.8"
    },
    "pathname": "/user/repos",
    "query": { "param": "value" },
    "timestamp": "2018-11-13T20:20:39+01:00"
  },
  "response": {
    "statusCode": 200,
    "body": "(response body string)",
    "headers": {
      "content-length": "1999",
      "content-type": "text/html; charset=utf-8"
    },
    "timestamp": "2018-11-13T20:20:39+02:00"
  }
}
```

More detailed documentation can be found on the [`http-types` GitHub repo](https://github.com/Meeshkan/http-types). We also have a small [website](https://meeshkan.github.io/http-types/) for the project with a general overview.


# Client libraries

We've written `http-types` client libraries in the most common languages we use at Meeshkan.  The current available client libraries are:

- [java-http-types](https://github.com/Meeshkan/java-http-types): Java library available on [Maven Central](https://search.maven.org/artifact/com.meeshkan/http-types).
- [py-http-types](https://github.com/Meeshkan/py-http-types): Python library available on [PyPi](https://pypi.org/project/http-types/).
- [ts-http-types](https://github.com/Meeshkan/ts-http-types): TypeScript library available on [npm](https://www.npmjs.com/package/http-types).

If you'd like to contribute a client library, please propose one on our [GitHub issues page](https://github.com/Meeshkan/http-types/issues).

We would love to see more people play with `http-types`.  While it's far from perfect, it has been relatively stable within Meeshkan and we think it can serve as a good basis for community discussion on how to store web traffic.

**If you find it useful or have any questions/comments/criticisms, please let us know in the comment section below.**

Enjoy `http-types`!
Launched a free library for productivity hacks
Published: 2020-02-19 00:32:16

Hey, 
Just launched a free library for small productivity hacks and shortcuts. It's my first project using Svelte.js and I am absolutely in love. There is zero overhead and the setup is just so easy. 
Looking forward to when they have Typescript support. 

Anyways, if you want to have a look, check our Product Hunt launch :) https://www.producthunt.com/posts/productivity-so
Python 3.X : rglob with FileNotFoundError: [WinError 3] The system cannot find the path specified
Tags: python
Published: 2020-02-19 00:14:47


More details of issue on StackOverflow:

def collate_files(old_dir, new_dir) -> str:
   for subfolder in old_dir.rglob('*.xlsx'):  
       if subfolder.match("string_title"):
           new_dir= new_dir.joinpath(subfolder)
           if Path.exists(new_dir):
               pass
           else:
               try:
                   shutil.copy(subfolder, new_dir, follow_symlinks=True)
               except OSError as e:
                   raise e
Signature Pad Example In Laravel
Published: 2020-02-20 11:32:12

---
title: Signature Pad Example In Laravel
published: true
date: 2020-02-19 00:00:00 UTC
tags: 
canonical_url: 
---

Hi GuysI am going to show you example of laravel signature pad this example will help you laravel signature pad example Here you will learn signature pad example in laravel you can understand a concept of laravel signature pad tutorial You just need to some step to done laravel signature pa
do you get an ego boost when your goog map photos have reached over 1M views ?
Tags: watercooler, smn, bmn
Published: 2020-02-18 23:49:29

do you get an ego boost or get paranoid when your goog map photos have reached over 1M views ?

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/6u6phrydboperjdqgxae.png)
nmap - i never knew that 
Tags: devops, devsecops, sysadmin
Published: 2020-02-18 23:35:32

nmap - i never knew that for large port range scans it only list OPEN ports but for short range scans it lists EVERY port ! i must have used nmap for over 15 years without noticing this behaviour

LONG RANGE
```
$ nmap localhost -p10000-20000

Starting Nmap 6.40 ( http://nmap.org ) at 2020-02-18 23:32 GMT
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00074s latency).
Other addresses for localhost (not scanned): 127.0.0.1
Not shown: 10000 closed ports
PORT      STATE SERVICE
19999/tcp open  unknown

Nmap done: 1 IP address (1 host up) scanned in 0.49 seconds
```

SHORT RANGE
```
$ nmap localhost -p19990-20000

Starting Nmap 6.40 ( http://nmap.org ) at 2020-02-18 23:32 GMT
Nmap scan report for localhost (127.0.0.1)
Host is up (0.0010s latency).
Other addresses for localhost (not scanned): 127.0.0.1
PORT      STATE  SERVICE
19990/tcp closed unknown
19991/tcp closed unknown
19992/tcp closed unknown
19993/tcp closed unknown
19994/tcp closed unknown
19995/tcp closed unknown
19996/tcp closed unknown
19997/tcp closed unknown
19998/tcp closed unknown
19999/tcp open   unknown
20000/tcp closed dnp

Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds
```
Unit testing .NET Exceptions
Tags: csharp, dotnet, testing, unittesting
Published: 2020-02-18 23:17:42

## What's wrong with the VisualStudio TestTools [ExpectedException] attribute?

I don't like [[ExpectedException]](https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.testtools.unittesting.expectedexceptionattribute) because:
* The test passes if the exception is thrown *anywhere* in the test method, not just in the "act" statement where it should be thrown.
* It doesn't let you test the exception message.

## A better way

My [**SparkyTestHelpers** Nuget package](https://www.nuget.org/packages/SparkyTestHelpers/) enables a "fluent" **AssertExceptionThrown** syntax:

```csharp
using SparkyTestHelpers.Exceptions;
. . .
AssertExceptionThrown
    .OfType<ArgumentOutOfRangeException>()
    .WithMessage("Limit cannot be greater than 10.")
    .WhenExecuting(() => { var foo = new Foo(limit: 11); });
```

There are a few other "WithMessage" alternatives (They’re all optional — You don't have to test the message.):

* WithMessageStartingWith(*string expected*)
* WithMessageEndingWith(*string expected*)
* WithMessageContaining(*string expected*)
* WithMessageMatching(*string regExPattern*)

There's also **AssertExceptionNotThrown**:

```csharp
using SparkyTestHelpers.Exceptions;
. . .
TestFooConstructor()
{
    AssertExceptionNotThrown.WhenExecuting(() => var foo = new Foo());
}
```

..which really doesn't do anything (if the code being tested throws an exception, the test will fail anyway) but clarify the intent of tests that wish to show that an action doesn’t throw an exception.

[API documentation](https://github.com/BrianSchroer/sparky-test-helpers/blob/master/SparkyTestHelpers/api.md)

[More about SparkyTestHelpers](https://dev.to/sparky/sparkytesthelpers-1n0h)

## The best way

But even ol' Sparky himself doesn't use SparkyTestHelpers for exception testing anymore since he discovered [**FluentAssertions**](https://fluentassertions.com/).

FluentAssertions makes assertions "look beautiful, natural and, most importantly, extremely readable", as it says on their home page. Their [exception testing syntax](https://fluentassertions.com/exceptions/) looks like this:

```csharp
subject.Invoking(y => y.Foo("Hello"))
    .Should().Throw<InvalidOperationException>()
    .WithMessage("Hello is not allowed at this moment");
```
...or:
```csharp
Action action = () => subject.Foo2("Hello");

action.Should().Throw<InvalidOperationException>()
    .WithInnerException<ArgumentException>()
    .WithMessage("whatever");
```
...and for "exception not thrown" testing:
```csharp
action.Should().NotThrow();

```
FluentAssertions has a lot of powerful exception testing features. Check it out!

- - -
Happy testing!
New desk with old desk underneath. I’m really liking this setup. What do you think?
Tags: discuss
Published: 2020-02-18 23:06:05

Hey so I got a new desk a week and a half ago and wanted to show my new setup. I will add another photo of how my old setup looked as well. It feels so good to have more space. If you want to show off your setup put it in the comments and lets see what you got. Lol ;D

### Old Setup
![OLD](https://dev-to-uploads.s3.amazonaws.com/i/iy9yydxts0hj8kzx9l2e.jpeg)

### New Setup
![NEW 1](https://dev-to-uploads.s3.amazonaws.com/i/oipz02iqjucnc4wx37xx.jpg)

![NEW 2](https://dev-to-uploads.s3.amazonaws.com/i/yp6kpitpw0han19x3n0u.jpg)

![NEW 3](https://dev-to-uploads.s3.amazonaws.com/i/52ly4oqrm8lewuhx3f9m.jpg)
Make VS Code Your Default Git Editor 📝
Tags: git, beginners, productivity, vscode
Published: 2020-02-18 22:54:06

---
title: Make VS Code Your Default Git Editor 📝
published: true
description: Article on how to make Visual Studio (VS) Code the default editor for git commands.
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/bdj1n4ug1thlmmvybxib.png
tags: git,beginners,productivity,vscode
---

Recently I've found myself using the git command `git commit --amend` to change typos in my commit messages. By default the <a href="https://www.nano-editor.org/" title="GNU's Not Unix!">GNU nano</a> text editor is used, which for me isn't a great experience and was starting to **BUG** me!

![Default GNU nano editor for changing git message](https://dev-to-uploads.s3.amazonaws.com/i/ne7mlf08p45kd99hg07i.png)
<figcaption>GNU nano editor is used by default to change git commit message</figcaption>

I use <abbr title="Visual Studio">VS</abbr> Code daily and as I'm typing the git command in the built-in VS Code terminal, naturally I want to edit the commit message using the same editor. Well luckily you can configure this with a one liner.

# Default VS Code As The Git Editor (Globally)

Type the following in the command prompt / bash shell.
```
git config --global core.editor "code --wait"
```

Or, alternatively if you don't like typing too much then use.

```
git config --global core.editor "code -w"
```

**Note:** The `--wait` or `-w` flag is crucial without this git won't know the editing has completed and in turn won't finish executing the git command.

## See It Working!

Below is a gif showing VS Code as the default editor for git.

![VS Code As The Default Git Editor](https://dev-to-uploads.s3.amazonaws.com/i/uwzyumaypx5yxff61lw0.gif)
<figcaption>Working example of VS Code as the default git editor</figcaption>

# Default VS Code As The Git Editor (Local Repo)

But wait there's more, if you don't want the change to happen globally you can set it locally for a git repository by using the flag `--local`.

```
git config --local core.editor "code -w"
```

# Revert Back To GNU nano (or default)

And if you prefer GNU nano and want to reset this to the default git editor, then run the following command.


```
git config --global --unset core.editor
```
**Note:** If you set the editor locally and you want to reset then replace the `--global` flag with the `--local` flag instead.
Accessing asset_path in webpacker *.js.erb pack
Tags: help, rails
Published: 2020-02-18 22:49:11

I’ve configured webpacker to be able to [process ERBs](https://github.com/rails/webpacker#erb) (`bundle exec rails webpacker:install:erb`) because I need paths generated by Sprockets' `asset_path` at build time so that I get properly generated asset URLs.

The ERB integration works with the simple example that you get after installing ERB/Webpacker integration, but I’m wondering how to have access to `asset_path`. From what I’ve found so far, it doesn’t appear to be possible, https://github.com/rails/webpacker/issues/284.

Does anyone know if it's possible? In the meantime, I will keep digging 😉

![Person slipping and sliding while attempting to shovel snow](https://media.giphy.com/media/ZIK2f5hBbnyyA/giphy-downsized-large.gif)
Statement: The Dom is slow.
Tags: webdev, discuss
Published: 2020-02-18 21:57:59

Heard that one before?

I'm sure you have, but who prey tell is measuring this on a monthly basis and keeps coming to this conclusion?

Recently I talked about the most powerful word in development, "why?", Continuing this train of thought 🚄 I'm here to talk about statements in software that are often passed around as a given deterministic fact. Despite the slightly less advertised fact that this statement is a handmedown from somebody else who heard it from thier grandma's dog Rex.

Software, development, life and everything in between is not deterministic, I'm not even sure the word really has a meaning. Time moves on and things change, what might be certain now is not certain tomorrow (perhaps, we can't determine this).

So back to that statement, I think we can call this inherited knowledge, do you think this is a helpful part of development? This knowledge is rarely tested but we inovate based statements like this, sadly we also berate those who didn't know this, (not that there is anything anyone could really know, non-deterministic).

Embrace indecision.
Love procrastination.
Think of everything in the present tense.
Ask why.

Right now I'd love to hear your thoughts 🤷‍♂️.
End of post or perhaps not.
FlowCore - A multi purpose, extendable, Workflow-net-based workflow engine for Rails
Tags: rails, workflow, ruby
Published: 2020-02-18 21:57:56

repo: https://github.com/rails-engine/flow_core

FlowCore is an open source Rails engine provides core workflow functionalities,
including workflow definition and workflow instance scheduling.
Easily making automation (including CI, CD, Data processing, etc.) and BPM applications or help you solve parts which changing frequently.

## Features

### Support all databases which based on ActiveRecord

All persistent data are present as ActiveRecord model and not use any DB-specific feature.

### Easy to extend & hack

FlowCore basically followed best practice of Rails engine,
you can extend as [Rails Guides](https://guides.rubyonrails.org/engines.html#improving-engine-functionality) suggests.

Your app-specific workflow triggers, callbacks and guards can be extended via [Single Table Inheritance](https://guides.rubyonrails.org/association_basics.html#single-table-inheritance)

FlowCore also provides callbacks for triggers (which control behavior of a transition) covered whole task lifecycle.

### Petri-net based

[Petri-net](https://en.wikipedia.org/wiki/Petri_net) is a technique for description and analysis of concurrent systems.

FlowCore choose its special type called [Workflow-net](http://mlwiki.org/index.php/Workflow_Nets) to expressing workflow.

Compared to more popular activity-based workflow definitions (e.g BPMN),
Petri-net has only few rules but could express very complex case.

Check [workflow patterns](http://workflowpatterns.com) to learn how to use Petri-net expressing workflows.

### Basic workflow checking.

A workflow must be verified first before running it.

FlowCore provides the mechanism to help to prevent unexpected error on instance running

### Interfaces and abstractions to integrate your business

FlowCore separate app-world and engine-world using interfaces and abstract classes,
basically you no need to know Workflow-net internal works.

### Runtime error and suspend support

FlowCore provides necessary columns and event callbacks for runtime error and suspend.

### A DSL to simplify workflow creation

FlowCore provides a powerful DSL for creating workflow.

For example:

```ruby
FlowCore::Definition.new name: "Timed split" do |net|
  net.start_place :start
  net.end_place :end

  net.transition :t1, input: :start, output: :p
  net.transition :t2, input: :p, output: :end
  net.transition :t3, input: :start, output: :end do |t|
    t.with_trigger TransitionTriggers::Timer,
                   countdown_in_seconds: 5
  end
end.deploy!
```