teleren/devto huggingface dataset:
Extending Javascript array with an event handler
Tags: javascript
Published: 2018-07-27 21:38:30

---
title: Extending Javascript array with an event handler
published: true
description: 
tags: #javascript 
---

I recently had to write a classifier algorithm that classified an array of items based on certain attributes. It was a pretty complicated dataset with an even more complicated set of constraints, but for the sake of this article i will keep it a simple.

Say we have the following dataset

```
    [
        {id:1, age:32},
        {id:2, age:4},
        {id:3, age:20},
        {id:4, age:30}
    ]
```

Now, say we wish to find the oldest age and the sum of all ages. This can easily be done using a loop and some variables, but for the sake of this article I will use an event listener attached to the traditional javascript array to pull this off.

# First Let's extend the array object
```
    const MyArray = function (){
        // this events object will be explained shortly
        this.events = {}
    }
```

So, simply I just created a function and called it my array then gave it an events object(or hashtable) that will hold all our events and callbacks in this form:


```
    {eventName:callback_function}
```

Let's continue with creating the extended array

```
    MyArray.prototype = []
    
    MyArray.prototype.on = function (event, callback){
        this.events[event] = callback
    }    

    MyArray.prototype.push = function(args){
        Array.prototype.push.call(this, args)
        const eventName = 'push'
        if(this.events[eventName]){
            this.events[eventName](args)
        }
    }

```

In the snippet above we let our function inherit the properties of the array object using prototype inheritance.

The second block implements our event listener function. We call the function on, so we can do things like on('filter') etc. All this function does is take in the event (or event name) and a callback to execute once that event occurs. The function stores the event name as the key and the callback as the value in our events hashtable.

Lastly we make our own push method to put new items into our object. The next line uses the push method of the parent Array object, but by using call, we call push in the context of the current object. This works because our object has inherited from Array. That's all.

## Testing our new object

So let's test this and see how it will work using the stated example data above.

```
const Arr = new MyArray()
let sum = 0;
let oldest = 0;
Arr.on('push', function (e){
    sum += e.age
    oldest = (e.age > oldest ? e.age:oldest)
})

for (let data of dataSet){
    Arr.push(data)
}

console.log(sum, oldest)
```

And that's it.
Looking for help fixing github-hosted custom domain's CNAME
Tags: help, webdev
Published: 2018-07-27 20:29:48

---
title: Looking for help fixing github-hosted custom domain's CNAME
published: true
description: having trouble with www subdomain.
tags: #help #webdev
---

TLDR: I am super new to front end dev and have just published my first website (yay!). The trouble is that when you type www at the beginning of the url, the website is not loaded (IP address cannot be found).

The whole story: The website - without the www subdomain (i.e.: example.com) loads just fine, but www.example.com gives me server IP cannot be found.

What I have set up: Over on google domains, I have a "www CNAME username.github.io/respositoryname." set up. And on my github repository, I have a CNAME set up. Right now the CNAME file has only example.com listed. I have also edited and tested it with these options: 
1. example.com 
2. www.example.com

and

1. www.example.com
2. example.com 

All three ways have not been successful.

Setting up all of this is all very new to me, and I've googled exhaustively last night and today. Everything I read says that one of these three ways to write my CNAME should have worked. I'm at a deadend now, any suggestions or further reading would be very welcome!! Thank you!!
Hello World again
Tags: writing, helloworld, beginners
Published: 2018-07-26 04:08:30

---
title: Hello World again
published: true
description: how to write hello world
tags: #writing #helloworld #beginner 
---
Hello World

yes, only those two words that I can write
I can write more code, but to write an article or just a line of caption why is it so hard and frustrating. of course this will be an obstacle in communicating with the public or clients who need a clear explanation.

if any of you are experiencing the same thing as me, do not be sad. We are the same. ha ha. and if any of you want to show, guide and teach how, I will be very happy and grateful.

in many articles about "How to Begin Writing" even confuses me step by step such as creating concepts, language structures, proper word selection, inter-sentence relationships ... while good concepts like what kind of language structure is like. so have to search first, browse again and again .. then when to start writing it ???? leave it.

let's write, write and write, keep writing, write again. what is written? what we have in mind, what we know ... can begin with definitions, like "what is a cup"
we can write, "cup is a cylindrical thing made of glass, useful as a place for water to drink",
"the mouse is the object we use to move the cursor on the computer",
"mice are an annoying animal, who eat what's in our house"
"boyfriend is someone who if we near him will make us happy",
"money can make us happy because with money we can have the goods we want",
"hello word's are two words that can make us happy, because it means our code is running, our program is successful, 'yeeeaah ... i am programmer now'"
and can still grow again as we think, what we see, what we feel ..

thank's
sory for my english
Start Windows service as non-admin
Tags: windows, service, user, start
Published: 2018-07-27 20:29:42

---
title: Start Windows service as non-admin
published: true
description: how to allow a non admin user to start/stop a specific service
tags: #windows, #service, #user, #start
cover_image: https://thepracticaldev.s3.amazonaws.com/i/xfybt4j06fdv6ot2d5j8.jpg
---
setting permissions for windows services is really awful.

just want to allow a nonadmin to start and stop my php worker:

```
sc sdshow php5-cgi-worker01
D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;IU)(A;;CCLCSWLOCRRC;;;SU)(A;;RPWPDT;;;S-1-5-21-<snip>-<snip>-<snip>-1000)
```
permissions can be set with `sc sdset ...`

the easier way is to use [SubInACL][1] as admin:

```
subinacl.exe /service php5-cgi-worker01 /grant=username=PTO
```
(P = pause, T = start, O = stop)

then you can start the service with your user:
```
sc start php5-cgi-worker01
```


- http://woshub.com/set-permissions-on-windows-service/
- https://www.microsoft.com/en-us/download/confirmation.aspx?id=23510
- cover image by geralt https://pixabay.com/en/binary-hands-keyboard-tap-enter-2372130/
[1]: https://www.microsoft.com/en-us/download/details.aspx?id=23510
I don't like exit intent popups.
Tags: discuss, ux
Published: 2018-07-27 16:43:02

---
title: I don't like exit intent popups.
published: true
description: 
tags: discuss, ux
cover_image: https://thepracticaldev.s3.amazonaws.com/i/adp837oerm1u2ondns7t.jpg
---
*Cover illustration adapted from wired.com*

You know the thing. Your cursor leaves the window, and suddenly a pop up appears with... something or other, honestly I don't read them. The idea is that if the user is about to leave your site, you should do something to try and retain them -- after all, the worst case is they leave anyway, right? But I always trigger these accidentally. Perhaps a site is too slow to load, so I open another tab while I wait (Shame if your site takes more than two seconds, by the way.) Or perhaps I'm just careless, or I have a nervous habit of moving my cursor. Whatever the case, there are lots of reasons my cursor might leave the window before I'm ready to leave. And now, the content I was waiting for has a giant box blocking it. I'm likely to abandon the site at this moment.

But I wonder if I am the only one. A cursory search on this subject shows a few sites promoting exit intent because they are selling some code that will do it for you (of course), but also a few sites that cite some data showing an increase in conversions. There is surprisingly little hate for something that seems so annoying.

So I'm left with a couple of questions:
1. Is this *really* a positive feature? And if so
2. Is it ethical or wise to implement a feature that you personally find annoying, if data proves it's beneficial?
Xamarin vs React Native: the complete guide
Tags: xamarin, mobile, reactnative, crossplatform
Published: 2018-07-27 16:22:01

---
title: Xamarin vs React Native: the complete guide
published: true
description: Tips for selecting the ideal cross-platform mobile development framework for your project
tags: xamarin,mobile,reactnative,crossplatform
canonical_url: http://bit.ly/2NKv4AY
cover_image: https://thepracticaldev.s3.amazonaws.com/i/49lauv08nb99amogevs6.JPG
---

We all know the benefits of building a cross-platform app over a native one. By using a cross-platform framework, we have a “2 for the price of 1” situation: developers are able to reuse code for both systems, iOS, and Android, which minimizes the project’s duration, expenses and time to market. However, there are several options for cross-platform frameworks. Have you already decided which one is the best for your product?

Two of the most popular cross-platform mobile development frameworks nowadays are Xamarin and React Native. They’ve become more known especially because of the buzzing communities of developers built around them. In order to discuss their differences and consider which technology is the best for different contexts, we gathered two developers from UruIT who are part of these communities. 

Rodrigo is a Xamarin dev, while Andrea has experience working with React Native. In this post, we list the most important aspects of a mobile software development project and what you can expect from React Native and Xamarin, based on our devs’ experience. The main conclusion that we can already tell you: there is no “best technology,” only different characteristics that can better fit one project over another. Find out which suits yours! [Read the complete Xamarin vs React Native guide here.](https://www.uruit.com/blog/2018/07/25/xamarin-vs-react-native/?utm_source=foros)
Write With Me (Day 7)
Tags: discuss, writewithme, dev, productivity
Published: 2018-07-27 16:13:22

---
title: Write With Me (Day 7)
published: true
description: Write With Me Challenge
tags: #discuss #writewithme #dev #productivity
---

I'm extremely excited that I have 7 posts now in the write with me challenge. The days were not back to back. However, this format has encouraged me to write/journal when I have something on my mind I want to talk about. 

I'm diving into Elixir with my free time lately. If you have any videos, books or tutorials you would recommend send them my way! I've been working through [Phoenix Web Development](https://github.com/PacktPublishing/Phoenix-Web-Development), and I've been enjoying it so far.  

https://github.com/PacktPublishing/Phoenix-Web-Development

Another thing I'm excited about is my boss made an announcement of a new contest Smooth Terminal is doing. This is the first contest we have held, and the prize is Exploding Rails. This Author has done some work with us before, and is a super cool guy. Checkout [Josh's post, on dev.to btw :), for more info.](https://dev.to/knewter/exploding-rails-giveaway-2k9l)

https://dev.to/knewter/exploding-rails-giveaway-2k9l


New goal is to write as often as possible and make it to at least 100 days by the end of the year.
SSH Shortcuts
Tags: ssh, linux
Published: 2018-07-27 14:51:40

---
title: SSH Shortcuts
published: true
description: Save time when using SSH by tweaking your SSH configuration!
tags: ssh,linux
---

_Originally posted at [hoelz.ro](https://hoelz.ro/blog/ssh-shortcuts)_


Let's say that you have a server you SSH into very often.  Let's also say that `sshd` on that server is running on a non-standard port to avoid annoying scanners (we'll using 53718 in this example).  To SSH into this server, you run the following:

```
  $ ssh -p 53718 rob@example-server.com
```
  
What a mouthful!  There's got to be a way to avoid typing that much!  A technique I've often seen people use is to create a shell alias for this:

```
  $ alias example='ssh -p 53718 rob@example-server.com' # in bash
```
  
So now all I'd have to do is run `example`.  Piece of cake, right?

But what if you're using `scp`?  Or `sftp`?  Or `rsync`? Or `git remote add`? Or Vim's netrw plugin?  Suddenly your simple shell alias doesn't seem so cool!

However, there is a solution to this!  Enter your SSH config file.

Your SSH config file, located at `~/.ssh/config`, can do a _lot_ of cool things.  To replicate our example above, we'd add this to our configuration:

```
Host example
  HostName example-server.com
  User rob
  Port 53718
```

Now all I need to do is `ssh example`, and voilà!  It works!  It's four characters longer than the alias, but the shortcut is applied to the following commands as well:

```
  scp example:that-important-file.txt .
  sftp example
  rsync -ar example:my-project/ .
  git remote add example ssh://example/~/my-project
  vim scp://example/that-important-file.txt
```
    
If you're interested in shortening the Git example even further, see my [blog post](https://hoelz.ro/blog/adding-remote-shortcuts-to-git) about it.

Your SSH configuration file is very powerful; I recommend checking out `man ssh_config` for more options to play with!

{{tag> ssh}}
Pattern Matching F# Union Types in C# 7
Tags: fsharp
Published: 2019-03-10 18:47:57

---
title: Pattern Matching F# Union Types in C# 7
published: true
tags: fsharp
canonical_url: https://stu.dev/pattern-matching-fsharp-union-types-in-csharp/
---

Starting with C# 7.0, there is basic pattern matching support. I want to look at using this to interop with F# Discriminated Unions, and see what consuming F# code from C# could look like at it's best.

Here is an example of an F# Discriminated Union (hereafter DU)

```fsharp
type Record = { Name: string; Age: int }

type Abc =
    | A
    | B of double
    | C of Record
```

For those unfamiliar with DUs, the `Abc` type defined above can be either `A`, `B`, or `C` (and nothing else), and in the case of `A` there is no "payload", with `B` and `C` there is a payload that comes with it.

So given that this compiles down to a sealed class, and that the cases become classes, we can use the new type pattern in C# to match this with:

```csharp
void HandleAbc(Abc abc)
{
    switch (abc)
    {
        case Abc.B _:
            Console.WriteLine("B");
            break;
        case Abc.C c:
            Console.WriteLine(c.Item.Name);
            break;
    }
}
```

There are some things to notice here:

### 1. It's really nice

The code here is clean I'd say, we are matching on type and can either ignore the result of the cast using `_` or we can take it as a named variable (like with `c` in this example).

### 2. We don't get the safety we have in F#

In F#, when handling DUs the compiler ensure that we have handled all cases, in C#, these safety checks aren't enforced.

### 3. What about case `A`!

Yeah, so this is where it's not perfect. The F# compiler does generate a type for case `A` however it is marked as internal and therefore is not accessible for us to match against, however, there are a few options, I'll let you pick which is your favourite:

```csharp
void HandleAbc(Abc abc)
{
    switch (abc)
    {
        // Option 1:
        case var x when x.IsA:
            Console.WriteLine("A");
            break;
        // Option 2:
        case var x when x == Abc.A:
            Console.WriteLine("A");
            break;
    }

    switch (abc.Tag)
    {
        // Option 3:
        case abc.Tags.A:
            Console.WriteLine("A");
            break;
    }
}
```

Let me know in the comments what your preference is, or is there a better option?

Thanks for reading!
Explain Gopher
Tags: explainlikeimfive
Published: 2018-07-27 10:56:43

---
title: Explain Gopher
published: true
description: 
tags: explainlikeimfive
---

[This article](https://lobste.rs/s/szbati/lobste_rs_mirror_on_gopher) popup on Lobste.rs and there was a small buzz about it and I couldn't understand why. Mostly because I never heard about Gopher.

Except for _this_ gopher! ;-) ![Pocket Gopher](https://m5.paperblog.com/i/12/126238/featured-animal-gopher-L-lk9X3I.jpeg)

Thank you.
Build stage on Travis CI
Tags: travis, build, deploy, ci
Published: 2018-07-27 10:55:48

---
title: Build stage on Travis CI
published: true
description: Share one benefit of the build stage on Travis CI
tags: Travis, build, deploy, CI
---

Today I found [a Travis CI blog post](https://blog.travis-ci.com/2018-07-18-build-stages-officially-released) regarding build stage on Travis CI. Now it goes GA so we all can enjoy this feature.

Here is [the my PR to introduce build stage](https://github.com/KengoTODA/findbugs-slf4j/pull/118/files). In my feeling, it has one good point:

## No more `if` in analysis and deploy part

When I run analysis like [SonarCloud](https://sonarcloud.io), it was necessary to limit target JVM & environment variable to make PR page easy to read. For example, here is a `.travis.yml` snippet that runs analysis only with specific condition:

```yml
jdk:
  - oraclejdk8
  - oraclejdk9
script:
  - ./mvnw org.jacoco:jacoco-maven-plugin:prepare-agent verify -B
  - if [[ $TRAVIS_JDK_VERSION == "oraclejdk8" ]]; then ./mvnw sonar:sonar -B; fi
```

In case of build stage, script runs with the first value in `env`, `jdk` and others by default. So we can remove `if` from `.travis.yml`:

```yml
jdk:
  - oraclejdk8
  - oraclejdk9
script:
  - ./mvnw verify -B
jobs:
  include:
    - stage: analysis
      script:
        - ./mvnw org.jacoco:jacoco-maven-plugin:prepare-agent verify sonar:sonar -B
```

One point, is that, each build stage and job doesn't share generated files. So here we need to run `verify` phase even in `analysis` stage, to generate analysis targets (`.class` file in this case).

This merit works even to [deploy](https://docs.travis-ci.com/user/deployment) phase. This feature should reduce complexity in our `.travis.yml`.


That's all. Enjoy hacking with Travis CI!
What are Your Best Practices for Writing React Code
Tags: discuss, beginners, react
Published: 2018-07-27 10:35:01

---
title: What are Your Best Practices for Writing React Code
published: true
description: 
tags: #discuss #beginners #react
---

React JS has lot of complexity in terms of concept for beginners. And there multiple ways of doing things. I am sure all of us have different approach to writing code, testing it and deploying it. 

So my question is for those who have set some flow or process for react projects. 

What are some of the practices that you follow while working on react project?
Inheritance over composition
Tags: discuss
Published: 2018-07-27 09:41:47

---
title: Inheritance over composition
published: true
tags: discuss
---

More often than not, I hear statements like „favor composition over inheritance“. I think there are valid uses of inheritance, so once again, it depends on context (let‘s ignore deep inheritance hierarchies, I hope we all agree that is usually a bad idea).

What are your experiences? Have you experienced situations where inheritance was really useful?
Why I used Docker?
Tags: docker, linux, container
Published: 2018-07-27 09:36:08

---
title: Why I used Docker?
published: true
description: Collection of answers from a couple of friends on why they use Docker
tags: docker, linux, container
---

A topic came up in my private telegram group on why we use Docker, so I'll just pasting back some of the answers here.

AC: Why Docker ? (because docker is just an additional layer of complexity, and only helps when you're doing a lot of things repeatedly, at scale. Otherwise, it's just a disk space sink). What do you wanna do with docker?

AS: It can be "Just because" guys... I dockerized my vim so from any pc I use I can have same plugins and everything. Like 60 MB compressed image and 130 uncompressed. But that's because I compiled vim with huge flag and threw in python perl lua and ruby otherwise it's much much smaller. My base vim with big feature flag is only 30MB uncompressed.

AC: The reason why "Why Docker?" is asked is to ensure you can see the benefit in containerizing your use case. Otherwise it's just so much more painful.

https://alysivji.github.io/php-mysql-docker-containers.html is already a good start. (He used Docker 'coz he don't wanna hunt down and install PHP-7.2 just for running/testing wordpress).

K: We're python shop so no proper php env. But sometimes customer come with their php script for help, so docker is the easiest to quickly test the script.
How to run Lighthouse on Travis CI
Tags: yaml, tools, sauselabs, script
Published: 2018-07-27 08:12:31

---
title: How to run Lighthouse on Travis CI
published: true
description: We look into lighthouse testing on Tracis CI and SauceLabs.
tags: yaml, tools, sauselabs, script
---

{% youtube 82SVcPFIVQI %}
My Windows 95 Story
Published: 2018-07-28 03:19:27

---
title: My Windows 95 Story
published: true
tags: 
canonical_url: https://www.geekytidbits.com/my-windows-95-story/
---

I was cleaning out one of my drawers today and came across this old gem.

![Windows 95 CD-ROM](https://www.geekytidbits.com/media/windows-95.jpg)

The day was Thursday, August 24, 1995. I had been anticipating this day for months. Microsoft brochures, geek buzz in AOL chatrooms, and chatter with my friends made me unable to wait to get my hands on a copy of Windows 95.

Since I was fifteen years old and unable to drive, my mom dropped me off at CompUSA around 8AM so I could be in line for the 9AM store opening. The line was already wrapped around the building. In line, I chatted with some folks about nothing other than Windows 95 and we gave our thoughts on it. Some people were skeptical and fearing Microsoft was moving in the direction of Apple where settings were abstracted and you had less control. Others had nothing but excitement for the world’s newest operating system. My opinion was somewhere between these extremes.

Once I finally made it inside the store and grabbed my Windows 95 _uprade_ box, I headed for the cashier line and prepared to pay the $109.95 (plus tax) price tag. I had been mowing lawns to save up for this important purchase. That was a lot of money for me but I didn’t think twice about it.

My mom came back and got me around 9:30 and when we got home I popped the CD in my Unisys 386 computer and started the installation process. It took for what seemed like forever but once it installed and booted, I was ecstatic. The interface was clean, fresh, and it felt so much more advanced than Windows 3.1.

It didn’t take too before I discovered and kicked back to watch the 2 music videos on the installation CD: [Edie Brickell - Good Times](https://www.youtube.com/watch?v=iqL1BLzn3qc) and [Weezer - Buddy Holly](https://www.youtube.com/watch?v=ApN2eLI4d-4).
Need ideas for call captioning app
Tags: discuss, opensource
Published: 2018-07-27 07:03:20

---
title: Need ideas for call captioning app
published: true
description: 
tags: #discuss #opensource
---

Do we have real-time call-captioning app for people with hearing issues? There are third-party providers for landlines but I have not heard of any such app. Ideally, a person should be able to call anyone who speaks English and the app should display text of what is being said in real-time.

I have tried using Skype Translator but it is too slow. I would like something like YouTube captions - they are machine-generated, fast, and (almost) accurate.

If there is no such app, we can try building it together. I'd love to have some collaborators for this project. Hit me up with ideas folks!