teleren/devto huggingface dataset:
Things I Enjoy in Rust: Immutability
Published: 2019-04-30 10:35:50

---
title: Things I Enjoy in Rust: Immutability
published: true
tags: 
canonical_url: http://blog.jonstodle.com/things-i-enjoy-in-rust-immutability/
---

**Things I enjoy in Rust:**

1. [Enums](https://dev.to/jonstodle/things-i-enjoy-in-rust-enums-4cdl)
2. [Error Handling](https://dev.to/jonstodle/things-i-enjoy-in-rust-error-handling-2jkh)
3. **Immutability**
4. [Impl](https://dev.to/jonstodle/things-i-enjoy-in-rust-impl-1doj)
5. [Macros](https://dev.to/jonstodle/things-i-enjoy-in-rust-macros-21fp)

Immutability is a term very commonly heard in relation to functional programming languages. In most C-like languages, immutability is mostly an afterthought and is usually implemented in a somewhat clumsy way.

In Rust, immutability is the default. If you assign a new value...

```
let myValue = 42;
myValue = 43; // <-- Not allowed
```

... it is immutable.

To enable immutability, you'll have to specify it explicitly:

```
let mut myValue = 42;
myValue = 43; // <-- Allowed
```

Rust also makes it easy to work with immutable structures. This is something that's often missing when working with immutable classes or structures in languages where immutability is not a main feature. Let's look at an example:

```
// Define a structure
struct Point {
	x: i32,
	y: i32,
};

// Create an instance
let point = Point {
	x: 2,
	y: 4,
};

// Change a value inside the structure
let point = Point {
	x: 4,
	...point,
};
```

Wait, what!?

Rust lets us create a value with the same name as a previous value. The second value *shadows* the first definition, effectively hiding it. This enables us to reuse the same name for the same thing, without having to come up with 3 ways to name it.

This also makes it easy to swap out an immutable structure, with an updated one, without having to change the name:

```
// Instead of this:
let point = Point { x: 2, y: 4 };
let updated_point = Point { x: 4, ...point };

// We do this:
let point = Point { x: 2, y: 4 };
let point = Point { x: 4, ...point };
```

Rust also has a spread operator which fills in the rest of the values in the structure with the values from an existing structure instance. The values we've defined in the new structure have the higher priority. Any value not assigned in the new instance of the structure will be filled with the corresponding value from the first structure.

Immutability as the default is something I truly enjoy.
Blockchain vs Bitcoin
Tags: blockchainvsbitcoin, blockchain, vs, bitcoin
Published: 2019-04-23 09:47:16

---
title: Blockchain vs Bitcoin
published: true
description: As most of us know blockchain came into limelight in 2009 with the ICO of bitcoin which was developed by Satoshi Nakamoto. What we don’t know and not even questioned ourselves was why an alternative currency was developed which has no financial backing even though it became extravagantly popular was as valuable as 20,000 USD in 2016.
tags: Blockchain vs Bitcoin, blockchain, vs, bitcoin
---
<img src="https://thepracticaldev.s3.amazonaws.com/i/92gf735d6n1jzfd3ec8g.png" />

As most of us know blockchain came into limelight in 2009 with the ICO of bitcoin which was developed by Satoshi Nakamoto. What we don’t know and not even questioned ourselves was why an alternative currency was developed which has no financial backing even though it became extravagantly popular was as valuable as 20,000 USD in 2016.

https://www.decipherzone.com/blog-detail/Blockchain-vs-Bitcoin--An-Investor-s-Perspective

Bitcoin was just a camouflage to introduce blockchain and to generate financial support for its development. Blockchain is a system where multiple nodes are connected through peer to peer connection and use a single ledger to record transactions and then data is encrypted using the hashing algorithm and public key from the previous node. This encrypted data is validated from other nodes using proof of work and consensus protocol. Blockchain development requires computing power and internet, in order to do so, blockchain programmers started rewarding tokens i.e Bitcoins which were given to contributors proving computing power to validate transactions and called them miners. These Bitcoins were first released through an ICO on exchanges where people started trading them. The possibility to earn money by contributing computing power to blockchain network increased the number of miners which resulted in ramping up the difficulty curve to generate a bitcoin. Low production and high demand for bitcoin on exchanges surged its prices to 20000 USD in 2016.
Server side application skeleton for Go language
Tags: go, web
Published: 2019-04-23 08:54:30

---
title: Server side application skeleton for Go language
published: true
description: 
tags: golang, web
---

Writing web application in Go can be pretty hard if you take care about login process wich include signing in, singing out, password recovery and minimal user management (like changing name, password and deleting account).

The solution can be a high level skeleton to help all those developers to focus on the application content.

Project is a work in progress, hosted on Github and is documented with code examples and some pictures.
 
[https://github.com/geosoft1/ssas](https://github.com/geosoft1/ssas)

How the things works? Supposing you have some experience with Go language and Mysql database, download the project from repository and compile.

You must create a database on your server and import `database.sql` file into (adjust before the file with your database name). In `model` folder you will find a model for Mysql Workbench application. You can use this model to sincronize with an existing database.

Next, you must complete the configuration file `conf.json`. Basically you must set the database connection informations like ip/domain, user, password and schema name.

Also, you may need to set the mailer for password recovery procedure. No big deal here, use a mailbox created for this purpose.

If you run the skeleton for the first time you will be asked to add a new user (or signup).

![signup](https://github.com/geosoft1/ssas/raw/master/static/images/signup.png)

Feel free to do this and then login

![signin](https://github.com/geosoft1/ssas/raw/master/static/images/signin.png)

After that you must see the home page

![home](https://github.com/geosoft1/ssas/raw/master/static/images/home.png)

You can manage local user account, logout and recovery forgotten password by clicking on the options from the top right bar.

![user](https://github.com/geosoft1/ssas/raw/master/static/images/user.png)

A nice part is that you have a fallback offline page for network fails.

![home](https://github.com/geosoft1/ssas/raw/master/static/images/cache.png)

Now you are ready to write your applications, take a look over [how to add simple application](https://github.com/geosoft1/ssas#adding-a-simple-application) section from documentation to see how to extend the skeleton with new functionalities. A dummy example explain this.

Note that you will need a HTML5 browser to see the application but you shouldn't have problems with modern browsers. You can also use Chrome [application](https://developers.google.com/web/fundamentals/app-install-banners/) mode for an experience more closest to native applications.

Enjoy.
Set CSS styles with javascript
Tags: css, javascript, cssom
Published: 2019-04-23 08:29:28

---
title: Set CSS styles with javascript
published: true
description: Explore options to add CSS with JS
tags: css, javascript, cssom
---

Let's say you have a paragraph.

```html
<p id="target">rainbow 🌈</p>
```
And you need to change it's color with JS. What options do you have?

## 1. Inline styles

The most straightforward path. Query the element from DOM and change it's inline styles.
```js
document.getElementById('target').style.color = 'tomato';
```
![inline styles](https://thepracticaldev.s3.amazonaws.com/i/hd67z2je0m8u7zyf7231.jpg)

Short and simple.

## 2. Global styles

Another option is to create `<style>` tag, fill it with CSS rules and append the tag to the DOM.

```js
  var style = document.createElement('style');
  style.innerHTML = `
  #target {
  color: blueviolet;
  }
  `;
  document.head.appendChild(style);
```

![global styles](https://thepracticaldev.s3.amazonaws.com/i/zhkm5phjflfick5xesu2.jpg)

## 3. CSSOM insertRule

Third option is less known. We gonna use [CSSStyleSheet](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet) `insertRule` method.
```js
  var style = document.createElement('style');
  document.head.appendChild(style);
  style.sheet.insertRule('#target {color: darkseagreen}');
```

While it might look similar to the 2nd option, it's definitely different.
![insertRule](https://thepracticaldev.s3.amazonaws.com/i/trjxmsf01o01w8c7u224.jpg)

As you can see in Chrome devtools, `<style>` tag is empty, but the style (darkseagreen color) is applied to the element. Also the color can't be changed via devtools because Chrome doesn't allow [editing dynamic CSS styles](https://bugs.chromium.org/p/chromium/issues/detail?id=387952).

Actually such behavior was the motivation to write this post. A popular CSS-in-JS library [Styled Components](https://www.styled-components.com/) use this feature to inject styles in production mode because of performance. This feature might be undesirable in specific projects or environments and some folks complain about it in the project's issues.

## 4. Constructable Stylesheets (July 2019 update)

It's now possible to create `CSSStyleSheet` object from JavaScript.
```js
// Create our shared stylesheet:
const sheet = new CSSStyleSheet();
sheet.replaceSync('#target {color: darkseagreen}');

// Apply the stylesheet to a document:
document.adoptedStyleSheets = [sheet];
```
More details are [here](https://developers.google.com/web/updates/2019/02/constructable-stylesheets).
This option is only valid for Chrome, so use with caution. 

Do you know other options to add styles with javascript? What is your preferred option these days?

Thanks for reading!
Using IoC in ASP.NET MVC
Tags: ioc, aspnet, c, azure
Published: 2020-01-23 19:42:40

---
title: Using IoC in ASP.NET MVC
published: true
date: 2019-04-22 23:46:37 UTC
tags: ioc,asp.net,c#,azure
canonical_url: https://barranger.dev//Using-IoC-in-ASP.NET-MVC/
---

## Why use IoC

The reasons to use IoC are numerous, but specifically for ASP.NET it will allow you to keep code isolated into functional components, and allow you to migrate those functional components to newer/more appropriate technologies.

Another major use for IoC is in testing. Where you will use full database repositories for production, using static data is often more than enough for unit tests.

## Which IoC Container

Since you are currently using ASP.Net MVC , the best option currently is Unity (no not the game engine :) ). Not that .NET Core has it’s own IoC tooling, but most, if not all, of the options here will be easily migrated when the time comes.

## Sample Project

To illustrate the concepts in this doc, I’ve created the worlds simplest project to go through these examples, that project can be found [here](https://github.com/barranger/IoCTutorial).

The sample project will simply display a quote received form a quote service, that implements the `IQuoteService.cs` Interface

## Register Services

Once adding the `Unity.MVC` library via NuGet, you’ll find both `UnityConfig.cs` and `UnityMvcActivator.cs` in your `App_Start` folder. The `UnityConfig.cs` file is where you register the services, like so:

```
public static void RegisterTypes(IUnityContainer container)
{
	// TODO: Register your type's mappings here.
    container.RegisterType<IQuoteService, StaticQuoteService>();
}
```

Where `IQuoteService` is the interface that we are registering, and `StaticQuoteService` is the concrete implementation of the Interface that we will be exposing to the system.

## Using Services

Once the services are setup, we’ll want to use them, in the case of Controllers, this is extremely easy as Unity will auto add them to our application if we declare the interfaces as parameter to our constructors like so:

```
private IQuoteService quoteService;

public HomeController(IQuoteService quoteService)
{
	this.quoteService = quoteService;
}
```

we can then use the service anywhere in the controller, like the sample does for the `About` route:

```
public ActionResult About()
{
	ViewBag.Message = this.quoteService.GetRandomQuote();
	return View();
}
```

Sometimes you will need to access the services outside of a controller, which we can also do by using `UnityConfig.Container` like so:

```
public static string GetRandomQuote()
 {
 	var service = UnityConfig.Container.Resolve(typeof(IQuoteService), null) as IQuoteService;
 	
    return $"From the RandomUtil: {service.GetRandomQuote()}";
 }
```
Nasha Mukti Kendra in Punjab
Published: 2019-04-23 08:23:24

---
title: Nasha Mukti Kendra in Punjab
published: true
description: <a href="http://lifelinefoundations.win/nasha-mukti-kendra-punjab/">Nasha Mukti Kendra in Punjab</a> offers de-addiction and detoxification treatment. We are the best De-Addiction Treatment centre in Punjab.
tags: 
---
Enable the dark theme on Chromium based Edge browser
Tags: edge, chromium
Published: 2019-04-23 08:05:29

Some weeks ago, Microsoft released a new browser based on Chromium.
At the moment you can use two main released channel: Dev and Canary.

![](https://thepracticaldev.s3.amazonaws.com/i/rz39sko2k03mudcw13sk.PNG)

In the future it will be possible to download and use the Beta Channel.

At the moment you can enable the dark theme in both channels.
It's very simple:

* Open a new tab on Edge and go here: **edge://flags/#edge-follow-os-theme**
* Select "**Enabled**" in the dropdown
* From your desktop, go to **Personalization -> Colors** and change the theme to dark on Windows

![](https://thepracticaldev.s3.amazonaws.com/i/6sp3je03oyb5sxiz398n.PNG)

Now the Edge theme reflects your Windows theme.

![](https://thepracticaldev.s3.amazonaws.com/i/nz90iu5q29xw7mswx255.PNG)
Your choice: go big, or get real
Tags: dailywriting
Published: 2019-04-23 16:36:29

---
title: Your choice: go big, or get real
published: true
tags: daily-writing
canonical_url: https://marcusblankenship.com/your-choice-go-big-or-get-real/
---

I’ve been a jittery, nervous wreck for a week because of the workshop which starts on Wednesday.

It reminds me of singing a solo in a Junior High musical – I’m terrified that I’ll forget the words, look like an idiot… or pee my pants on stage.

Yeah – you get it: I’m nervous.

I have found that in these moments, I have a choice.

## Go big or get real

When I feel insecure, my default has long been to pretend that I’m fine – calm, cool, collected, and in control. The man with the plan.

I call this “going big”. It’s when I pretend to be large and in-charge. Except, sometimes people get hurt in the process.

But there’s a problem with that.

See, if anything threatens the plan, or doesn’t go perfectly, I tend to get upset. I start holding on to my plan too tight, and I try too hard to keep things going the way I planned.

For example, once I was in such a hurry to finish a workshop exercise that I didn’t notice a participant was silently crying, trying to cope with a super painful work situation that the exercise reminded him of.

By the time I noticed, I’d bulldozed through the moment to keep us on schedule. Ugh.

# Instead, now I get real.

Now, I do my best to remember that I’m there to respond to the participants, not keep them ‘on schedule’.

I’m there to lead them by creating an environment where everyone can safely participate, experiment, communicate, challenge, discuss their mistakes, and get real with each other.

The only way I can do that for them is if I do it for me, first.

Because you can’t give what you don’t have.

I’m sure the workshop won’t go as planned.

In fact, my outlines have gotten vaguer as I’ve learned that the good stuff happens _between_ the things you’ve planned. That’s when the magic happens between people.

It’s when leadership happens too, between real people, at the most unexpected times.

So today I want you to keep an eye out for the magic, be ready for the unexpected emotion, and keep it real.

That’s when the good stuff happens.

Tomorrow I’ve got a surprise from a sponsor for ya – so watch your mailbox.

Doing my best to keep it real,

Marcus

The post [Your choice: go big, or get real](https://marcusblankenship.com/your-choice-go-big-or-get-real/) appeared first on [Marcus Blankenship](https://marcusblankenship.com).
Weekly Coding Challenge - Week #8 - Chat Interface
Tags: challenge, html, css
Published: 2019-04-23 04:29:01

---
title: Weekly Coding Challenge - Week #8 - Chat Interface
published: true
description: Week #8 of the Weekly Coding Challenge program - Chat Interface
tags: challenge, html, css
canonical_url: https://www.florin-pop.com/blog/2019/04/chat-interface/
cover_image: https://www.florin-pop.com/static/bac0cfd6fa41e8e6d03c8bc18109b19c/ff993/chat-interface.png
series: Weekly Coding Challenge
---

Theme of the week: **Chat Interface**

### Description

Everyone is using a chat of some sort nowadays so in this article we're going to create the bare bones of a chat application. We'll start with the HTML/CSS to create the layout and in a future post we'll hook it up to a server and allow the users to communicate with each other.

## Useful Resources

Check out my submission for this challenge: [Chat Interface](https://www.florin-pop.com/blog/2019/04/chat-interface/).

See all the submissions in this [Codepen Collection](https://codepen.io/collection/XEEkdY/).

Are you interested in joining the challenge? :smiley: Read [The Complete Guide](https://www.florin-pop.com/blog/2019/03/weekly-coding-challenge/) to find out how. Don't forget to share your creation! :wink:

Happy Coding! :innocent:
Log MongoDB query plans when the query is slow.
Tags: webdev, node, mongodb, mongoose
Published: 2019-04-23 03:27:06

---
title: Log MongoDB query plans when the query is slow.
published: true
description: A Mongoose plugin to show query plans when the query is slow.
tags: #webdev #node #mongodb #mongoose
---

## How to tune the performance issue about MongoDB?
We can use `.explain()` then [MongoDB](https://www.mongodb.com/) will return [explain-results](https://docs.mongodb.com/manual/reference/explain-results/).
The explain-results are look like this.
```
"executionStats" : {
   "executionSuccess" : <boolean>,
   "nReturned" : <int>,
   "executionTimeMillis" : <int>,
   "totalKeysExamined" : <int>,
   "totalDocsExamined" : <int>,
   "executionStages" : {
      "stage" : <STAGE1>
      "nReturned" : <int>,
      "executionTimeMillisEstimate" : <int>,
      "works" : <int>,
      "advanced" : <int>,
      "needTime" : <int>,
      "needYield" : <int>,
      "saveState" : <int>,
      "restoreState" : <int>,
      "isEOF" : <boolean>,
      ...
      "inputStage" : {
         "stage" : <STAGE2>,
         "nReturned" : <int>,
         "executionTimeMillisEstimate" : <int>,
         ...
         "inputStage" : {
            ...
         }
      }
   },
   "allPlansExecution" : [
      {
         "nReturned" : <int>,
         "executionTimeMillisEstimate" : <int>,
         "totalKeysExamined" : <int>,
         "totalDocsExamined" :<int>,
         "executionStages" : {
            "stage" : <STAGEA>,
            "nReturned" : <int>,
            "executionTimeMillisEstimate" : <int>,
            ...
            "inputStage" : {
               "stage" : <STAGEB>,
               ...
               "inputStage" : {
                 ...
               }
            }
         }
      },
      ...
   ]
}
```
+ `executionStats.totalDocsExamined` too large means your query need scan a lot of documents.
+ When the `stage` is `COLLSCAN` means MongoDB scanning documents from the collection not the index. Scanning from the index is more quickly than from the collection.

When we log all explain-results on the console. There are too much information, so that we can't find we want.

## A [Mongoose](https://mongoosejs.com/) plugin to show query plans when the query is slow.
You can set your own when to show the explain result.

{% github kelp404/mongoose-profiler %}

```js
const mongooseProfiler = require('mongoose-profiler');
schema.plugin(mongooseProfiler({
  isAlwaysShowQuery: true,
  duration: 1000,          // Show query plans when it took more than this time (ms).
  totalDocsExamined: 1000, // Show query plans when "totalDocsExamined" more than this value.
  level: 'COLLSCAN'        // Show query plans when the stage is "COLLSCAN".
}));
```
Job Search - Day 4 of 42
Tags: jobsearch, businesscards, agile
Published: 2019-04-23 03:18:08

---
title: Job Search - Day 4 of 42
published: true
description: Morning interviews, personal page, business cards, more interviews
tags: jobsearch, business cards, agile
---

```
run with the lean dog
python dev remote or cle
cards for conferences
```

Started off with a great call at 10am
May land an interview next to my spirit animal, an *agile technical coach*
Three other inbound calls

Created [personal github.io](https://dev3l.github.io) page

# Business Cards

Attending conference, representing myself
Speaking at conferences, representing myself
First time for everything

![Font Business Card](https://thepracticaldev.s3.amazonaws.com/i/lgxcv7ashdp9s9ysvfrw.png)

![Back Business Card](https://thepracticaldev.s3.amazonaws.com/i/37vzp4cw95oqpbhj2n6a.png)
Anybody wants to start/practice contributing to OSS projects??
Tags: opensource, beginners, practice, help
Published: 2019-04-23 00:21:03

---
title: Anybody wants to start/practice contributing to OSS projects??
published: true
description: 
tags: OSS, beginners, practice, help
---

# Introduction
I made this super simple ruby gem called [spell_generator](https://github.com/K-Sato1995/spell_generator) and looking for people who want to start/practice contributing to OSS projects.

# Why?
Making a PR to an OSS project can be intimidating if you don't know how to actually do to it. But if you know the process of making a PR and have already done it before, it can be very simple and fun. 
I want to help people who have been thinking about contributing to OSS projects but have been too scared to do it.
Especially if you are a self-taught programmer or new graduate who is looking for some experience to put on your resume, contributions to OSS projects would be great to have as your experience.

__I want to help you to take the first step of your OSS journey.__

# What I want you to do
As I mentioned above, this gem I created is very simple. 
All it does is creating a random spell based on adjectives and verbs that are stored in different arrays respectively.

I want you to add one or more adjectives or verbs to the corresponding array.

https://github.com/K-Sato1995/spell_generator/issues/1


---
Or You can just make an issue and make some improvements on the gem.

# How?

Here is an amazing post about how to contribute to GitHub projects by Rob Allen.
You can follow the steps in the post.

- [The beginner’s guide to contributing to a GitHub project – Rob Allen's DevNotes](https://akrabat.com/the-beginners-guide-to-contributing-to-a-github-project/)