teleren/devto huggingface dataset:
Rust existential type
Tags: rust, existential, trait
Published: 2019-07-19 11:08:09

---
title: Rust existential type
published: true
description: Rust existential type
tags: rust, existential, trait
---

最近在封装一点lib，本来想在trait里面定义async fn的，但是目前来说是不允许的.[Async Methods I: generic associated types](https://boats.gitlab.io/blog/post/async-methods-i/)，只能想其他办法咯，那我们就再调用async fn返回个future吧，也一样的。

然后问题又来了，本来想是return 一个 impl Future，但是。。。trait里面又不允许，sad！

[Async Methods I: generic associated types](https://boats.gitlab.io/blog/post/async-methods-i/)这里也解释了为什么直接associated types不行。

原因就是async返回的Future是个闭包，把所有东西的lifetime都丢进去了，如果我们要写associated types需要这样:
```rust
trait Foo {
    type _Future<'a>: Future<Output = i32> + 'a;
    fn foo_method<'a>(&'a self) -> Self::_Future<'a>;
}
```
但是呢。。。问题又来了，目前associated types不支持lifetime参数，这个东西叫[generic associated types](https://github.com/rust-lang/rfcs/blob/master/text/1598-generic_associated_types.md)


不过还好，我们还有existential type，参考[RFC](https://github.com/rust-lang/rfcs/blob/master/text/2071-impl-trait-existential-types.md)

```rust
#![feature(async_await, existential_type)]

use futures::compat::Future01CompatExt;
use futures::compat::Stream01CompatExt;
use futures::future::{FutureExt, TryFutureExt};
use futures::stream::{StreamExt, TryStreamExt};
use futures::Future;
use reqwest::r#async::{Client, ClientBuilder, Decoder};
use std::io::{self, Write};

trait Fuck {
    type AsyncResult: Future<Output=()>;
    fn download(&self) -> Self::AsyncResult;
}

struct Down;

impl Down {
    pub fn new() -> Self{
        Down{}
    }
}

impl Fuck for Down {
    existential type AsyncResult: Future<Output=()>;
    fn download(&self) -> Self::AsyncResult {
        download()
    }
}

async fn download() {
    let client = ClientBuilder::new().build().unwrap();
    let res = client
        .get("https://dev.to/x1957/rust-async-await-2l4c")
        .send()
        .compat()
        .await;
    let mut body = res.unwrap().into_body().compat();
      while let Some(next) = body.next().await {
        let chunk = next.unwrap();
        io::stdout().write_all(&chunk).unwrap();
    }
    println!("\nDone");
}

fn call<T: Fuck>(x: T)->T::AsyncResult {
    x.download()
}

fn main() {
    // let fut = download().unit_error().boxed().compat();
    let fut = call(Down::new()).unit_error().boxed().compat();
    tokio::run(fut);
}

```
我们定义了Fuck这个trait里面有个associated type AsyncResult，在我们impl这个trait的使用通过existential type来指出AsyncResult是impl Future的即可。

现在使用的时候需要打开feature existential_type
From Cat to Hat
Tags: communities, freelibreopensources, redhat
Published: 2020-10-06 14:57:07

---
title: From Cat to Hat
published: true
date: 2019-07-19 10:54:39 UTC
tags: Communities,FreeLibreOpenSourceS,RedHat
canonical_url: 
---

On June I joined Red Hat as a Senior Software Engineer. I always said that I preferred to work on a small company before a big company, because on a big company you can’t be anything more than a number. That you can’t really grow professionally if you are such a small piece on a … [Continue reading "From Cat to Hat"](http://delawen.com/2019/07/from-cat-to-hat/)

The post [From Cat to Hat](http://delawen.com/2019/07/from-cat-to-hat/) appeared first on [Délawen](http://delawen.com) written by [María Arias de Reyna Domínguez](http://delawen.com/author/delawen/).
Friday Blast #75
Tags: fridayblast, links, post
Published: 2019-07-22 05:40:50

---
title: Friday Blast #75
published: true
tags: friday_blast,links,post
canonical_url: https://horia141.com/friday-blast-75.html
series: "Friday Blast"
---

[TensorFlow.js - machine learning for web and beyond (2019)](https://blog.acolyer.org/2019/02/04/tensorflow-js-machine-learning-for-the-web-and-beyond/) - an overview of the TensorFlow.js paper. It’s pretty impressive how this can handle both training and inference in JS via WebGL! It uses “old timey” tricks of expressing non-graphics code in terms of shaders and graphics operations and the performance is quite decent! Seems like the abstraction layers between JS and the GPU aren’t that big!

[Sven myths in machine learning research (2019)](https://crazyoscarchang.github.io/2019/02/16/seven-myths-in-machine-learning-research/) - this was quite an interesting read, though it does conflate ML with Neural Networks. What was interesting was the “every datapoint is used in training a neural network” myth and how it relates the approaches of SVMs and NNs with regards to exploration of the input distribution. Namely, both _kinda_ focus on interesting examples, usually near the edge of the decision boundary or surface which is being estimated.

[Supercookies (2019)](https://www.johndcook.com/blog/2019/02/08/supercookies/) - an overview of “other tracking” methods, beside regular cookies. John D Cook has spent some time on this topic, but suffice to say, we’re pretty trackable regardless of whether cookies are enabled or not.

[A brief history of AWS architectures (2019)](https://cloudonaut.io/a-brief-history-of-aws-architectures/) - where is your company stuck? In any case, I’m curious how many folks have used the big “container” or “serverless” offerings from AWS at scale. I’ve had mixed results with some of their offerings which seemed magical - loads of bugs, loads of not-intuitive performance behaviours. It’s understandable when folks are loath to switch over from their _known but flawed_ systems to the _unknown and flawed_ ones.

[AWS costs every programmer should know (2019)](https://david-codes.hatanian.com/2019/06/09/aws-costs-every-programmer-should-now.html) - really cool synthesis of the AWS pricing page. Focuses on basic compute (which at it’s cheapest is 30$/month for one modern CPU with 4 cores), storage, bandwidth and memory. This about covers it, since many other services are expressed in terms of these basic units!
Does any of you know someone worthy of being followed?
Tags: discuss, javascript, webdev, react
Published: 2019-07-19 10:39:56

Long time, no see, fabulous [Dev.to](https://dev.to) community!

Today I've removed the dust that set over my old and unused [Twitter account](https://twitter.com/alvpopa) and I want to enrich it with relevant people. Coming from a country where this social media platform is not that relevant, it didn't take a lot until I totally forgot about it.

I couldn't help myself to see that dev community is quite active on Twitter. Trying to find some accounts worthy of being followed and since I didn't find any good source of this kind of information, why not empower the community and create one right here?

That being said, I want to give a shout-out to each one of you and I kindly ask everybody to share with me the devs/accounts that you're following. I'm mostly interested in Twitter, but LinkedIn profiles are highly appreciated also.
Quick Tour Of Generics In C#
Tags: csharp, deepdive, nuggets
Published: 2019-07-19 10:30:09

Generics have been around since C# 2.0 and has become a tool we leverage so naturally now in C# we almost don't even think about it. So let's change that...

### Definitions

_Generics introduce to the .NET Framework the concept of type parameters, which make it possible to design classes and methods that defer the specification of one or more types until the class or method is declared and instantiated by client code_. 

Essentially generics allow you parameterize types and methods. Just as normal methods have *parameters* to tell them what *values* to use, generic types and methods have *type parameters* to tell them what *types* to use. 

### Clarification

Type parameters are placeholders for a type.

There are *constructed types* and *generic types*.
A constructed type is when the type arguments are specified. For example, 
```
Dictionary<int, string>()
```

A generic type is when the type arguments are not specified. For example,
```
Dictionary<TKey, TValue>()
```

As per the code snippet below, writing a method to swap two _Integer_ values is pretty rudimentary. But what if later we needed to do the very same but with _Strings_. This would result in two methods, or perhaps overloads.

{% gist https://gist.github.com/daneb/13124e5ec2369117aff8fc27a3a861e5 %}

Generics to the rescue. We've isolated the type as a form of abstraction (`T`) to act as a placeholder for the type we intend to use.

{% gist https://gist.github.com/daneb/9ab19f0a644a3e79525f932e4e34cd5f %}

When the method is actually called, that placeholder is replaced with the type of the values used.

{% gist https://gist.github.com/daneb/f318890ecb9849ced43bccfe86744093 %}

The value of Generics here is that it grants you _productivity_ improvements, _expressiveness_ and moves some safety concerns from _execution time to compile time_.

Note the two ways in which the _method_ can be called. One with the type explicit, and the other implicit through _type inference_. The compiler is inferring the *type parameters* based on the method arguments you pass.

A *generic* is simply a placeholder for a type.
Nestjs-i18n
Tags: nestjs, javascript, fastify
Published: 2019-07-19 09:50:34

Hello guys!
if you bumped into trouble into getting the client language, I prepared [the solution](https://github.com/sergey-telpuk/i18n-nestjs) to allow grabbing the language of the current user (i.e., the client that is interacting with the API).
Electron brings the web to native, but is there anything that goes the other way around?
Tags: discuss
Published: 2019-07-19 09:46:04

I've been thinking about Electron performance issues on low-end computers, and it got me thinking: Are there any native UI libraries or frameworks that have been ported to the web? GTK+ had Broadway, but that had the app running on a server and sending the UI to the client, instead of the app running on the client itself.
Top 10 Commonly Used HTTP Status Codes
Tags: http, statuscodes, api, rest
Published: 2019-07-19 09:28:09

---
title: Top 10 Commonly Used HTTP Status Codes
published: true
description: All top ten commonly used and useful status code
tags: #HTTP #statuscodes #API #REST
---
HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped into five classes: informational responses, successful responses, redirects, client errors, and server errors. 

Here are the 10 commonly used and useful HTTP status codes:

## 1xx: Informational
_`None in this class.`_

## 2xx: Success
#### 200 OK
It is the general status code. Most common code used to indicate success.
The request has succeeded. The meaning of success varies depending on the HTTP method:
**GET:** The resource has been fetched and is transmitted in the message body.
**HEAD:** The entity headers are in the message body.
**PUT or POST:** The resource describing the result of the action is transmitted in the message body.
**TRACE:** The message body contains the request message as received by the server
#### 201 Created
Successful creation occurred (via either POST or PUT). Set the Location header to contain a link to the newly-created resource (on POST). Response body content may or may not be present.
#### 204 No Content
Status when wrapped responses are not used and nothing is in the body (e.g. DELETE).

## 3xx: Redirection
#### 304 Not Modified
This is used for caching purposes. It tells the client that the response has not been modified, so the client can continue to use the same cached version of the response.

## 4xx: Client Error
#### 400 Bad Request
General error when fulfilling the request would cause an invalid state. Domain validation errors, missing data, etc. are some examples.
#### 401 Unauthorized
The error code response for missing or invalid authentication token.
#### 403 Forbidden
The error code for a user not authorized to perform the operation or the resource is unavailable for some reason (e.g. time constraints, etc.).
#### 404 Not Found
 Used when the requested resource is not found, whether it doesn't exist or if there was a 401 or 403 that, for security reasons, the service wants to mask.
#### 409 Conflicts
Whenever a resource conflict would be caused by fulfilling the request. Duplicate entries and deleting root objects when cascade-delete is not supported are a couple of examples.

## 5xx: Server Error
#### 500 Internal Server Error
The general catch-all error when the server-side throws an exception.
While vs for
Tags: typescript, javascript, loops, indexof
Published: 2019-07-19 09:05:27

---
title: While vs for
published: true
description: battle of loops
tags: typescript, javascript, loops, indexOf
---

This is a fun little story. A few months ago I wrote the following function, due to a need to get the index of a specific occurrence of a character (exclusive mode, by which I mean position you are passing is not part of the search) within a stream (yes, stream). Basically its being used to do a small validation on every message that is coming in from an EventSource.

While writing the function, I didn't give much thought. I wrote 3 unit tests, I then wrote the function and didn't give much thought.

```typescript
 private getNthIndex(text: string, delimiter: string, occurrence: number, position: number):number {
    while (occurrence-- && position++ < text.length) {
      position= text.indexOf(delimiter, position);
      if (position < 0) break;
    }
    return position;
  }
```
Then a fellow team member had a ticket to change something around that area. When running into that function, they told me that it was entirely confusing and it needed a bit of a thought to understand it properly, and whether if I mind, if it got refactored. 

It has been nearly 9 months since I wrote that, and because it did took me a couple of minutes to remember why I did it like that, I agreed that if a more readable version is possible, obviously I would welcome it.

So they came up with the following

```typescript
 private getNthIndex(text: string, delimiter: string, occurrence: number, position: number):number {
    for (let i = 0; i < occurrence; i++) {
      position= text.indexOf(delimiter, position+ 1);
      if (position < 0 || position>= text.length) break;
    }
    return position;
  }
```

In my eyes, they are nearly identical and of the same level of readability. There are only two small changes the `while` loop is now a `for` loop, and fact that the counter goes up instead of going down.

So, just for the fun of it, I post it on the `dev channel` to ask about opinions and weirdly I realised that some developers are really suspicious of while loops and that `for` loops are easier to read than `while` loops.

I lost 6 to 1 :tada:
How to Drive Quality and Targeted Traffic to Your Website? (New Tips)
Tags: targetedwebtraffic, targetedwebsitetraffic, purchasetargetedtraffic, targetedvisitors
Published: 2019-07-19 09:01:03

If you want to make an Ideal Deal in the online market then you may need website traffic. To make your brand popular, you can to buy targeted website traffic. This is genuine traffic for your website.
https://trafficyupp.blogspot.com/2019/07/buy-targeted-website-traffic.html

#websitetraffic #audience #onlinebussiness #SEOstrategy
Visual Form Builder in 200 lines of code
Tags: javascript, npm, wordpress
Published: 2019-07-19 11:33:19

---
title: Visual Form Builder in 200 lines of code
published: true
tags: javascript,npm,wordpress
canonical_url: https://medium.com/tripetto/visual-form-builder-for-contact-form-7-5024fd41c872
---

Next level editing for the most popular form plugin of WordPress

![](https://cdn-images-1.medium.com/max/1024/0*Et_X8ccgf769lqsC)<figcaption>Photo by <a href="https://unsplash.com/@peter_mc_greats?utm_source=medium&amp;utm_medium=referral">Pietro De Grandi</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption>

### Every website has a contact form

When you have been involved with WordPress websites, you have likely come across the [Contact Form 7](https://wordpress.org/plugins/contact-form-7/) plugin. It is — by far — the most successful form plugin for WordPress, with more than 5 million installations! Imagine how many contact forms are filled in right now?

One of the reasons this plugin is so succesfull is that it just get’s the job done. No nonsense. People want simple contact forms and that’s what this plugin gives them.

### Editing like it’s 2009

But if I have to be critical, the editor in Contact Form 7 is pretty outdated.

![](https://cdn-images-1.medium.com/max/502/1*OanwKuLWChtcYX_ptFhlOQ.png)<figcaption>Contact Form 7’s HTML markup editor in action</figcaption>

A couple of drawbacks of the editor:

- No drag and drop of fields
- No editing of fields via the Generate tag tool
- No syntax checking

### Editing like it’s 2020

To make the lives of all the Contact Form 7 users a little easier and more fun, we’ve come up with a free alternative for this old fashioned user experience.

A brand new visual form builder for Contact Form 7!

![](https://cdn-images-1.medium.com/max/1024/1*au_hfpIsJzqm1BJboNIHqw.png)<figcaption>Visual Form Builder for Contact Form 7</figcaption>

Create your Contact Form 7 forms like you’ve never done before. Using features like:

- Move fields with drag and drop
- Change the type of a field
- Add, edit and delete fields via intuive UI
- Don’t worry about the syntax anymore!

The Contact Form 7 code is updated real-time in a panel next to the editor. Grab this code and paste it back into Wordpress. No extra plugins required. No hassle.

### Show me the magic

Try the editor in CodePen directly. For free. 🧙‍♂️

{% codepen https://codepen.io/tripetto/pen/mNbJZj %}

Feel free to check out the code. Please let me know if you like it!
20 Best IDE of 2019 by Programming Language
Tags: html, javascript, css
Published: 2019-07-19 07:40:50

Tools That Are Guaranteed to Help You Excel

If you are new to web development, you may think that the basic notepad is the best tool for creating websites of any complexity. Many pros, however, would call that a big mistake. While you might be able to make it work, it would require a lot of unnecessary coding and time that could be used for other more important tasks. There are a lot of different types of IDE available online that can help you with this process, but it may be quite hard to choose one from such an extensive variety. So, that brings us to the question … what is the <a title="best IDE for web development" href="https://www.goodcore.co.uk/blog/best-ide-for-web-development/">best IDE for web development</a> that you could choose?

If you are struggling with choosing the right development software for your project, then we have some solutions for you right here. We recommend that you go for an IDE that will save you from having to manually eliminate typos and errors, increasing your productivity and saving time for developing your idea further.

We have prepared a comprehensive comparison of 20 different integrated development environments for you to consider their pros and cons and choose the one that will serve you best.
Learn 7 Basics of Java Programming to Start Coding Today
Tags: java
Published: 2019-07-19 07:30:47

I probably don’t need to tell you that without mastering basics in Java or any programming language, you cannot do coding efficiently.

Whether you are a recent graduate who is looking to learn a major programming language like Java or an experienced programmer who wants to increase the potential for future career growth, having a solid knowledge of basic concepts of Java is must.  Java is an easy programming language for one who has paid attention to the basics, however, it can be equally frustrating for one who tries to take the shortcut.

If any of the above points sounds familiar, I have a great news: There are 7 basics concepts of Java which can help you to start coding better right today. You can also find a list of Java online courseswhich will cover these basics concepts and their application in detail. Let’s get started with our discussion….
Click here to continue: https://blog.simpliv.com/learn-7-basics-of-java-programming-to-start-coding-today/
Top 50 PHP Blogs And Websites for PHP Developers To Follow in 2019
Tags: php
Published: 2019-07-19 07:29:56

PHP Blogs List.
The Best PHP blogs from thousands of top PHP blogs in our index using search and social metrics. Data will be refreshed once a week. Also check out Top PHP Youtube Channels list for Top videos on PHP.
1. Planet PHP Blog

Planet PHP Blog

About Blog Planet PHP Blog covers all PHP news in one place. A close to complete list of all important PHP related weblogs.
Frequency about 8 posts per week.
Blog planet-php.net
Facebook fans n/a. Twitter followers 63,700.View Latest Posts ▸
2. Reddit – PHP: The latest news in the PHP world

Reddit - PHP: The latest news in the PHP world

About Blog Ask questions about frameworks, try your hand at php golf and strike gold or simply show off your latest work.
Frequency about 56 posts per week.
Blog reddit.com/r/PHP
Facebook fans 1,285,479. Twitter followers 629,358.View Latest Posts ▸
3. The Zend Blog

The Zend Blog

About Blog Read the latest PHP trends and best practices in the world of cloud, mobile and web application development on the Zend blog, featuring thought leaders from the PHP community
Frequency about 2 posts per month.
Blog blog.zend.com
Facebook fans 51,466. Twitter followers 47,715.View Latest Posts ▸
4. PHP Classes Blog

PHP Classes Blog
 click here to continue: https://simpliv.wordpress.com/2019/07/19/top-50-php-blogs-and-websites-for-php-developers-to-follow-in-2019/
About Blog Follow PHPClasses for early insights about upcoming site features. Free ready to use contributed PHP class scripts, book reviews, jobs, specialist forums.
Frequency about 1 post per week.
Blog phpclasses.org/blog
Facebook fans n/a. Twitter followers 47,690.View Latest Posts ▸
Hire Android App Developer USA | Android App Development Company 
Tags: hireandroidappdeveloperusa, androidappdevelopment, androidappdevelopmentservices
Published: 2019-07-19 06:42:24

---
title: Hire Android App Developer USA | Android App Development Company 
published: true

description: Hire Android app development company, IPHS Technologies is one of the top listed mobile app development company offers the best app development services in India, USA.  IPHS Technologies offers various types of <a href="https://iphtechnologies.com/android-app-development">android app development</a> services, experience developer which works on the latest technology with a successful cost-effective mobile app development services. 

tags: Hire Android App Developer USA, Android App Development, Android App Development services  
---