teleren/devto huggingface dataset:
Getters and Setters
Published: 2017-10-13 23:43:26

---
title: Getters and Setters
published: true
description: 
tags: 
---

Some test automation I “inherited” a while back dealt with a textbox, labelled `Brick` (not quite its real name), whose getter method was called `GetCurrentBrick`.

Take just a moment to try to guess what the corresponding setter was called.

It was called `Brk`.

Nice, huh?  Getter/setter pair:  `GetCurrentBrick` and `Brk`.

Now if there is going to be a getter/setter pair (and I'll get to that question in a moment), the two should at least have consistent naming.

A start would be `GetCurrentBrick` and `SetCurrentBrick`.

Actually, though, the page had nothing else about bricks, so it would be better to say just `GetBrick` and `SetBrick`.

But why have two methods at all?  A setter should always return the previous value, in case the caller needs to restore it. Therefore it’s simple and useful to have a single method that always gets and can, optionally, set.

Thus:

- `Brick()` with no value parameter is a pure getter.
- `Brick("in the Wall")` is a setter that returns the previous value.

This means there’s only one method name to learn, and it’s pretty intuitive that the value-less call is a getter, while the value-bearing call is a setter.
Browser Caching 
Tags: likeim5
Published: 2017-10-13 23:23:27

---
title: Browser Caching 
published: true
description: Illustration of browser caching 
tags: LikeI'm5
---
<img src="https://thepracticaldev.s3.amazonaws.com/i/6ru4dmtv6ch0566umahp.jpeg" alt"road">
Ever noticed how traveling to somewhere new seems very far? But on your 2nd trip it's short, well that's how browser cache works. On the first load of the page it takes longer just like the first trip, then the browser stores some data in the systems memory, just like the way your brain stores images of landmarks or buildings in your memory. So on your return trip it recollects the images, making the journey seem shorter, same thing with the browser, it retrieves the store data from the systems memory saving it the trip to the servers thus making the page load faster.

Just some random illustration that came to my mind could be used to explain to someone.
Combining Blade templates with Vue.js
Tags: laravel, seo, vue
Published: 2018-08-11 13:42:00

---
title: Combining Blade templates with Vue.js
published: true
tags: laravel,seo,vuejs
canonical_url: https://medium.com/@treggats/combining-blade-templates-with-vue-js-868937bb0f6
---

In a project that I am working on, there are currently two public facing parts.

1. Website
2. Backoffice

In a discussion about what (front-end) technique we should use. Vue.js being a big contender. But a big concern was _Search Engine Optimization_ for the website.

Having no experience with prerender options (prerender.io, Nuxt.js) we chose to use the default template engine in Laravel projects ([Blade](https://laravel.com/docs/5.5/blade)).

I’d like to show how I went about and implemented this. Source code for an example project can be found on [Github](https://github.com/Treggats/co-housing-blade-vuejs).

Starting from scratch, I just created a fresh Laravel project with

> composer create-project laravel/laravel co-housing-blade-vuejs

The next step is to create some structure. Go to **resources/views** and add a directory called backoffice. And in that directory create a view called index.blade.php

![](https://cdn-images-1.medium.com/max/1024/1*5_PrEHF0RNNCgjnsqUgqBQ.png)

In that file reference the app.css and app.js, put the latter at the bottom of the body tag. Otherwise Vue won’t load. And put one div with an id of app in the body.

Next add two controllers, **PageController** & **Backoffice\PageController** and update the current route to point to the main index method of the _PageController._

Also add the route for the index method for the backend _PageController_.

Load the default welcome view in that method.

![](https://cdn-images-1.medium.com/max/1024/1*3CGwWx0kKUfAX2EIpz8ehQ.png)

![](https://cdn-images-1.medium.com/max/1024/1*qJsef3otvbqhbvKNRnJ4YA.png)<figcaption>Both controllers</figcaption>

![](https://cdn-images-1.medium.com/max/1024/1*s3yfsQS2G5D9armQyls6Hg.png)<figcaption>Web routes</figcaption>

By default a new Laravel project comes with an example Vue.js component, which is loaded in the _backoffice/index.blade.php_ template. So all that is needed to show the Vue.js template is to run

> npm run dev || yarn run dev

The result is that the ‘normal’ website is build using blade templates and that everything in the ‘backoffice’ route prefix is being rendered by Vue.js

So in closing we have two different front-end techniques in use due to SEO concerns. In a next article I’ll be looking into alternatives to only use Vue.js in the front-end.
Taking advantage of BitMasks
Tags: csharp, devtips, algorithms, computerscience
Published: 2017-10-13 17:11:43

---
title: Taking advantage of BitMasks
published: true
description: 
tags: #CSharp #devtips #algorithms #computerscience
---
![Binary](https://thepracticaldev.s3.amazonaws.com/i/8b25vhmztxkltsgmodqn.jpeg)
Recently I needed a way to store a finite list or error messages that could potentially occur during an async process.  
I could have implemented something like - creating a relational table structure, store them as a JSON file etc.  All of the alternatives felt a bit like 'overkill' for reasons I won't go into here.  So I decided to opt for a Bitmask.  Why?  Well, essentially, bitmasks are a great way to store a large amount of 'information' in a small space.  

Here are the potential errors that I needed to log.

- invalidName
- invalidDate
- invalidTime
- invalidType
- invalidRange
- invalidState

So what Bitmasking allowed me to do was to assign an integer value to each of the potential errors. So:

- invalidName = 1
- invalidDate = 2
- invalidTime = 4
- invalidType = 8
- invalidRange = 16
- invalidState = 32

_Usage_
In C# land we would implement something like this:

```c#
using System;
					
public class Program
{
	static int _errorTotal = 0;

	public static void Main()
	{			
		//simulate some errors
		_errorTotal += (int)Errors.Name;
		_errorTotal += (int)Errors.Date;
		_errorTotal += (int)Errors.Time;
		_errorTotal += (int)Errors.Type;
		
		Console.WriteLine("Error total: {0}", _errorTotal); // this is what we persist
		Console.WriteLine("Error list: {0}", (Errors)_errorTotal); // this is how we read the data back out
	}
	
	// Holds the value of each of the error types
	[Flags]
        public enum Errors 
	{
		Name = 1,
		Date = 2,
		Time = 4,
		Type = 8,
		Range = 16,
		State = 32
	}
}
```

Output: 
`Error total: 15
Error list: Name, Date, Time, Type`

We can now see how storing just one integer value, you can gain access to any combination of errors that occurred during the async process.

Note: Like I said at the start, this is a great way of storing a finite list of 'stuff' - for particularly long lists of 'stuff', you might want to cast your `[Flag]` enum to `(long)`:

```c#
[Flags]
public enum Errors : long
{
	Name = (long)1,
	Date = (long)2,
	Time = (long)4,
        ...
```
The World of Emacs
Tags: showdev, emacs
Published: 2017-10-13 16:35:28

---
title: The World of Emacs
published: true
description: A brief guide for getting into and through the world of Emacs
canonical_url: https://github.com/myTerminal/world-of-emacs
tags: showdev, emacs
---

I've come across a lot of stories where people stumbled upon Emacs and it took over their computer by being more than just a text-editor for them. It quickly turned into a passion for them, and they ended up spending their time looking for every possible way to fine-tune their configuration, add more packages and talk about it to as many people as they can, all the time.

I've also seen people having trouble at the start and they need all the help they can get during their early days with Emacs as there are a lot of questions and the answers are scattered all over the internet which can be

1. Hard to find
2. Cumbersome to switch between sources

Though this makes it look like one would use Emacs only "if they are worthy of it" and they need to prove it by making the effort to learn it, how about we make it easy for the newbies by providing this information at one place to start from?

To make this possible, I came up with a mini-guide to Emacs for newbies that is not a guide in itself, but can act as a map by providing pointers to actual useful content that is scattered all around the universe.

You can find the project on GitHub: [world-of-emacs](https://github.com/myTerminal/world-of-emacs)

Do let me know your thoughts about it and enlighten me with some bright ideas from the developer community!
sudo apt-get install emacs25
Tags: ubuntu, install, emacs, linux
Published: 2017-10-13 16:06:12

---
title: sudo apt-get install emacs25
published: published
description: Install Emacs25 on Ubuntu Server 16.04.3
tags: Ubuntu,Install,Emacs,Linux
---


<a href="https://framapic.org/nVAWqZ4JtQZx/rTeAQcmtqmv1.png"Picture">
<img border="0" alt="W3Schools" src="https://framapic.org/nVAWqZ4JtQZx/rTeAQcmtqmv1.png">
</a>

```shell
~ sudo add-apt-repository ppa:kelleyk/emacs
```
```shell
~ sudo apt-get update
```
```shell
➜  ~ sudo apt-get install emacs25
[sudo] password for psn: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  emacs25-common
The following NEW packages will be installed:
  emacs25 emacs25-common
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 21.0 MB of archives.
After this operation, 90.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://ppa.launchpad.net/kelleyk/emacs/ubuntu xenial/main amd64 emacs25-common all 25.3~1.gite0284ab-kk1+16.04 [17.2 MB]
Get:2 http://ppa.launchpad.net/kelleyk/emacs/ubuntu xenial/main amd64 emacs25 amd64 25.3~1.gite0284ab-kk1+16.04 [3,792 kB]                                                                   
Fetched 21.0 MB in 1min 16s (276 kB/s)                                                                                                                                                       
Selecting previously unselected package emacs25-common.
(Reading database ... 153708 files and directories currently installed.)
Preparing to unpack .../emacs25-common_25.3~1.gite0284ab-kk1+16.04_all.deb ...
Unpacking emacs25-common (25.3~1.gite0284ab-kk1+16.04) ...
Selecting previously unselected package emacs25.
Preparing to unpack .../emacs25_25.3~1.gite0284ab-kk1+16.04_amd64.deb ...
Unpacking emacs25 (25.3~1.gite0284ab-kk1+16.04) ...
Processing triggers for mime-support (3.59ubuntu1) ...
Processing triggers for hicolor-icon-theme (0.15-0ubuntu1) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for install-info (6.1.0.dfsg.1-5) ...
Setting up emacs25-common (25.3~1.gite0284ab-kk1+16.04) ...
Setting up emacs25 (25.3~1.gite0284ab-kk1+16.04) ...
update-alternatives: using /usr/bin/emacs-25.325 to provide /usr/bin/emacs-25.3 (emacs-25.3) in auto mode
```
Start Emacs25.3
```shell
~ emacs25
```
{% twitter 918870636319133696 %}
Writing a Stepped Slider in Fuse
Tags: video, fuse, coding, ui
Published: 2017-10-13 14:53:37

---
title: Writing a Stepped Slider in Fuse
published: true
description: A stepped slider with indicators and snapping animation
tags: video, fuse, coding, ui
---

{% youtube jYAEf8fSLLQ %}

This time I write a linear slider with fixed stepping values. This was recently reported as not working so I had to fix the code first. After doing this video I found another defect in LinearRangeBehavior that I'm off to fix now.
Nevertheless, Lida Coded
Tags: wecoded
Published: 2017-03-07 23:15:49

---
title: Nevertheless, Lida Coded 
published: true
tags: shecoded
---

## I began coding because...

It turned out not to be about fixing the family's computer or playing video games, but a way to organize your thought, to customize things to your taste and needs and a tool to express your creativity and challenge your mind and imagination.

## I'm currently hacking on...

The power control systems software in the particle accelerators at CERN.
I focus on the software quality assurance of the libraries and applications of the embedded computers controlling the powering of the magnets that drive the beam of particles. Yay!

## I'm excited about...

Software and Design and everything in between. For me, it needs to be interesting as a process and also to have a purpose. This usually happens when working on something completely useless that fulfills a weird artistic need or something really useful with an impact on society.

## My advice for other women who code is...

Try not to get discouraged by the culture in the university or the industry: join communities with other women who code to share your experiences and support each other, seek role models to help you stick to your goals. 

Try to not be too harsh on yourself: don't feel the pressure to prove your worth every single day by fear of confirming a stereotype and don't feel the need to be 100% ready to get out there, nobody is.
A Little Fun with Assembly
Tags: assembly, compiler
Published: 2017-10-13 14:03:41

---
title: A Little Fun with Assembly
published: true
description: Tackling a simple programming quiz by looking at compiler output
tags: #assembly #compiler
---

_Originally published on [my blog](http://harvid.blogspot.com/2014/12/fun-with-assembly.html) in 2014_

I still remember an interview I had around February 2001, in which an embedded firmware engineer talked about how his team wrote code:

> We write stuff in Assembler, because we're too lazy to write stuff in C.

Wait...what?  I thought the whole purpose of C was to have portable Assembly, so you could control the bare metal correctly?  I did get an inkling if you were that good, assembly could be seductive in your ability to do whatever you want.

This came to mind again when a [former colleague of mine](https://twitter.com/robododo) posed a similar question on Facebook the other night:

> Pop quiz: When you run this, what prints out? 

{% gist https://gist.github.com/miniharryc/6033aaa96e0f9b7564d7 %}

Basically, the above is a quiz to determine if you understand loops, expressions -versus- statements, and the pre-decrement operator (`--`).  Pre-decrement specifies that the lvalue of the expression is the current value minus one and the post-state of that variable is assigned that decremented value.  Post-decrement has the same result (decrementing the value), but the lvalue of the expression is the PREVIOUS value.

As is my wont, I got the above wrong, but that's not the point. :-D

To check my answer, I sucked it into quick c program using vim:
Compiling that program and using mac's [`otool`](http://www.unix.com/man-page/osx/1/otool/) to dump the assembly gives you this:

### Unoptimized version

{% gist https://gist.github.com/miniharryc/4008a189535a6250d90e %}

Some things to note in the above:

- The compiler has done a faithful job of translating exactly the program (as-is) to assembler:
- We load the variables in lines 9 and 10
- We have the first loop in lines 11-22
- The second loop (despite being a no-op) _still exists_, in lines 24-29

### Compiler-optimized version

Things get slightly more interesting when you pass the -O (optimize) flag

{% gist https://gist.github.com/miniharryc/e9b24eab7221c6ae4333 %}

Some things to note:

- This looks nothing like the C code.  There are no loops (or indeed, branch instructions) at all.
- The compiler determined the second loop to be a no-op, and compiled it away completely.
- Our stack variables are gone.  The compiler is using x64 CPU registers exclusively. 
- The compiler has analyzed the loop and unrolled it into discrete calls to `callq` for the printf function.

Lastly:  The **answer to the quiz** is in the assembly if you look hard enough:

```
5 9
5 8
5 7
5 6
5 5
5 4
5 3
5 2
5 1
```

Pretty cool....I never get to look at assembly in my day-job, so getting this close to the CPU was a neat
Snake over Telnet in Go
Tags: go, telnet
Published: 2017-10-13 09:47:41

---
title: Snake over Telnet in Go
published: true
description: Snake over Telnet in Go
tags: go,telnet
---

Telnet games were very popular some time ago, especially this Star Wars movie: `telnet towel.blinkenlights.nl`.

I wanted to create something in Go, and I wrote this [Snake game over Telnet](https://github.com/plutov/go-snake-telnet).

Go is awesome in this case, no need any dependencies to build this funny stuff.

Try it:

```
telnet pliutau.com 8080
```

![go-snake-telnet](http://pliutau.com/go-snake-telnet.gif)

### Development

```
go get github.com/plutov/go-snake-telnet
go-snake-telnet --host localhost --port 8080
```

### Contribute

It's open source project, so feel free to contribute - [go-snake-telnet](https://github.com/plutov/go-snake-telnet).
Solutions Distribution of the N-Queens Problem
Tags: nqueenspuzzle, nqueensproblem, nqueenscompletion, qpsdistribution
Published: 2017-10-12 22:55:39

---
title: Solutions Distribution of the N-Queens Problem
published: true
description: 
tags: n-queens puzzle, n-queens problem, n-queens completion, QPSdistribution 
cover_image: https://thepracticaldev.s3.amazonaws.com/i/47bgr47rj3e92mb7piya.jpg
---

I would like to share some interesting results of playing with the N-Queens Problem solver. The following plots represent distribution of the solutions number depending on the arrangement of a subset of queens. This distribution is built by iterating the possible permutations of such a subset and counting the number of all solutions containing the current permutation (i.e. by solving N-Queens Completion Problem for each permutation).
In this particular case, subset consists of three queens that occupy the first three adjacent columns and only the permutations without overlaps (no one attacks each other) are enumerated. The subset length affects the resolution of the plot but not the general nature of the distribution.

![plots_img](https://thepracticaldev.s3.amazonaws.com/i/0iiedd6qg31toxbdkuoh.jpg)

[Here](https://plot.ly/create/?fid=Zubetto:7) you can see results and data for N = 13, 14 ... 17
Turning off the syntax highlighter
Tags: vim, code, programming, discuss
Published: 2017-10-12 19:08:57

---
title: Turning off the syntax highlighter
published: true
description: 
tags: vim, code, programming, discuss
---

Well... first of all, this is a well-known topic that widely discussed everywhere already.

- [1] https://www.robertmelton.com/project/syntax-highlighting-off/
- [2] https://dudzik.co/digress-into-development/syntax-off/
- [3] http://www.linusakesson.net/programming/syntaxhighlighting/
- [4] https://groups.google.com/forum/#!msg/golang-nuts/hJHCAaiL0so/kG3BHV6QFfIJ
- [5] http://howivim.com/2016/damian-conway/
- [6] https://twitter.com/enneff/status/710071512330477568
- [7] https://www.youtube.com/watch?feature=player_embedded&v=dkZFtimgAcM#t=15m58s

So I started turning off my Vim's syntax color from May this year, it's 5 months already.

![](https://thefullsnack.com/posts/img/no-color-vim.png)

There some real benefits for it that I can confirmed now:'

- Getting more focus on the work, that mean, more productivity
- Read/understand the code better, and even faster
- Vim run faster as well
- ~~Being way more cooler~~, my colleagues now look at me as a guy from Mars

Is there anyone doing the same thing?

**P/S:** This is the color scheme I'm using for my vim https://gist.github.com/huytd/8394f21bda3a08be025813c060d64e75
php sudo mysql_secure_installation
Tags: mysql, linux, ubuntu, install
Published: 2017-10-12 17:06:22

---
title: php sudo mysql_secure_installation
published: published
description: Remove some defaults that are dangerous to use in a production environment.
tags: mysql,linux,ubuntu,install
---

```shell
➜  php sudo mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Please set the password for root here.

New password: 

Re-enter new password: 

Estimated strength of the password: 0 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : 

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 

```