teleren/devto huggingface dataset:
Friday Blast #66
Tags: fridayblast, links, post
Published: 2019-03-30 06:10:42

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

[On infrastructure at scale - a cascading failure of distributed systems (2019)](https://medium.com/@daniel.p.woods/on-infrastructure-at-scale-a-cascading-failure-of-distributed-systems-7cff2a3cd2df) - all the things that started failing in Target’s infrastructure. It’s a nice story of how complex systems interact. It even has oscillating behaviour.

[Laws of tech - commoditize your complement (2018)](https://www.gwern.net/Complement) - an article on Gwern.net about Joel Spolsky’s _pattern_ of “comoditizing your complement”. Or making sure a complementary product to yours has many providers, or is open source, or otherwise making it _easy and cheap_ for your customers to use. The bulk of the article is a long list of such occurences.

[Communication is a core skill for programmers (2019)](https://medium.com/@mquiros/communication-is-a-core-skill-for-programmers-ff61162bbe6d) - true words. So much of what an engineer does, especially as they become more senior, is _persuasion_ and effective communication. Design docs, postmortems, documentation, product pitches etc. are some day-to-day cases where this is needed. So it’s best one is always practicing this skill.

[How fast can you multiply really big numbers? (2019)](https://www.johndcook.com/blog/2019/01/14/multiply-big-numbers/) - betcha you didn’t know you can multiply numbers via the fast Fourier transform? And that it’s faster for “big numbers” too - not just a theoretical exercise.

[How fast can you multiply matrics? (2018)](https://www.johndcook.com/blog/2018/08/31/how-fast-can-you-multiply-matrices/) - a complement to the other one. Strassen showed that you can do it in under <script type="math/tex">O(n^3)</script> which sparked off a search to find the theoretical lower bound for this. It sits at <script type="math/tex">O(n^2.37)</script> right now, with a natural limit of <script type="math/tex">O(n^2)</script> which some folks believe is actually doable.
Recording Your Learning Survey Results
Tags: research, learning, productivity, beginners
Published: 2019-03-29 22:48:02

---
title: Recording Your Learning Survey Results
published: true
description: Survey results -- small sample group
tags: #research #learning #productivity #beginners
---

Hello everyone! As some of you might have seen; I ran a short survey and got about 20 responses. While not a viral survey by any means, I did have a great opportunity to learn a little more about the problem domain I'm looking at. I also learned a little bit about making surveys. 

### Drafting the survey

It helped to have a problem domain I wanted to look at. I'm wanting to build some kind of note app, but I didn't really have a good grasp of what problems existed for current systems. I would say it's important not to guide your survey participants in a specific direction. 

### Realizing I have a bad question in the survey

After about 4 people responded to the survey; I realized that I had a question that was essentially useless. I was worried about breaking the survey link, so I just left the question in there. This probably could have been avoided if I had done a quick survey with a person or two in order to test the usefulness of each question. 

### Deciding the length of time to keep the survey open

I had 11 responses on the first day of the survey, 3 responses on the second, and 7 on the third day. By the 4th day I had no responses and I felt I could see a decent gathering of common information gathered by the survey, so I decided to close it. I had recruited a number of other people to take the survey manually on the 3rd day, which is where the spike came from. 

### Getting participants

Honestly this was the hardest part. I think a majority of participants for the survey were people I recruited through direct communication. I had the idea of going to local coffee shops and asking the manager if I could conduct the survey but I decided a smaller sample set was okay for this purpose. 

### Results

Here are the results, they are by no means comprehensive for a large audience, but it's a starting point if you're curious to explore this problem domain a little further! 

-------

![Survey Page 1](https://thepracticaldev.s3.amazonaws.com/i/9tjw2c8e5fexlsqc3atf.jpeg)

![Survey Page 2](https://thepracticaldev.s3.amazonaws.com/i/uhkga4wpl19nemlqwsrw.jpeg)

![Survey Page 3](https://thepracticaldev.s3.amazonaws.com/i/cdxkm2tf515yvuyqok2b.jpeg)
Telegram bot in Go: database
Tags: go, telegram, bot, webdev
Published: 2019-03-29 22:36:45

---
title: 'Telegram bot in Go: database'
published: true
series: Telegram bot in Go
tags: 
- go
- telegram
- bot
- webdev
cover_image: https://images.unsplash.com/photo-1527430253228-e93688616381
canonical_url: https://detunized.net/posts/2019-03-29-telegram-bot-in-go-database/
---

Today I'm gonna add a database to my bot. As I mentioned in the [previous post](https://dev.to/detunized/telegram-bot-in-go-3hd4), I'm going to use SQLite to keep it simple and because the management turned down my budget request for Oracle on this project.

I quickly shopped around for an SQLite package for Go and found [go-sqlite3](https://github.com/mattn/go-sqlite3). This seems to be a very popular package. It allows me to use the standard `database/sql` package and it acts as a driver, which allows the Go database engine to talk to SQLite databases. So far so good. I'll use that then.

Since I'm writing everything in Go, I desperately need to use goroutines somewhere. So the first thing I did was to move the reply functionality into a goroutine.

```golang
for update := range updates {
    go reply(bot, update)
}
```

That should make things go **FAST**! Never mind the fact that Telegram will [not allow](https://core.telegram.org/bots/faq#my-bot-is-hitting-limits-how-do-i-avoid-this) frequent requests for any extended period of time. I've gotta try anyway.

To use the database I have to open it first. It's done like this:

```golang
func openDatabase() *sql.DB {
    db, err := sql.Open("sqlite3", "./since.db")
    if err != nil {
        log.Panic(err)
    }

     _, err = db.Exec("CREATE TABLE IF NOT EXISTS events (" +
        "id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " +
        "user INTEGER, " +
        "name TEXT, " +
        "date INTEGER);")

     if err != nil {
        log.Panic(err)
    }

     return db
}
```

I also create a table if it doesn't exist. Since I barely use SQL, I prefer to SCREAM so people can hear me. And maybe the DB will get a [sense of urgency](https://stackoverflow.com/a/35684720/362938) and [process my queries faster](https://twitter.com/shipilev/status/703176579191410689).

Once the database successfully opened and no one panicked, it's time to start saving incoming events to it. I do it like this:

```golang
func store(message *tgbotapi.Message, db *sql.DB) {
    _, err := db.Exec("INSERT INTO events (user, name, date) VALUES ($1, $2, $3);",
        message.From.ID,
        message.Text,
        message.Date)
    if err != nil {
        log.Panic(err)
    }
}

store(update.Message, db)
```

Now, every time I send a message to my bot it stores its content in the database. It's a start. The bot is still responding with the same reply as before. It's still really dumb. We'll get to make it smarter in the next day.

If you're curious, the code is [available on GitHub](https://github.com/detunized/since-bot/tree/day-2). This version is tagged `day-2`.

*Originally published on [detunized.net](https://detunized.net/posts/2019-03-29-telegram-bot-in-go-database/)*
Getting to Yes -- As Quickly as Possible
Tags: go, beginners, linux
Published: 2019-03-29 22:05:13

---
title: Getting to Yes -- As Quickly as Possible
published: True
description: Is it possible to beat gnu yes in go?
tags: #go, #beginners, #linux
---

There [was a great discussion a year ago](https://www.reddit.com/r/unix/comments/6gxduc/how_is_gnu_yes_so_fast/) about how fast gnu's version of "yes" is.  If you're unfamiliar, `yes` outputs `y` indefinitely.

```
yes |head -5
y
y
y
y
y
```

The key takeaway was that `write` is expensive and writing page-aligned buffers is much faster.  The is true across languages, so let's see how to do it properly in go. 

If you're shocked or impressed by the results, let's see you do it in your language -- post your results in the comments.   


First, our benchmark C code from last-year's post.
```
/* yes.c - iteration 4 */
#define LEN 2
#define TOTAL 4096 * 4
int main() {
    char yes[LEN] = {'y', '\n'};
    char *buf = malloc(TOTAL);
    int bufused = 0;
    while (bufused < TOTAL) {
        memcpy(buf+bufused, yes, LEN);
        bufused += LEN;
    }
    while(write(1, buf, TOTAL));
    return 1;
}
```

And now the throughput benchmark
```
$ gcc yes.c -o yes_c
$ ./yes_c |pv >/dev/null
...[3.21GiB/s] ...
```

So our Benchmark rate = **3.21 GB/s**

## Go Round 1 -- Captain Obvious

Hypothesis: this will be slow.  I'm guessing 20% as fast as the benchmark.

```
package main

import (
	"fmt"
	"os"
)

func main() {
	for {
		fmt.Fprintln(os.Stdout, "y")
	}
}

```

```
$ go run yes.go |pv > /dev/null 
$ ...[1.07MiB/s] ...
```

Yikes! 1.07 MB/s or only **0.03%** of our benchmark.   💩 Hypothesis confirmed!


## Go Round 2 -- Page-aligned buffers
*note* on Darwin Pagesize X 4 produced the best results -- i'll leave that to the readers to guess why.

```
package main

import (
	"os"
)

func main() {
	buf := make([]byte, os.Getpagesize()*4)
	for i := 0; i < len(buf); i += 2 {
		buf[i], buf[i+1] = 'y', '\n'
	}
	for {
		os.Stdout.Write(buf)
	}
}

```

results: 
```
$ go run yes.go |pv > /dev/null 
$ ...[3.15GiB/s] ...
```
Results : 3.15 GB/s or **98.13%** of our benchmark. We have a winner 🏁


➡️ How fast can you "Get to Yes" in your favorite language?
How to center elements vertically on a create-react-app project
Tags: react, javascript, html, css
Published: 2019-03-29 21:08:40

---
title: How to center elements vertically on a create-react-app project
published: true
description: You've just started a new react project with CRA, but you can't get your elements to be centered directly on your page, now what?
tags: react, javascript, html, css
---

TLDR: Just add the following to `public/index.html`
```html
<style>
  html, body, #root, #root>div {
    height: 100%;
    margin: 0;
  }
</style>
```



You've just run `create-react-app my-app`, and now you edit your `App.js` file to include a centered button:

```jsx
import React, { Component } from "react";

class App extends Component {
  render() {
    return (
      <div
        style={{
          display: "flex",
          justifyContent: "center",
          alignItems: "center"
        }}
      >
        <button onClick={() => alert("hello")}>alert hello</button>
      </div>
    );
  }
}

export default App;
```

But, oh no! It is only centered horizontally, and not vertically!

To look further, add a background color to your div there, like so:

```jsx
<div
  style={{
    display: "flex",
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "blue"
  }}
>
```

You will notice that the blue background does not take up the entire screen, even though this div is the only thing in the application at the moment.

In order to fix this, add the following to `public/index.html`:

```html
<style>
  html, body, #root, #root>div {
    height: 100%;
    margin: 0;
  }
</style>
```

Source code available here: https://github.com/mcrowder65/centered-cra-example
Labs Week 2: A Review
Tags: lambdaschool
Published: 2019-03-29 18:05:12

---
title: Labs Week 2: A Review
published: true
description: Brief review of Lambda Labs week 2
tags: Lambda School
---
![training bot](https://thepracticaldev.s3.amazonaws.com/i/qwrt0bt452lccfj935bp.png)
## What a week!

This has by far been the one of the more challenging weeks I've had at Lambda School. From feeling impostor syndrome in the beginning of the week to feeling great mid week and then getting stuck today.

This week I took on getting Stripe integrated into our project. Started out reading documentation and not understanding how it all fit together. This was the first time I had to integrated a front end, back end, and third party API. Understanding how all the pieces fit together has been the biggest challenges. Mid week I started to get a hang of things and by the end of the week started to refactor the code to add in redux.

---

This week one of my bigger accomplishments has been getting the front end to look decent while updating based on the state of the subscription.

![UI for Profile](https://thepracticaldev.s3.amazonaws.com/i/gzybajq1i01gjx9r4uca.png)

When a user selects a subscription type the payment form appears. Upon entering their card info the back end handles registering the user with stripe if they aren't already and sending the Stripe user ID to our database. Then it takes the Stripe user id and subscribes the user to the plan and updates the user account type in our database to be reflected on the front end. I'm currently running into some promise issues while integrating redux to better handling the updating of state for the profile page.

---

My team has been nothing but incredible through the entire process. I've tried to be in our zoom sessions at all times to help out where I can. I think a big part of being a team player is being in the room there for when someone has an issue or wants to bounce an idea off you. I jump in on the discussions where I feel I have a valuable idea and listen to the discussions that are outside of what I know

Overall our team is fairly laid back and nobody has a strong opinion on design or technology decisions. If someone feels like taking on a task we all trust their decision and if something comes up we handle it as a team.This has made the entire process pretty frictionless. I do feel that I haven't been good personally about asking for help and rather just try and grind through something I'm not sure on. This is something I would like to work on in the final three weeks of Labs.
Dev-Log #2: Lander-Game, we have a loop!
Tags: elixir, gamedev, indie, space
Published: 2019-03-29 20:27:01

The lander-game is still figuring itself out piece by piece, but it already has some rules and a loop. This is mostly a scratchpad for myself and rather hastily written.

**Current state**:

- The player is looking at a space-hangar-management-software and has to manage approaching ships. The hangar has four landing-platforms in a row. Ships pay a fee for each round they stay landed.

- The arriving ships can be from three different fractions: Police, Corporate, Cartel. 

- The player has a reputation with each fraction. A positive reputation means the player gets a bigger tip from that fraction.

- The reputation changes based on how the player places ships from certain fractions next to each other.
Example: Putting *Police* next to *Cartel* will improve the rep. with *Police*, and lower it with *Cartel*. *Corporate* next to *Cartel* means a minus with *Corporate* and a plus with *Cartel*. Think rock-paper-scissors.

- A ship will remain on the platform for 3 to 6 rounds.

- Sending a ship away prematurely by placing a new ship on that platform will decrease reputation with that fraction.

- The player is paying a fixed maintenance fee each round.

**Current ideas and struggles**:

- Should a ship pay for each round, or just on landing, or just on leaving? With pay-on-leave I could add that the player won't get payed if the ship gets "sent home" prematurely. 
- An arbitrary number of platforms. Start with one or two, and buy additional platforms as the game progresses. Currently, 4 are hardcoded into the game.
- A lose-condition is still missing. Maybe lose if you run out of cash?
- Game-objectives may be: Get n money by round 50; Don't get a negative reputation with the cartel; survive 50 rounds; start with a negative rep. with the police and get it positive by round 30;
- A fourth fraction, "Leisure" or "Private", which does have effects on neighbouring ships, but doesn't have a reputation with the player. Could be useful as filler for empty slots, I don't know…
- A second dimension. The platforms aren't just 4 in a row but maybe 3x4, and the reputation-effects go up and down.
- Events! This will spice up the game and add story. 
Example: 
 - Cartel offers you money if you don't let police land
- The game currently has instant state-changes, since the interface is still a CLI. That means every change happens instantly and the player has no transitions to help visualise consequences. It's waaaay to early to think about final visuals etc. but I would want this to be a browser-based game if it ever goes public. Of course I had to do a little yak-shaving and put the CLI-game into Cathode.app, for a little trashy Sci-Fi-Cyber-Vibe:

![Cathode.app](https://thepracticaldev.s3.amazonaws.com/i/9rgrdwiclmbao50p0ih3.jpg)
What aspect of Go were you at odds with, coming from a different tech stack?
Tags: discuss, go
Published: 2019-03-29 20:06:33

---
title: What aspect of Go were you at odds with, coming from a different tech stack?
published: true
description: 
tags: devdiscuss, go, golang
---

Recently, I added the Go language to my programming tool belt. Yet, as much as I want to give the language more and more chances, it hasn't really been a shiny success story so far. A lot of things in how one writes Go programs are just different. And I mean, not only syntax-wise. I have spent quite a lot of time digging into the philosophy of the language, and guiding principles of the founding team, and I have to say, for the most part, I do agree with them on 100%. Go isn't exactly a beautiful and fluent language in terms of its level of syntax sugar and this is supposed to be a feature and not a bug. Having witnessed the evolution of Java over the past close to a decade, I have quite learned to like the verbosity and ceremony. As much as it hurts to write code, it makes its long-term comprehension and maintenance much easier. 

And yet, I can't make myself appreciate Go as much as I want to. There are some things that cross my principles, and I can't decide whether to believe and accept that this is an ingenious way to do things, or cross them out as utterly stupid. Like, when you'd pass an argument to a function and expect the return to be a modified version, but instead, it was the argument itself that got modified. I know that these are just things that I could simply avoid doing, but it is difficult not to stumble upon them everywhere, because they are part of what is known as "idiomatic Go".

Maybe it's just me, or maybe not. I did not want to open up an argument, but just to sort of figure out what struck others as odd, when approaching the Go language from a different domain.
Maven: Execute main method from command line
Tags: maven, mvn
Published: 2019-03-29 19:24:35

---
title: Maven: Execute main method from command line
published: true
description: 
tags: maven, mvn
---

Using maven to execute the `main` method of a class:
```
mvn exec:java -Dexec.mainClass="com.example.Main" [-Dexec.args="argument1"] ...
```
Drawing a Minion with CSS
Tags: css, css3
Published: 2019-03-29 18:18:07

---
title: Drawing a Minion with CSS
published: true
description: I tried to make some art with CSS
tags: css,css3
---
Quick Video on how I created a Minion with CSS
<blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">Drawing Minion with <a href="https://twitter.com/hashtag/css?src=hash&amp;ref_src=twsrc%5Etfw">#css</a><a href="https://twitter.com/hashtag/css3?src=hash&amp;ref_src=twsrc%5Etfw">#css3</a> <a href="https://t.co/eOcvteabzm">pic.twitter.com/eOcvteabzm</a></p>&mdash; Ahmed ⚯͛ (@geeksamu) <a href="https://twitter.com/geeksamu/status/1111360066681212936?ref_src=twsrc%5Etfw">March 28, 2019</a></blockquote>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

Here's the code https://codepen.io/geeksamu/pen/OqKRom
Creating Image Filters in JS
Tags: showdev, javascript, multithreading
Published: 2019-03-29 17:57:21

---
title: Creating Image Filters in JS
published: true
description: Kernel convolution on an image using JS and Web Workers
tags: showdev, javascript, multithreading
cover_image: https://thepracticaldev.s3.amazonaws.com/i/xzz215aem1t4guyc5uw8.png
---

I spent the last two weeks on a project that I hoped would help me obtain a concrete understanding of how image kernels work. You know those image filters you have in Photoshop or your typical photo editor app that let you sharpen or blur an image? Those are implemented using image kernels. This [blog post](http://setosa.io/ev/image-kernels/) has by far the best explanation of image kernels I could find. For something a little more formal, here's [Wikipedia](https://en.wikipedia.org/wiki/Kernel_(image_processing)).

The demo is online and I've given the link to it below. What you'll see is a simple page with some instructions at the top. Feel free to play around with the kernel and sample images.

The image is split into four partitions and each partition is passed to a web worker to be processed so we don't block the main thread. I found that four web workers are only a little over twice as fast as one web worker processing the entire image alone. I expected four times the speed, but I guess I got too optimistic, not considering the overhead in copying the pixel arrays, etc.

I can conclude that I now do have a better understanding of how image kernels work (aside from the fact that I ended up spending way more time working with web workers). If only this could get me extra credit for my image processing course.

Here's [the demo](https://mebble.github.io/imfx/) and the repository:
{% github mebble/imfx %}