teleren/devto huggingface dataset:
I made a JS Module so you can *almost* use the pipeline operator today!
Tags: showdev, javascript, polyfill, esnext
Published: 2018-04-13 04:52:22

---
title: I made a JS Module so you can *almost* use the pipeline operator today!
published: true
description: I heard you like functions so I made a function for you to pipe your functions to other functions functionally.
tags: showdev, javascript, polyfill, esnext
---

I heard you like functions so I made a function for you to pipe your functions to other functions functionally.

TC39, the standards body for ECMAScript, currently has a proposal for the [pipeline operator](https://github.com/tc39/proposal-pipeline-operator) in Stage 1 that's gaining a lot of traction.

Suppose you have the following function declarations

```js
function doubleSay (str) {
    return str + ", " + str;
}
function capitalize (str) {
    return str[0].toUpperCase() + str.substring(1);
}
function exclaim (str) {
    return str + '!';
}
```

So if you wanted to use the functions together, you could do:

```js
let result = exclaim(capitalize(doubleSay("hello")));
```

But that executes all of our functions in the backwards order that we wrote them, so introducing the *pipeline operator*!

```js
let result = "hello"
  |> doubleSay
  |> capitalize
  |> exclaim;
```

That looks much better! And there's a lot of discussion about the exact syntax and whatnot, but whilst reading said discussion, someone mentioned that this is actually already possible with JavaScript! So I did some research, tested it, and wrapped it up, and this is the core result :D

```js
function pipeline(input, ...methods) {
    const next = methods.shift();
    if (typeof next !== 'function') {
        return input;
    }
    return pipeline(next(input), ...methods);
}
```

And that's it! And then to use this we would do,

```js
let result = pipeline(
  "hello",
  doubleSay,
  capitalize,
  exclaim
);
```

But this is #showdev so I made a module and you can use this today!

> Note: At the time of this writing ES 2015+ Module support on Node and Firefox is experimental so your mileage may vary depending on your platform. Issues and comments on GitHub welcome :)

Links:
- GitHub: https://github.com/Nektro/js-pipeline
- NPM: https://www.npmjs.com/package/pipeline-operator
- CDN: https://unpkg.com/pipeline-operator/index.js

----

edit: Thanks to advice, this is now also available as a 1-liner that take advantage of `Array.reduce`!

```js
const pipeline = (input, ...methods) => methods.reduce((ac,cv) => cv(ac), input);
```
What's the weirdest coding practice you've seen?
Tags: discuss, webdev
Published: 2018-04-13 00:24:12

---
title: What's the weirdest coding practice you've seen?
published: true
description: Coding slurs. We've all seen them. Which are the worst you've seen?
tags: discuss, webdev
---

Inspired by [kodengo's post](https://dev.to/kodengo_com/whats-the-most-irritating-if-statement-condition-that-youve-come-across-27jf), what's the weirdest thing you've seen in code?

For me, I managed a CRUD app that used Oracle as a DB. We had a mix of pure queries and stored procedures, so in the app (.NET), we had to create a bunch of parameters.

Nearly every file that executed queries and procedures had this setup, but one had this for *over 30 parameters*! Something like.

```csharp
OracleParameter prm_FNAME = new OracleParameter("FIRST_NAME", OracleType.Char, 32);
prm_FNAME.SourceColumn = "FIRST_NAME";
prm_FNAME.Direction = ParameterDirection.Input;
prm_FNAME.IsNullable = true;
prm_FNAME.Value = strFirstName;

OracleParameter prm_LNAME = new OracleParameter("LAST_NAME", OracleType.Char, 32);
prm_LNAME.SourceColumn = "LAST_NAME";
prm_LNAME.Direction = ParameterDirection.Input;
prm_LNAME.IsNullable = true;
prm_LNAME.Value = strLastName;

...

OracleParameter prm_RETVAL = new OracleParameter("RET_VAL", OracleType.Char);
prm_RETVAL.Direction = ParameterDirection.Output;

List<OracleParameter> params = new List<OracleParameter>();
params.Add(prm_FNAME);
params.Add(prm_LNAME);
...
params.Add(prm_RETVAL);

for (int i = 0; i < params.Length; i++) {
    oraCommand.Parameters.Add(params[i]);
}

oraCommand.ExecuteNonQuery();

string value = params[params.Length - 1].Value;

return value;
```

I haven't worked at this place in years, but I still remember code like this. After asking, I later found that

1. Nobody else found anything wrong with this codebase
2. Nobody on the team knew what a `Dictionary` was

What's the worst thing you've seen?
How do you decide what order to put code in?
Tags: discuss
Published: 2018-04-12 23:23:51

---
title: How do you decide what order to put code in?
published: true
description: 
tags: discuss
---

What order do you put classes and functions in within a file, when it doesn't affect syntactic or semantic correctness?  What order do you put methods in within a class?  If two "code paragraphs" don't depend on each other, which do you put first?  Do you denote groupings of functionality with section header comments or whitespace?
Weekly Command: jumping directories with z
Tags: xnix, commandline, monades
Published: 2018-04-13 13:49:49

---
title: Weekly Command: jumping directories with z
published: true
tags: xnix, command-line, monades
canonical_url: https://monades.roperzh.com/weekly-command-jumping-directories-with-z/
---

This week we are going to review one of my favorite and most used commands. If you move around the command line, you may have experienced the pain of recalling directory structures and typing them over and over to access directories that are distant from each other.

`z` is specifically designed to fix this pain by allowing you to _jump_ trough directories.

_h/t to [@luislavena](https://twitter.com/luislavena/) for sharing the existence of `z` with me._

## The basics

<div>
  <pre><strong>z</strong> [<i>-chlrtx</i>] [<i>regex1 regex2 ... regexn</i>]</pre>
</div>

As simple as it sounds, `z` will take you directly to a directory that matches the regexes you provide, no matter where you are.

It’s worth emphasizing that the argument is a regex, which is especially useful if you are lazy: I usually type the first two or three letters of the directory that I want to access and it’s enough.

`z` is very easy to install, if you are anxious to try it by yourself head to the [install instructions in the README](https://github.com/rupa/z).

An important gotcha: `z` is only able to take you to directories that you already visited before: it needs a learning phase because of how it works.

## How it works

`z` does its magic by storing the directories you visit in a flat file database and matching your query against this list. This file is located by default in `$HOME/.z`, but the directory can be changed via the `$_Z_DATA` variable.

`z` works so well because this list of directories is ordered based on what the author refers as “frecency” (a term apparently coined by Firefox developers, if you have more info please let me know!) which combines _frequency_: the amount of time you spend in a directory with _recentness_: how recently you were in a directory.

![A bash session using `z` on the left, the flat file database on the right, notice how it gets updated everytime a directory is visited.](https://user-images.githubusercontent.com/4419992/38288175-64e10660-37a5-11e8-83b4-665b657adfc8.gif)<figcaption>
    <i>
      Session using z on the left, flat file database on the right: notice how it gets updated every time a directory is visited.
    </i>
  </figcaption>

As you keep navigating directories, the rank maintained by `z` undergoes aging based on a simple formula:

> The rank of each entry is incremented every time it is accessed. When the sum of ranks is over 9000, all ranks are multiplied by 0.99. Entries with a rank lower than 1 are forgotten.

## Examples

| Command | Functionality |
| --- | --- |
| `z foo` | cd to most frecent dir matching foo |
| `z foo bar` | cd to most frecent dir matching foo, then bar |
| `z -r foo` | cd to highest ranked dir matching foo |
| `z -t foo` | cd to most recently accessed dir matching foo |
| `z -l foo` | list all dirs matching foo (by frecency) |

## Sources

- [z Repository](https://github.com/rupa/z)
TIL Why AND should have two representations.
Tags: todayilearned
Published: 2018-04-12 21:50:55

---
title: TIL Why AND should have two representations.
published: true
description: VB!!!!!
tags: #til
---

In most languages, the concept AND has two different representations. For example, in F# there is _logical_ AND:

```fsharp
let awesome = good && great
```

Then there is _bitwise_ AND:

```fsharp
// this is pretty common when working with Flags
let hasRed = someColors &&& Color.Red = Color.Red
```

But then there's VB, for which both concepts use the keyword `And`. So I implemented a feature in VB to clone an image. I had this code snippet.

```vb
    Public Shared Function CloneImage(ByVal sourceImage As Bitmap) As Bitmap
        If sourceImage.PixelFormat And PixelFormat.Indexed <> 0 Then
            Return CreateIndexedImage(sourceImage)
        Else
            Return CreateNonIndexedImage(sourceImage)
        End If
    End Function
```

This code always calls `CreateIndexedImage`. And it took me a bit to figure out why. It was because the language sees the keyword `And` as the lowest priority operator and evaluates it last. It does that because it is only considering the priority of _logical_ `And`. So the actual evaluation was something like `(sourceImage.PixelFormat) And (PixelFormat.Indexed <> 0)`. VB coerces the type of PixelFormat to be truthy, and the second condition will always be true.

The fix was to add parenthesis

```vb
        If (sourceImage.PixelFormat And PixelFormat.Indexed) <> 0 Then
```

But this could have been avoided by simply having a different operator between the two uses. Then each could have a different order of precedence.
What does ** (two asterisks in a row) mean in Ruby?
Tags: todayisearched, ruby
Published: 2018-04-12 21:07:11

---
title: What does ** (two asterisks in a row) mean in Ruby?
published: true
description: 
tags: todayisearched, ruby
---

Today I saw `**` used between two integers. I had no idea what it meant so I turned to google. Turns out that two asterisks is Ruby's arithmetic operator for exponentiation.

i.e. 2**3 means 2³ aka 2x2x2 aka 8
Whats the most irritating "if statement condition" that you've come across?
Tags: discuss, pinocchioconditions, doublenegation
Published: 2018-04-12 19:56:24

---
title: Whats the most irritating "if statement condition" that you've come across?
published: true
tags: discuss,pinocchioconditions,doublenegation
---

Inspired by the Pinocchio's discussion with prince charming in "Shrek":

**Prince Charming:** You! You can't lie. So tell me, puppet, where is Shrek?
**Pinocchio:** Uh, I don't know where he's not.
**Prince Charming:** You're telling me you don't know where Shrek is?
**Pinocchio:** It wouldn't be inaccurate to assume that I couldn't exactly not say that it is or isn't almost partially incorrect.
If you feel slow with Mac + Docker + Laravel, the reason may be Laravel Debugbar
Tags: larave, docker
Published: 2018-04-12 19:05:04

---
title: If you feel slow with Mac + Docker + Laravel, the reason may be Laravel Debugbar
published: true
description: 
tags: Larave, Docker
---

I researched the reason why my development environment with Mac + Docker + Laravel.

My conclusion is disabling `Laravel Debugbar`. It increases the app speed about **3 times faster**.

![image.png](https://qiita-image-store.s3.amazonaws.com/0/103885/ac4d4abf-e6d7-b2a2-568a-27740cc76298.png)

The response time was 2.6s and now 0.85s, so approximately 3x faster.

# The considerable reason

Laravel Debugbar creates a log file under `storage/debugbar/` like `Xc590ef0f5b368cf34373093291b95147.json` **per request**.

This is a log with a request.

```
~> find storage/debugbar -type f | wc -l
58
```

Within this file, we can view the stack trace of app.

`/api` has a lot of middlewares so the file size is terribly bigger.
We can find over  **24000 Line** as formated json.

```
~> cat storage/debugbar/X2e75040e69de9cae006253a48fd5276c.json | jq . | wc -l
24676
```

This time size of the file was about **500KB**.

```
~> ls -lh storage/debugbar/X2e75040e69de9cae006253a48fd5276c.json
-rw-r--r--  1 kazuya-mac  staff   508K  3 27 18:32 storage/debugbar/X2e75040e69de9cae006253a48fd5276c.json
```

As we know, when we run Docker on Mac, writing file is terribly slow.
So stopping the logging make app faster greatly.

# TODO

I would like to use Laravel Debugbar itself, so I am looking for the way to improve the performance of Laravel Debugbar.
I think the following way should be a candidate.

- Forward logs via HTTP
- Set log output directory to directory other than `storage/logs`.
- Do not mount `storage/` as Docker `volume` (Is it possible not to mount with Docker partially...?)

We may make the Laravel app faster, except for Debugbar with log output directory.

# Off topic

This is useful.

```bash
#!/usr/bin/env fish

while true
    curl -H 'Accept-Encoding: gzip' -Ss -LI -o /dev/null -w \
        '%{http_code} in %{time_total} seconds, %{content_type} as %{size_download} \n' \
        $argv
    sleep 1
end
```
Who uses TypeScript, and what is your opinion of it?
Tags: discuss
Published: 2018-04-12 15:41:13

---
title: Who uses TypeScript, and what is your opinion of it?
published: true
tags: discuss
---

I started learning TypeScript [on my stream](https://www.youtube.com/watch?v=DzJ_oN1bpz4&t=7s) as we'll be using it at work. It seems like it's somewhat popular, but on my [second show](https://www.youtube.com/watch?v=_4zfDZJmfSg) I'm recognizing some problems I wasn't expecting. It feels a lot less mature than it's popularity would suggest.

It's clearly a step up about plain JavaScript, but seems to be missing a lot, or perhaps just be poorly documented.

Who is using TypeScript and what are you experiences with it?
Common Threats in Web Application Security
Tags: webapp, webappsecurity, cybersecurity, webdev
Published: 2018-04-12 14:59:35

---
title: Common Threats in Web Application Security
published: true
description: Common threats in web application security, how to protect against them and mitigate their impact
tags: #webapp #webappsecurity #cybersecurity #webdev
canonical_url: https://auth0.com/blog/common-threats-in-web-app-security/
---

In this article, we'll attempt to cover a comprehensive security strategy for web applications to protect against common threats in web application security and mitigate their impact.

[Read on 🖥🔐](https://auth0.com/blog/common-threats-in-web-app-security/?utm_source=dev&utm_medium=sc&utm_campaign=web_app_security)

![Common Threats in Web Application Security](https://thepracticaldev.s3.amazonaws.com/i/ecj8hqo96r539d2eggth.png)
Why you shouldn't be stingy when naming variables!
Tags: discuss, productivity
Published: 2018-04-12 14:41:44

---
title: Why you shouldn't be stingy when naming variables!
published: true
description: W y st b s w n v!
tags: discuss, productivity
---

Recently I took over another project and as usual there is a bit of reading-into-it period to understand what is actually going on. It isn't a big project, but one of its classes had about 1.5K lines of code with X methods, which sometimes were very very long. In this moments  I always ask myself: "Is it me or is it the layout of this class that makes it so difficult to understand?". I certainly sure about the fact that I'm not always the fast, who understands everything at once. But I think every developer has the obligation to try at least to make his or her code easily readable and understandable. Part of that is not writing looooooooong classes or even looooooooooooonger methods, but also how we name things. 

I came across a lot of variables like: `p`, `c`, `pc`, `pkAdd`, etc., and I think that this is just not a good way of doing this. Sure, if you need a counter for a loop so, use `c`. I guess that is universal and everyone gets that. Based on that I recently posted a tweet (https://twitter.com/tschaka1904/status/984409479444824064), can you read it? :D 

The point is, sometimes it is worth to write things out and use `project`, `category`, `projectCategory` and `addProjectCategory`. And surprise: Your IDE is doing almost all the magic for you 🧙‍♂️!

Keep your code r!
Test Contravariance - Who Understands It And Can Provide an Example?
Tags: discuss, testing
Published: 2018-04-12 13:17:36

---
title: Test Contravariance - Who Understands It And Can Provide an Example?
published: true
tags: discuss, testing
---

I deal with brittle unit tests that I have to fix every time I change production code. I don't just deal with them, I write them as fast as I write production code.

To me this is far better than not having or writing unit tests. I still get many benefits, which include that writing unit tests guides towards writing cleaner, simpler code.

But there's another level I haven't gotten to yet, and I want to get there. Robert Martin's blog post [Test Contra-variance](http://blog.cleancoder.com/uncle-bob/2017/10/03/TestContravariance.html) provides the outline of something better, but I have no idea what the reality looks like. 

Most of the time I create test classes that directly correspond to the classes they test. Breaking away from that seems like a first step, even if it's not technically any different, just because it breaks the habit. Instead of writing a `FooTests` class to go with my `Foo`, I write a `FooDoesX` class with tests for that particular behavior.

That's surface-level, though. Under the hood it's essentially the same old test class. I can make it a little less brittle by reusing some setup, with the goal of minimizing code duplication within tests while still ensuring that the "arrange" for each test is explicit so that it's clear what behavior it's testing.

Can anyone provide an example, perhaps in a public repository, of test contravariance? I'm not looking for a general discussion of unit tests vs. integration tests or testing a single class vs. testing a class with its collaborators, although there's likely significant overlap. I'm trying to see if someone who understands exactly what Uncle Bob is talking about can elaborate or provide an example.

Thanks!
🦊 Building A WordPress Artificial Intelligence Plugin
Tags: azure, mongodb, wordpress, ai
Published: 2018-04-12 12:12:35

---
title: 🦊 Building A WordPress Artificial Intelligence Plugin
published: true
description: I've been working on this cool little project for WordPress, a sort of an Artificial Intelligence based on 🎩 Microsoft Azure, ☘️ MongoDB Atlas, and a bunch of other services that helps me automate lots of silly things for my WordPress website.
tags: Azure, MongoDB, WordPress, AI
---

I've been pulling an all-nighter, all-too-excited while working on this cool project where I am building a WordPress Artificial Intelligence plugin.

![PW AI](http://on.ahmda.ws/qqwI/c)

Sounds cliché, but before I go ahead and explain it to you, I'd rather have you watch this quick silly video of me trying to demo what I've built at 5 am. Have at it. 👇


{% youtube Dv_qJhn8KM4 %}


<em>— So, what are your thoughts? Mind-blowing ain't it.</em>

<ul>
 	<li>👌 Cognitive Services APIs</li>
 	<li>🎩 Microsoft @Azure</li>
 	<li>☘ @MongoDB Atlas</li>
 	<li>🚀 Automation FTW</li>
</ul>

With any luck, I'll try my best to release this work as FOSS (Free and Open Source Software) along with <a href="https://github.com/ahmadawais">hundreds of other open source projects</a> I've released at GitHub. Coz, why not. Also, it's 10-year anniversary of GitHub 💥

<h3>What Now?</h3>
Well, hop on Twitter and tell me how you feel about this project. Or just say 👋 and maybe retweet this one. Would make a lot of difference.

{% twitter 984223532631711744 %}

<p style="text-align: center;">Peace! ✌</p>
Linux Fedora 27 Install Gmic | sudo dnf install gmic
Tags: install, linux, fedora
Published: 2018-04-12 11:40:10

---
title: Linux Fedora 27 Install Gmic | sudo dnf install gmic
published: true
description: Linux Fedora 27 Install Gmic | sudo dnf install gmic
tags: Install, Linux, Fedora
---

```
psnebc@localhost  ~  sudo dnf install gmic    
Zwischenspeicher für Paketquelle »Dropbox« konnte nicht synchronisiert werden, wird deaktiviert.
Letzte Prüfung auf abgelaufene Metadaten: vor 0:48:30 am Do 12 Apr 2018 12:45:46 CEST.
Abhängigkeiten sind aufgelöst.
================================================================================================
 Paket              Arch                 Version                    Paketquelle           Größe
================================================================================================
Installieren:
 gmic               x86_64               2.1.8-1.fc27               updates               9.7 M

Transaktionsübersicht
================================================================================================
Installieren  1 Paket

Gesamte Downloadgröße: 9.7 M
Installationsgröße: 28 M
Ist dies in Ordnung? [j/N]:y
Pakete werden heruntergeladen:
gmic-2.1.8-1.fc27.x86_64.rpm                                    1.4 MB/s | 9.7 MB     00:06    
------------------------------------------------------------------------------------------------
Gesamt                                                          1.3 MB/s | 9.7 MB     00:07     
Transaktionsüberprüfung wird ausgeführt
Transaktionsprüfung war erfolgreich.
Transaktion wird getestet
Transaktionstest war erfolgreich.
Transaktion wird ausgeführt
  Vorbereitung läuft    :                                                                   1/1 
  Installieren          : gmic-2.1.8-1.fc27.x86_64                                          1/1 
  Ausgeführtes Scriptlet: gmic-2.1.8-1.fc27.x86_64                                          1/1 
Running as unit: run-r972e58bc6d444fefb98554d54b1085fa.service
  Überprüfung läuft     : gmic-2.1.8-1.fc27.x86_64                                          1/1 

Installiert:
  gmic.x86_64 2.1.8-1.fc27 
```
Microsoft is Making love to Linux in the Windows store.
Tags: opensource, fossstories, fossnaijanews, linux
Published: 2018-04-12 10:19:54

---
title: Microsoft is Making love to Linux in the Windows store.
published: true
tags: FOSS,FOSS Stories,FossNaija News,Linux
canonical_url: https://fossnaija.com/microsoft-is-making-love-to-linux-in-the-windows-store/
---

Bringing the unmatched Linux experience to the world of windows is being made possible by Microsoft through its windows subsystem for Linux (WSL) that has been released as open-source software to the public. Though the then newly appointed CEO of Microsoft, Satya Nadella, publicly declared Microsoft’s love for Linux, many in the free and open… [Read More »](https://fossnaija.com/microsoft-is-making-love-to-linux-in-the-windows-store/)

The post [Microsoft is Making love to Linux in the Windows store.](https://fossnaija.com/microsoft-is-making-love-to-linux-in-the-windows-store/) appeared first on [Foss Naija](https://fossnaija.com).