teleren/devto huggingface dataset:
Sending e-mails from Cloudflare Workers
Tags: serverless, javascript
Published: 2020-08-17 20:42:31

In most serverless environments, [Cloudflare Workers](https://workers.cloudflare.com/) included, you can not send e-mail through SMTP. Also, many client SDKs for providers such as Mailgun or Sendgrid assume you are on the Node platform and will not work in many serverless runtimes. Luckily most providers also provide a REST API to send e-mail.

I ended up going with Mailgun, below is some example Typescript code that works in Cloudflare Workers.

```typescript
declare const MAILGUN_API_BASE_URL: string;
declare const MAILGUN_API_KEY: string;

export interface EmailData {
    from: string;
    to: string;
    subject: string;
    text: string;
    html: string
    cc?: string;
    bcc?: string;
    "h-Reply-To"?: string;
    "o:testmode"?: boolean;
}


function urlEncodeObject(obj: {[s: string]: any}) {
  return Object.keys(obj)
    .map(k => encodeURIComponent(k) + "=" + encodeURIComponent(obj[k]))
    .join("&");
}


export function sendMail(data: EmailData) {
    const dataUrlEncoded = urlEncodeObject(data);
    const opts = {
        method: "POST",
        headers: {
            Authorization: "Basic " + btoa("api:" + MAILGUN_API_KEY),
            "Content-Type": "application/x-www-form-urlencoded",
            "Content-Length": dataUrlEncoded.length.toString()
        },
        body: dataUrlEncoded,
    }

    return fetch(`${MAILGUN_API_BASE_URL}/messages`, opts);
}
```

You will have to set the global environment variables `MAILGUN_API_BASE_URL` and `MAILGUN_API_KEY` for your worker script using wrangler. The API base url can be put in the environment variables, `MAILGUN_API_KEY` should be added as a secret which you can do using the wrangler cli:

```
wrangler secret put MAILGUN_API_KEY
```

It will prompt you for the secret value afterwards.
Visualising documentation: JavaScript array.filter
Tags: javascript, beginners, tutorial, codenewbie
Published: 2020-08-17 20:39:59

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/h9waxenfyaouvdq1n80o.jpg)

Most days, for a few weeks, I’m aiming to sketch core JavaScript array functions.

This series [began on medium](https://medium.com/@charlottebrf) and moves over here :)

Today’s function is array.filter(), mdn description [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter). Filter creates a new array with all the elements which meet the requirements for the test function.

Here’s my own version of the rewritten core docs & the sketches together. [Here’s the folder for array.filter](https://github.com/cfereday/javascript-core-functions/tree/master/arrays/do%20not%20mutate/returns%20a%20new%20array/filter). Check out the [readme](https://github.com/cfereday/javascript-core-functions/blob/master/README.md) to see how you can run the examples.
Hello, world! I'm James :)
Tags: react, javascript, html, css
Published: 2020-08-17 20:25:10

## It's nice to meet you

[www.jamescox.dev](https://www.jamescox.dev/)

Being my first post, I thought it would be fitting to share my newly-hosted portfolio site, made from scratch with React, Material UI, HTML and CSS. 

I have been coding for 3 years now, and graduated from Flatiron School this past March. I recently moved to Austin, Texas with my wife and daughter, and looking for my first dev role.

## What will I post?

* highlighting tough challenges and how I overcame them
* specific obstacles that aren't well-documented
* coding, networking and looking for a job during a pandemic
* my take on other developers' posts, projects, insights
* my own projects with specific code examples
* whatever else I am inspired to share

## About me

I'm 36 years old and do not have a technical background. I graduated from University of Memphis in 2008 with an English degree, but found myself progressing in the restaurant industry, eventually ending up in management. After 10 plus years of working in kitchens and dining rooms from Memphis to Nashville, Tennessee I was BURNT OUT. I needed a change. I had no idea what I wanted to do. 

Flatiron School fell into my lap in late 2018, and after taking a couple of their free prep courses, I WAS HOOKED. I still had no idea what being a "developer" really meant, but once I saw things I coded alter what I saw on my computer screen, I wanted to know more. No, I wanted to know it ALL.

A year and a half later I turned in my final project (check out [Memes Vs Gif](https://memes-vs-gifs.netlify.app/), a Meme and Gif generator) and I was a Flatiron graduate!

Since then I have been consistently creating new projects and honing my chops. 

## My favorite project

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/dd0tdis3w9ivvh9fwbos.png)

[GIF FIT](https://gif-fit.netlify.app/), is a home workout app I designed to help with the challenges of COVID-19 and quarantine. After a few weeks of use, I already notice a huge improvement in my own fitness!

I learned so much building this app: using more React hooks, integration of a React component library, Material UI, better Redux design, strengthening my understanding of reusable components, and discovering my LOVE/HATE relationship with setTimeOut() and setInterval() 

(Also, can we talk about how AWESOME the useEffect() hook is????) 

## Wrapping up

If you made it this far, THANK YOU for reading my first post. I hope you will connect with me. If I can learn from you, I will! And if you can learn something from me, I hope I help you in your own journey.

Follow me on Twitter, [@MemRook](https://twitter.com/MemRook)

Connect with me on LinkedIn [James Cox](https://www.linkedin.com/in/jamesnathanielcox/)

I can't wait to meet all of you!
🚀 How to add Themis crypto-library to your app with 1 line of code
Tags: tutorial, security, cryptography, programming
Published: 2020-08-17 20:10:56

> True true true. Using encryption correctly could be so super-easy, even if you are not a cryptographer.

With innovative teams in mind, we thought of an effective data protection solution **which would not hinder their apps development process**. And this is how high-level “boring” cryptographic open-source library [Themis] (https://github.com/cossacklabs/themis) turned into reality 5 years ago. 

Compared with other cryptographic libraries, Themis has ready-to-use blocks ("crypto-systems") that are designed to solve your use case ("encrypt data for storage") instead of getting you bogged down with crypto parameters.

###You can add Themis to your app with 1 line of code.

![Get a high-level solution made by cryptographers to developers] (https://media.giphy.com/media/cNfIqjpCY1zqfaLmd8/giphy.gif)
 
So, 
 
> to start using Themis for mobile and web platforms, install [Themis language wrapper] (https://docs.cossacklabs.com/themis/installation/installation-from-packages/#installing-themis-language-wrappers) for language you’re using in your application (Swift, Objective-C, Kotlin, Java or JavaScript for WebAssembly).
 
Example for iOS app that uses CocoaPods, just add 1 line to your `Podfile` like this: 
 
`pod 'themis'`
 
and then update or install your pods:

`pod install`

That is all.
 
💡 Now you installed the library that solves 90% of typical data protection use cases common for most apps.
 
*PS:* installing Themis for [server-side and desktop platforms] (https://docs.cossacklabs.com/themis/installation/#server-side-and-desktop-platforms) (Go, Python, Ruby, PHP, Java, JavaScript (for Node.js), Rust, C++, C) takes no long way too. Just install the core library for your OS, then install Themis language wrapper for your language. 
 
Check out [docs and examples] (https://docs.cossacklabs.com/themis/#use-cases-that-themis-solves) to learn how to use your freshly obtained crypto-powers for good.
 
**Easy-to-use and hard-to-misuse.** 🚀 Now just focus on your app.✨

![Themis takes on data security, and you can just focus on your app](https://media.giphy.com/media/MGdfeiKtEiEPS/giphy.gif) 
***
###More resources you can be interested in:
- [Themis on GitHub] (https://github.com/cossacklabs/themis)
- Themis documentation on [CossackLabs' DocServer] (https://docs.cossacklabs.com/themis/)
- Blogpost [Swift way to build OpenSSL for Carthage iOS, as we did it for Themis] (https://www.cossacklabs.com/blog/openssl-for-carthage-for-themis.html)
Http Status Codes 
Tags: 100daysofcode, javascript
Published: 2020-08-17 19:53:32

Sending status codes has become a matter of course in this backend journey. But when do i send a 401 and when do i send a 404? 
Today I'll be looking at http status codes. A http status code is a response by the server on the state of a request. Http status codes are divided into 5 major categories 
1. Informational responses: 100–199
2. Successful responses: 200–299
3. Redirects: 300–399
4. Client errors: 400–499
5. Server errors: 500–599

There's a whole list on each of the categories in [MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) and [httpstatuses.com](https://httpstatuses.com/). 
Here is a list of the status codes I've come across so far.
200 - Ok
201 - Resource Created 
204 - No Content
400 - Bad request
401 - Unauthorized
403 - Forbidden. The client is known but has no access rights
404 - Not found
500 - Internal Server error

Having learnt that i adjusted the code to send a 401 when a client is unauthorized. I'll try and use the relevant status codes from now on wards.

_End of Day 32_
You should speak at a conference this year
Tags: cfp, career, speaking, beginners
Published: 2020-08-17 19:52:17

---
title: You should speak at a conference this year
published: true
description: New Relic's nerd days CFP is open and you should apply to it, speak about observability, the serverless space, cloud hosting, or any other web dev talk that interests you.
tags: cfp, career, speaking, beginner
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/bwj78on4brpw8j7gek1v.jpg
---
_cover image: Painting on the east wall of the north bay of central audience hall of Chehel Sotoun Palace, Isfahan, Iran_

You should speak at a conference. 

I mean *you* specifically. I didn't write this for someone else.

Not enough experience? Balderdash, speak about how you're getting started and questions you still have.

Haven't done public speaking before? Good news the conferences are online now, hide the chat and pretend you're monologuing alone.

Someone else could do it better? I guarantee audiences are tired of hearing from the same 5-10 speakers in a given field. And most of the smartest, most interesting speakers never give talks at all because they lack time or motivation to  do it.

So I'm saying you should do it. 


There are *so* many open CFP's, google "[programming language] cfp" and I guarantee you half a dozen events are desperate for more submissions.

First time speakers are a prized get for organizers. You have a point of view no one has heard. Go share it!

My team at New Relic [has an open CFP right now](https://blog.newrelic.com/product-news/nerd-days-2020-call-for-proposals/). DM me on twitter or comment below if you'd like help with a first pitch:

<blockquote class="twitter-tweet"><p lang="en" dir="ltr">Mutuals, if you&#39;d like to talk at this let me know and I will help! <a href="https://t.co/SNEF9u7z4I">https://t.co/SNEF9u7z4I</a></p>&mdash; Nočnica Fee (@ServerlessMom) <a href="https://twitter.com/ServerlessMom/status/1295440414183264256?ref_src=twsrc%5Etfw">August 17, 2020</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
MLOps Tutorial 🎦: Track models with Git & GitHub Actions
Tags: tutorial, git, machinelearning, datascience
Published: 2020-08-17 19:47:14

Did you know you can use Git to keep track of your ML models? Yes, you can use Git to snapshot your project at many stages of development! Then with GitHub Actions, you can take your work to the next level by automating repetitive processes like model training and reporting. I'm creating a video series to help people take advantage of these software tools for data science and ML. 

{% youtube xPncjKH6SPk %}


One of the big ideas around Git is to use branches to develop new features. In data science, this can look like using new branches to try out new modeling approaches or ways of processing data. So today I've released a new video tutorial about a frequent question:

_How do I compare ML models on different Git branches?_

The answer (and the video!) goes a little more in-depth than you might expect. There's an easy approach, and then there's a good approach.

**Easy answer.** If your model training and evaluation scripts creates a metric file- say, `metrics.csv`- then you could use

`$ git diff metrics.csv`  

**Good answer.** So you can do a `git diff` of your metrics file, but aside from being a little hard to read, there's another issue:

What if `metrics.csv` is modified by different processes on different branches?

For example, on the `main` branch of a project, I might run a script `train.py` that creates `metrics.csv`. But there's no guarantee that on a feature branch, I or a teammate will keep `train.py` and `metrics.csv` "in-sync". A few scenarios:
* Someone manually updates `metrics.csv` on their branch
* Someone changes `train.py` but forgets to re-run it, so `metrics.csv` is never re-generated
* Someone modifies `train.py` on a feature branch to output a reformatted file (`metrics.json` instead of `.csv`, perhaps), or to output an entirely different file (`score.csv`). 

To avoid these kinds of errors, we need to make sure that our metrics file is tightly linked to the processes that produced it (and any other processes it depends on, like standardizing data).

So long story short- I set out to make a video about how to do something like a `git diff` for model metrics and then report it in a Pull Request with GitHub Actions. But I ended up telling a longer story about why and how to use ML pipelines to ensure that your model metrics are reproducibly regenerated on every branch of your project. It got bigger than I expected but I hope you'll find the tutorial worth it!
Gophorem - A go API client for forem
Tags: go, forem, showdev, api
Published: 2020-08-17 19:39:59

---
title: Gophorem - A go API client for forem
published: true
description: I wrote a forem API client in go
tags: go, forem, showdev, api
cover_image: https://github.com/ShiraazMoollatjie/gophorem/raw/master/gophorem_logo.png
---


> This is a post about gophorem. Where gophers and forem meet to build communities.

**I love to use go and I love the idea of `forem`**. I also noticed that `forem` 
does not have any go client support. So I wrote one and it's called `gophorem`. It's awesome.

{% github ShiraazMoollatjie/gophorem no-readme %}

# 🤔 What is gophorem

In reality, it's a REST API client for the entire forem API written in go. I 
prefer to call it **the place where gophers and forem meet up to build communities**.

# 🤷 What can you do with it?

Many things! Soon I'll be posting about how I used gophorem to do some data 
visualization with dev.to data. Essentially, **the entire forem API is supported
by gophorem**. This means that you can:

* Use this on ANY forem
* Manage articles
* Manage listings
* Manage webhooks
* List podcasts, video articles

# ⌨️ How do you use it?

Gophorem is pretty simple to use. There are also **examples to help you** get started too.
This is an example to retrieve the latest go articles:

```go
func main() {
	cl := gophorem.NewDevtoClient(gophorem.WithAPIKey("MY_API_KEY"))
	ctx := context.Background()

	// Retrieve all the go articles.
	al, err := cl.Articles(ctx, gophorem.Arguments{
		"tag": "go",
	})
	if err != nil {
		log.Fatalf("something went wrong: %+v", err)
	}

	fmt.Printf("All Articles: %+v", al)
}

```

# 🌧️ It supports streaming too!

It's also possible to **stream articles** with this package. This makes it 
useful for certain use cases. It's **still a work in progress**, but the idea is 
to support all the listing endpoints as streams.

This is an example (ripped from the examples folder) of how to stream all the recent go articles on dev.to:

```go
func main() {
	cl := gophorem.NewDevtoClient(gophorem.WithAPIKey("MY_API_KEY"))
	ctx := context.Background()

	s := streamer.NewStreamer(cl)

	ch := s.Articles(ctx, gophorem.Arguments{
		"state": "fresh",
	})

	for a := range ch {
		fmt.Printf("Received article ID: %d, Title: %s, Username: %s URL: %s \n", a.ID, a.Title, a.User.Username, a.URL)
	}
}

```

# 🤖 Future work and contributions

Since the API is largely complete, I was thinking of adding the following features:

* Finalize the streaming features
* Some rate-limiting features when querying forem servers
* Support oauth authentication
* Some showcase articles for what you're able to do. There is a lot of potential in this package

That's all for now, check out the package and have a go at it. All contributions are welcome. Have fun!!
A Nifty Use Case for Rails Virtual Attributes
Tags: rails, ruby, html, css
Published: 2020-08-17 19:26:50

I work on a Rails project uses models to represent some front end components, which gives us access to clever tricks, including using [virtual attributes](http://railscasts.com/episodes/16-virtual-attributes-revised) for custom styling. 

## The base component class

All of these components inherit from a `Component` model that looks like this: 

```rb
class Component < ApplicationRecord
  def css_class_list
    class_string = "#{self.class}"
    self.style_list.each { |style| class_string << (" " + style.to_s) if self.send(style) }
    class_string
  end
end
```

The `css_class_list` method spits out a class list for use in our ERB templates, like so: 

```erb
<div class="<%= component.css_class_list %>"></div>
```

If we want to build out some `EventComponent` that inherits from the `Component` class, its rendered template would come out like this: 

```html
<div class="EventComponent"></div>
```

## Customize the event component styles

Let's say we want to add some different flavors to the `EventComponent`. We can add additional CSS classes using the `style_list` method:

```rb
class EventComponent < Component
  belongs_to :page

  def style_list
    [
      :description_enabled
    ]
  end
end
```

The parent class, `Component`, grabs `style_list` and sends each symbol to the instance of the `EventComponent`. If it returns true, it adds the symbol to the final class list. 

In this case, if we have an `EventComponent` with `description_enabled`, the rendered template would be: 

```html
<div class="EventComponent description_enabled"></div>
```

## Generate CSS classes with virtual attributes

This works well for model attributes that are boolean values, but what if we want to style based on a non-boolean attribute? This is where virtual attributes really shine. 

Here's a version of `EventComponent` that we can style based on the number of attendees: 

```rb
class EventComponent < Component
  belongs_to :page

  def over_capacity # This is the virtual attribute
    rsvp_count > 1000
  end

  def style_list
    [
      :description_enabled
      :over_capacity
    ]
  end
end
```

Now if we render out an `EventComponent` with more than 1000 RSVPs, the output will look like: 

```html
<div class="EventComponent description_enabled over_capacity"></div>
```

And we can go on to target `.EventComponent`, `.description_enabled`, and `.over_capacity` with our CSS!
Fedora 32 Wallpaper
Tags: fedora, linux, opensource
Published: 2021-03-12 20:48:53

---
title: Fedora 32 Wallpaper
published: true
date: 2020-08-17 19:26:48 UTC
tags: fedora,linux,opensource
canonical_url: https://kylerconway.com/2020/08/17/fedora-32-wallpaper/
---

This time around I was a late adopter (very late) and only recently upgraded my laptop to Fedora 32. It’s great to install a free and open OS and see a wallpaper you worked on greeting you (as I did with Fedora 32). I was involved in creating the [Fedora 26 wallpaper](https://kylerconway.com/2017/08/27/squeak/) as well which featured a treeline that followed a sound wave of my voice saying the word “Fedora.”

I was recently able to attend the _Nest with Fedora_ event (an online, from home, mid-pandemic version of _Flock_ that was wonderful as I was able to “meet” many of the screen names I’d seen in forum posts and email lists for years.

Fedora’s design process is open but not many find their way to the ticket thread to follow along ([here’s a link the above wallpaper’s thread](https://pagure.io/design/issue/669)). I figured I’d share some of the other angles and shades of the above that I had been using as my background until my recent upgrade―initially for testing but then they just kind of stuck. They’re much too dark for a default Fedora release, but I figured I’d share them here. My favorite is the lone object, floating in the void.

Lastly, if you want to get involved on the next wallpapers check out the discussions about [Fedora 33](https://pagure.io/design/issue/687) and [Fedora 34](https://pagure.io/design/issue/688) on pagure at the links.

![](https://kylerconway.com/wp-content/uploads/2020/08/F32-Dark-01-1024x576.png)

![](https://kylerconway.com/wp-content/uploads/2020/08/f32-on-02-1024x576.png)

![](https://kylerconway.com/wp-content/uploads/2020/08/f32-grit-mask-1024x576.png)

![](https://kylerconway.com/wp-content/uploads/2020/08/middle-f32-1024x576.png)
[PoC] I've built a logging provider using .NET Core
Tags: dotnet
Published: 2020-08-17 19:18:33

.NET Core 3.0 releases new compelling features. 

Two of these new features are [Channels](https://devblogs.microsoft.com/dotnet/an-introduction-to-system-threading-channels/) and the new API [System.Text.Json](https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-apis/), which are heavily motivated by performance. 

These features allow us to achieve better performance when we are building our applications.

To try out these features, I've created a logging provider component using .NET Core 3.0. The project is a PoC.

## Architecture Diagram

The architecture diagram of the component looks like

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/1oe71skoyaad6rqq2o7q.png)

The idea is simple; the app writes logs into a shared channel synchronously. Then, two hosted services are listening in the background and pulling messages from the channel to execute the bulk insert into a SQL Server database.

## Limitations

It writes log records into a SQL Server Database using batch sizes or when the timer reaches the end. You can use this project to getting started to write log records wherever you want.

## To dig into the code

{% github mpetrinidev/yadl %}

# Closing Thoughts

Channels and System.Text.Json are new compelling features to come into the latest version of .NET Core. 

On the other, creating a PoC helps me to try out new features in a programming language and make better decisions in the software that I am building.

We are looking forward to .NET 5 🤩