teleren/devto huggingface dataset:
Golang: HTTP Serve static files correctly
Tags: go, http, staticfile
Published: 2018-08-14 09:25:55

---
title: Golang: HTTP Serve static files correctly
published: true
description: 
tags: Go, http, static-file
---
![Demo](https://thepracticaldev.s3.amazonaws.com/i/1cta07w4u7jyd1jcw2zc.png)



#### The EasyWay

Handle static files in Golang is very straightforward just one line of code to do this:

```
http.Handle("/", http.StripPrefix(strings.TrimRight(path, "/"), http.FileServer(http.Dir(directory))))
```

where path is _http_ path and _directory_ is the static directory you want to serve over http

But, there is a problem, by accessing to root url you can expose your directory structure to public as well =\_=:

 ![](https://cdn-images-1.medium.com/max/1600/1*Y9U0dNsQcUroz7rp7uSVpA.png)
*listing directory*

The code is:
[https://gist.github.com/hauxe/09cd680deb9c8c4e36d61568db57647b](https://gist.github.com/hauxe/09cd680deb9c8c4e36d61568db57647b)

We need to do something to prevent this danger

First Don’t use default HTTP File server, we’ll create our custome http file server and reject which request accessing to directory path:
[https://gist.github.com/hauxe/f88a87f4037bca23f04f6d100f6e08d4#file-http_static_custom_http_server-go](https://gist.github.com/hauxe/f88a87f4037bca23f04f6d100f6e08d4#file-http_static_custom_http_server-go)

The custom rule that I chose is: if accessing to a directory, and if that directory contains index.html, return it, otherwise return error

Second Register HTTP File server with this custom struct:

```
fileServer := http.FileServer(FileSystem{http.Dir(directory)})

http.Handle("/", http.StripPrefix(strings.TrimRight(path, "/"), fileServer))
```

If you access it again:

 ![](https://cdn-images-1.medium.com/max/1600/1*_C9zn45efpxTCSDbnxyBlQ.png)
*Successfully prevents*

Put a **index.html** file into statics folder and run example again with new code:

 ![](https://cdn-images-1.medium.com/max/1600/1*t6Lf19ENgl0YoFLBCOCEZQ.png)
*After put index.html*

Full working code:
[https://gist.github.com/hauxe/f2ea1901216177ccf9550a1b8bd59178#file-http_static_correct-go](https://gist.github.com/hauxe/f2ea1901216177ccf9550a1b8bd59178#file-http_static_correct-go)

* * *

I have made a [Repo](https://github.com/hauxe/GoM/blob/master/http/filesystem_handler.go) for this purpose which return the http handler for it
Take up New FreshBooks API in Upgraded dotConnect for FreshBooks and SSIS Data Flow Components
Tags: connector, dotnet, ssis, freshbooksapi
Published: 2018-08-14 08:26:16

---
title: Take up New FreshBooks API in Upgraded dotConnect for FreshBooks and SSIS Data Flow Components
published: true
description: Devart introduced a noteworthy update of dotConnect for FreshBooks and SSIS Data Flow Components with the support for New FreshBooks API (alpha) to make data access process even more seamless. 
tags: connector, dotnet, ssis, freshbooks api
---

Devart, a Czech software vendor of data connectivity solutions and database tools, has rolled out a greatly improved version of dotConnect for FreshBooks, a fast and advanced ADO.NET provider, and SSIS Data Flow Components that allow users to integrate database and cloud data via SQL Server Integration Services. The Devart tools now fully support New FreshBooks API (alpha) with OAuth authentication in addition to FreshBooks Classic API.

Speaking of other implemented improvements, users now can query deleted records from FreshBooks objects supporting this feature: Client, Staff, Expense, Invoice, Item and Payment.
What’s more, updated SSIS Data Flow Components for Salesforce Marketing Cloud are empowered with TLS 1.2 to encrypt network communications safely.

Take a closer look at some current and previous features that are available in dotConnect for FreshBooks and SSIS Data Flow Components at https://www.devart.com/dotconnect/freshbooks/ and https://www.devart.com/ssis/ .

About Devart

Devart is one of the leading developers of database tools and administration software, ALM solutions, data providers for various database servers, data integration and backup solutions. The company also implements Web and Mobile development projects.

For additional information about Devart, visit https://www.devart.com/ .
Avoid dict overuse in Python
Tags: python, python3
Published: 2018-08-14 04:02:07

---
title: Avoid dict overuse in Python
published: true
description: Dicts are great, but they're often overused!
tags: python, python3
series: Python tips
---

Python's dicts are great and we all love them, but on large projects we can easily end up with dozens of functions like this:

{% gist https://gist.github.com/victor-o-silva/10ddefa8346190ae4d4add18511a547b %}

There's nothing inherently wrong with the function above, but there are some little things that may complicate our lives as the project grows.

We may mistype the value of a key when accessing the returned data (like typing `daily_interest_rates` instead of `daily_interest_rate`). Because we're dealing with a dict, we would only find this error (that is, **if** we find it) during run time.

Or maybe we could start calling this function and using its returned dict in a lot of places. In this case, we would find ourselves repeatedly coming back to the implementation just to remember the dict's keys, or to check the due dates' structure.

We can get rid of these potential problems in advance, and make this code a lot more explicit, if we

## Use proper classes instead of using dicts everywhere

Let's try it:

_Note: below, I will use [`dataclasses`](https://docs.python.org/3/library/dataclasses.html), added in Python 3.7, to avoid some boilerplate \_\_init\_\_ code._

{% gist https://gist.github.com/victor-o-silva/f16f9472f2f14471f66bae528743045b %}

Now our function returns instances of a class, and thanks to the type hints that were added, we know the exact structure of these instances.

> _Note: if you never heard of type hints, check my really short introdution to them:_ {% link https://dev.to/victorosilva/explicit-is-better-than-implicit-type-hints-12i0 %}

By using any Python-aware IDE, the two problems that I described before are no more. Because of the new class `CalculationResult` combined with type hints, [PyCharm](https://www.jetbrains.com/pycharm/) will warn me if I mistype a field name:

![PyCharm - mistyped field](https://thepracticaldev.s3.amazonaws.com/i/0u1ie1s355tx4onr6zru.png)

If I forget the structure of the due dates, type hints got me covered. PyCharm will rely on them to remind me that the dates are the values of a dict whose keys are integers:

![PyCharm - field structure](https://thepracticaldev.s3.amazonaws.com/i/bbj85oww01tdsrvx9enp.png)

Now, I'm not saying we should stop using dicts altogether. My point is that, for larger projects, maybe it's better to represent our data as proper classes. With the new Python dataclasses, we can do this in a jiffy.

Nowadays I tend to prefer dicts only in places like the field `CalculationResult.due_dates` above: when all keys are of the same type and represent the same thing (e.g.: the installments) and all the values are of the same type and represent the same thing (e.g.: the due date of the corresponding installment).

I find that my code is getting more expressive, explicit and maintainable by adopting this strategy.
Have you ever tried any bash frameworks?
Tags: bash, discuss
Published: 2018-08-14 03:28:12

---
title: Have you ever tried any bash frameworks?
published: true
description: 
tags: Bash, discuss
---

These days, [Bash Infinity](https://github.com/niieani/bash-oo-framework) reached the top 10 repo in github trends. 

I have not ever tried object-oriented bash programming before, so how about your opinions on bash frameworks?
My First Chrome Extension: Stackoverflow Starred Viewer
Tags: showdev, opensource
Published: 2018-08-13 23:34:30

---
title: My First Chrome Extension: Stackoverflow Starred Viewer
published: true
description: An extension to easily browse starred questions on StackOverflow
tags: showdev, opensource
---

>**Update 2021-05-21:** I plan to get back on improving this project. I neglected it in the past due to other responsibilities. 

Are you a [mediocre developer](https://dev.to/sobolevn/i-am-a-mediocre-developer--30hn) like me? Do you firmly believe in [StackOverflow driven development](https://meta.stackoverflow.com/questions/361904/what-is-stack-overflow-driven-development)? Did you forget to bookmark that answer you always copy-paste from? 

That was my main itch that prompt me for this side project. 

**TL;DR:** An easier way to browse starred StackOverflow questions. It simply injects a sidebar onto your browser when you visit stackoverflow.com. This sidebar displays a filterable list of all your starred questions.


- [Chrome Extension Link](https://chrome.google.com/webstore/detail/stackoverflow-starred-vie/cnamfgnggohmnbilcjdnjjahlgkndhmp?hl=en)
- [Project Github Link](https://github.com/AlahmadiQ8/StackFave)

I [star](https://stackoverflow.com/search?q=infavorites%3A5431968) [many](https://stackoverflow.com/search?q=infavorites%3A5431968) [StackOverflow questions](https://stackoverflow.com/search?q=infavorites%3A5431968) that I frequently refer to. However, it is not easy to navigate through them. I tried searching the web, but the next best answer I found was [this](https://meta.stackexchange.com/questions/3912/better-favourites-organisation). 

This motivated me to create my own extension for a simpler way to navigate through my starred questions. I was hugely inspired by my ultimate [favorite extension octotree](https://github.com/buunguyen/octotree).

Here are some screenshots. 


![](https://d2mxuefqeaa7sj.cloudfront.net/s_8A94332956CEBD301F63DA15A44A118E6AE15B285C27C0609AC48084A8D96C51_1534023176495_so.gif)

# Feedback 

What do you think of this extension? I would really appreciate any feedback you could give, especially on the following: 


- Do you find it useful? 
- How's the user experience?
- Any features that would make it more useful?

There are still [some bugs](https://github.com/AlahmadiQ8/StackFave/issues) I'm aware of that need to be addressed. Feel free to create issues if you find any others.

There are also missing core features that I plan to add.

Thanks in advance for trying it out! I look forward to hearing your thoughts.
A 2 Minute Primer on Modern Deep Learning
Tags: machinelearning, ai, deeplearning
Published: 2018-08-13 21:54:32

---
title: A 2 Minute Primer on Modern Deep Learning
published: true
description: 
tags: Machine Learning, AI, Deep Learning
---

In most cases, Deep Learning (DL) is really just an application of statistical methods to suss out patterns in data using neural network architecture with several layers.

A neural net usually follows a general design. There are some inputs that represent data being fed to the network, i.e. pixels in an image, followed by several layers of hidden nodes that process information in a particular way before passing it on.

The “deep” in deep learning is really just a reference to these hidden layers that exist between your input and output layers. The architecture is, as you might have inferred from the name, very loosely inspired by that of the brain. Emphasis on loosely.

![sample neural network](https://thepracticaldev.s3.amazonaws.com/i/i2su6hiu9ri1r7g9lz7n.jpeg "Credits: Stanford CS229")

To train these networks, we present them with numerous examples of sample data that is labeled. (Think showing it a picture of a german shepherd with the label “dog”) We employ a process called gradient descent to modify the connections between our nodes, through an algorithm known as back-propagation. This allows us to prune our network and strengthen input-output mappings. As we train them, DL based networks often form interesting representations of data corresponding to some sub-component of the inputs. Think lines representing the edges of a table.

There are numerous interesting sub-architectures that provide optimized or incrementally better results, especially in a specific problem space, but we won’t dive too deeply into those here.

If you can only takeaway one thing from this primer, let it be this:

In a universe with infinite data and computational power, DL techniques can encode any discrete representation between inputs and outputs, and this is a very powerful notion. For example, there are an enormous set of problems that involve the classification of certain inputs into categories. Of course, categories can represent pretty much anything, so throw DL enough data and compute, and it can probably map to any input output pair you give it.

Practically, there are a number of endemic problems, including the concept of getting caught at a local minima, where your algorithm thinks it is optimized despite there being better solutions. This is usually solved, and is often not a huge problem when dealing with sufficiently large amounts of data.

TLDR: DL is powerful with large amounts of data and computational power, and can solve simple mapping problems effectively. But how would it do if the goal is to encode causality and intelligence? I’ll examine that soon.

*This is Part 1 of a few part series introducing Modular Neural Networks with* *Adaptive Topology, an architecture I think will be enormously successful for* *complex, hierarchical problems.*

*You can check out the rest of the series as it comes out here or on [technomancy!](https://medium.com/technomancy)*
js13kGames competition started!
Tags: beginners, javascript, gamedev
Published: 2018-08-13 21:41:11

---
title: js13kGames competition started!
published: true
description: A little reminder about the competition and encouragement for beginners.
tags: #beginners #javascript #gamedev
---

### Just a little reminder :)

There is a wonderful competition out there called [js13kGames](http://2018.js13kgames.com). The name explains its objective very clearly. You have to create a game that weighs 13kb in JS. The game has to fit the theme that the author of the competition appointed.

This year's the theme is: **Offline**

I tagged this post #beginners for a reason. It is a great opportunity to learn how to design and make a game. Their website has a wonderful "Resources" page that links to many tiny libraries and frameworks that you can use to create your game.

To encourage people to participate in a competition, there are many valuable [prizes](http://2018.js13kgames.com/#prizes), like a year of GitHub subscription, CodePen Pro plans, and more!

You don't have to rush! Competition ends at September 13th, so you have enough time to think, create and test your game.

Good luck!
Look up faker methods on your terminal
Tags: ruby, rails, faker, fakerbot
Published: 2018-08-13 21:13:51

---
title: Look up faker methods on your terminal
published: true
description: 
tags: #ruby #rails #faker #fakerbot
---

I'm a huge fan of the [Faker Gem](https://github.com/stympy/faker) and I use it everywhere. However, sometimes I find myself digging through Faker's ReadMe _(which is brilliant btw)_ when I'm unsure of a method's namespace or I'm just not sure what's available. 

I've always wished I had some way to search faker at the comfort of my terminal.

> Well... `gem install fakerbot`! 😉

[fakerbot](https://github.com/akabiru/fakerbot) is a cli tool that does just that. It reflects [faker's](https://github.com/stympy/faker) object space exposing lookup & listing functionality.

Enough talk, let's see it in action.

```sh
$ fakebot search number -v
```

![](https://thepracticaldev.s3.amazonaws.com/i/w6qas7os5aydm4mnvec0.jpg)

```sh
$ fakerbot list
```

![](https://thepracticaldev.s3.amazonaws.com/i/7fk2yvzsutsi7pj4a8rn.jpg)

_More [Usage instructions](https://github.com/akabiru/fakerbot#usage) can be found on the ReadMe._

If this looks like something that interests you, don't by shy! Please drop by the [repo](https://github.com/akabiru/fakerbot#usage) , contribute, suggest a feature, add tests, ✨ e.t.c.

My hope is that this tool makes your DEV life a tad easier as it has mine. Cheers! 🍺
React Weather App Video Course 12-14
Tags: javascript, react
Published: 2018-08-13 21:05:38

---
title: React Weather App Video Course 12-14
tags: javascript, react
published: true
description: React tutorial for beginners. Making weather app part 12-14.
cover_image: https://thepracticaldev.s3.amazonaws.com/i/ojsoibgy6hwt92m05eq8.jpg
---

In these parts we’ll make the back part of the card. We’ll display cities list and add proper styles to it:

* [Part 12](https://youtu.be/0yjUC4kTOa8)
* [Part 13](https://youtu.be/whiRrP0jNXw)
* [Part 14](https://youtu.be/2CM1H9RtuJ4)
TIL about paste
Tags: bash
Published: 2018-08-13 21:01:37

---
title: TIL about paste
published: True
description: No, not that kind
tags: #bash
cover_image: https://thepracticaldev.s3.amazonaws.com/i/1ai6xj4zw8w19i6sypqp.png
---
In a large chunk of my work, I've had to deal with cleaning and combining multiple data files. Today I learned that bash has a simple command called paste. Here's what the manpage says
![alt-text](https://thepracticaldev.s3.amazonaws.com/i/1ai6xj4zw8w19i6sypqp.png "Man pages")
Now that's a lot to digest but how is it useful? Well I have two files here, fileone.csv and filetwo.csv

![alt-text](https://thepracticaldev.s3.amazonaws.com/i/8q9mher96md44jsq86ql.png "fileone.csv")
![alt-text](https://thepracticaldev.s3.amazonaws.com/i/cug5t1qm9hixt6d801xm.png "filetwo.csv")

I generally don't like wasting lines of code to read in multiple data frames so I usually want to combine them. Now, it takes more than just a simple `paste fileone.csv filetwo.csv > combined.csv` to combine them since the output is this:
![alt-text](https://thepracticaldev.s3.amazonaws.com/i/o9h380f5p7v70s9m8gu7.png "bad output")
This is because paste merges the files. No replacing character is specified. For my work, I use```paste -d"\n" fileone.csv filetwo.csv > combined.csv```
to achieve the output I desire:
![alt-text](https://thepracticaldev.s3.amazonaws.com/i/xiyek3o8stitesitlnrj.png "correct output")
Now all I have to do is delete a single row. Yes you may have multiple csv's combined, but your header row gets moved to the top regardless, making deletion much easier. *Extra ease if you're using Vim :\^)*
Tools I use to stay on top of Github's notifications
Tags: opensource, tools, productivity
Published: 2018-08-13 19:45:57

---
title: Tools I use to stay on top of Github's notifications
published: true
description: 
tags: OSS, tools, productivity
---

In order to maintain a lively open source community, it is crucial to stay actively engaged with all issues and pull requests. Everything should be looked at and nothing should be missed, but that is much easier said than done. In the effort to stay on top of it all, here are a few apps that I use to stay sane and efficient.

## [github-notifications](https://github.com/bkeepers/github-notifications)
![](https://cl.ly/1Y2i3z3b0633/Image%202018-08-13%20at%203.08.50%20PM.png)
I like to think of github-notifications as an improved version of the vanilla notification page. The main highlight of this app is that it also provides a comment form. This provides a much better way to get an overview on all unread notifications.

## [Octobox](https://octobox.io/)
![octobox](https://dzwonsemrish7.cloudfront.net/items/2i2C212L0o2c070F1a1L/Screen%20Recording%202018-08-13%20at%2001.00%20PM.gif)
Streamlining Github Notification into the email-like interface is an amazing way to manage notifications. Octobox provides multiple filter options along with a native search feature. They've also added an "archive" feature that allows you to hide any completed notifications.

## [Workona](https://workona.com/)
![workona example](https://cl.ly/1b1T1f28262u/Screen%20Recording%202018-08-13%20at%2001.17%20PM.gif)
Ever find yourself opening one GitHub issue right after another and eventually losing track of what you were trying to do? This is a relatively new tool that just came out to address that problem.  It has already improved my workflow and reduced distraction. Workona provides a cleaner way to manage tabs — instead of keeping multiple windows open, you can now create "workspaces". So far, I have 3 workspaces: one for general browsing, one dedicated to handling Octobox notifications, and one for production monitoring.

These three tools have helped me a lot. Let me know in the comments if there is anything else I should try.
Better CSS outlines with box-shadows
Tags: css, a11y
Published: 2018-08-13 19:21:05

---
title: Better CSS outlines with box-shadows
published: true
description: I think we can all agree that the default browser outline styling isn't the most beautiful design implementation
tags: css, a11y, accessibility 
---
I think we can all agree that the default browser outline styling isn't the most beautiful design implementation. I also think we can agree that it may not be pretty but it does *function well*.

It can be common to see folks remove the outline completely and not replace it with any other visual indication. This is bad practice and can hurt the user experience for keyboard users.

To appease our designers while keeping our site accessible, lets remove the default outline style and replace it with a box-shadow implementation shown below.

```css
input:focus {
  outline: 0;
  box-shadow: 0 0 0 3px rgba(0, 123, 255, .5);
}
```

So we can see we set the outline to 0 when the input is focused and added a box-shadow declaration to replace its functionality. As an added bonus, using a box-shadow also follows border-radius declarations. So if our input has a 4px border radius, our faux outline will not have a gap in the corners.

Check out the [CodePen](https://codepen.io/alexcarpenter/pen/vaPwaa) example to see it in action.

{% codepen https://codepen.io/alexcarpenter/pen/vaPwaa %}
Top 3 web application development trends
Tags: webdev, webappdevelopment, saasdevelopment
Published: 2018-08-13 18:52:03

---
title: Top 3 web application development trends
published: true
description: Here a few trends in the web application development space.
tags: web development, web app development, saas development
---

![](https://s3.amazonaws.com/snaps-bucket/2018/08/c9JrISY/web-development.gif)

Top 3 Web Development Trends That Deserves Your Attention

Just like the speed of your 4G LTE, web technologies are moving at the highest speed. You need to be at your best to catch you with the pace, else you’ll be far behind in a twinkle of an eye.
 
Which is why you need to be in the know as to every web application developments. To keep up the pace, check out what we consider as the top 3 web development trend for 2018; 

##1. The Growing Popularity of Real Time Web Apps
They have been around for years but in recent times, their popularity is increasing, especially with [SaaS development](https://medium.com/@webrefinery/top-saas-development-companies-saas-developers-agencies-in-2018-c2c996c1a002). It’s meeting the needs of users who yearns for faster interaction. No need to check back manually for feedbacks with real time web apps. 
It used to be the domain of node.js, but its spreading faster to other frameworks and languages. 

Do you want to build a web application? Here's a compilation of the top [web application development companies](https://medium.com/@webrefinery/top-5-web-application-developers-agencies-list-of-best-developers-in-2018-5c99f7e1f2a2)

##2. Progressive Web Apps to the Rescue
It was announced in 2015 by Google to correct the abnormality of mobile apps, it will help in rebuilding websites. PWA has risen as an alternative and 2018 is the year that its usefulness has come to the forefront. 
PWA doesn’t seems to be slowing down at all, it popularity may spill into subsequent years to come. 

##3. JavaScript and Functional Programming
For those with a love for JavaScript programming, they will understand the impact it is having on functional programming in recent times. The improvement in JavaScript in the aspect of ES6 and ES7 is responsible for the new trend. 
Arrow functions, object/array spread and async/await has gotten even better.