teleren/devto huggingface dataset:
Declaring Variables in Go
Tags: go, fundamentals, variables
Published: 2020-02-06 03:31:21

---
title: Declaring Variables in Go
published: true
description: How to define variables in Golang.
tags: Go, Golang, Fundamentals, Variables
canonical_url: https://www.rahatcodes.com/posts/declaringvariablesingo/
---

I've recently taken up learning Go on the side to broaden my knowledge as a developer and dive into some backend a little more. Since I'm learning this language from scratch there are lots of things I'm going to be sharing. This post starts off a little small with declaring variables in Go. 

Declaring variables is probably one of the first things you learn in any language after a Hello World! (We're skipping that here). Let's look at one way of doing a variable declaration:

```golang
var name string = "Rahat"
```

Ok so...yay var looks like there isn't a let and const war in this language...that was a JavaScript joke. Go is a statically typed language so if you're like me and used to dynamic languages like JavaScript, Python, or Ruby you might say at first, oh this is different. In Go we keep the type of the variable consistent, so if name is a string I can't later replace it with some numbers, it's always got to be a string! 

That's great and all but Go gives us a nicer way of making a declaration:

```golang
name := "Rahat"
```

Looked a little weird to me at first but this is great, Go will infer that you want the variable name to be a string and you won't have to declare the type every time. One thing to note is that this syntax would only be used when declaring. If I want to change my name, later on, I would do something like this:

```golang
name := "Rahat"
name = "Goku"
```
Once I change my name to Goku I can just use an equal sign since I'm re-assigning the value of the name variable.

I hope you enjoyed the post, it would be great to see if others are learning Go as well, always looking for accountability partners! Feel free to send over a tweet or dm @rahatcodes.
Angular Forms Story: A Dev Tool
Tags: tooling, development, angular, devtools
Published: 2020-04-22 14:20:27

---
title: Angular Forms Story: A Dev Tool
published: true
date: 2020-03-17 21:24:26 UTC
tags: tooling,development,angular,devtools
canonical_url: https://itnext.io/angular-forms-story-a-dev-tool-f4a27e28c28e
cover_image: https://cdn-images-1.medium.com/max/1024/1*pphWdX9TFFb7JErYj3i0DA.png
---

#### A simple tool to make Dev’s life easy :)

This is part of the _Angular Forms Story_ series:

- _Angular Forms Story: A Dev Tool (this one)_
- _Angular Forms Story: Strong Types ([_link_](https://dev.to/gparlakov/angular-forms-story-strong-types-dmg))_
- _Angular Forms Story: The Whole Story (coming up)_

More than once, while developing forms in Angular application I had to template hack `{{form.value | json}}` and `{{form.valid}}` and form.pending while editing to check if my form control was actually doing what I wanted it to do.   
I thought:

> Wouldn’t it be nice if there was a component to show me all the info about the form?

So I created it:

[ngx-show-form-control](https://www.npmjs.com/package/ngx-show-form-control)

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

1. **Named** and **draggable** window!
2. **Status ** — dirty/pristine, touched/untouched, valid/invalid/pending/disabled
3. **Value** JSON.stringify-ed. **Editable ** — edited value appears in form!
4. **Minify** and **Maximize** And MORE…  
\* **Resizable** (see bottom right corner)  
\* Multiple **instances** supported   
\* **Only** visible in **dev** builds! **No** danger of it showing in **production**!

See it in  **action** :

![](https://cdn-images-1.medium.com/max/640/0*1woRcThhCMII4edO.gif)

Making it a directive and supporting older Angular versions is on the roadmap. It now needs Angular v5 at least — due to using Metadata version 4

Go check it out and submit issues at [https://github.com/gparlakov/forms-typed/issues](https://github.com/gparlakov/forms-typed/issues).

I am working on a few Open Source Angular Dev Tooling projects. Check them out at:  
[SCuri — Unit test boilerplate automation](https://github.com/gparlakov/scuri/blob/master/README.md) ([_with Enterprise support option too_](https://tidelift.com/subscription/pkg/npm-scuri?utm_source=npm-scuri&utm_medium=referral&utm_campaign=enterprise))  
[ngx-forms-typed — Angular form, just typed!](https://github.com/gparlakov/forms-typed/blob/master/projects/forms/README.md)  
 [ngx-show-form-control — Visualize/Edit any FormControl/Group](https://github.com/gparlakov/forms-typed/blob/master/projects/show-form-control/README.md)
Botão responsivo no Flutter
Published: 2020-03-17 21:20:25

Uma solução interessante para criar um botão responsivo no flutter é utilizar o SizedBox.expand widget, que força o filho a corresponder ao tamanho do pai.
```dart
new SizedBox.expand(
  child: new RaisedButton(...),
)
```
Existem muitas alternativas, o que permite mais ou menos essa personalização:
```dart
new SizedBox(
  width: double.infinity,
  // height: double.infinity,
  child: new RaisedButton(...),
)
```
ou usando um ConstrainedBox
```dart
new ConstrainedBox(
    constraints: const BoxConstraints(minWidth: double.infinity),
    child: new RaisedButton(...),
)
```
Shell command options you didn't know you needed #5
Tags: perl, shell, bash, linux
Published: 2020-03-17 21:05:08

Technically, this one's a Perl option, but... if your Perl usage is at the sysadmin/devops level (i.e. the Swiss Army Chainsaw) you might find this very handy for processing files and running potentially complex Perl code against every line in the file. Particularly if, like me, you speak better Perl than AWK :D

`perl -ne` (and `perl -pe`)

The `-ne` option wraps the code you provide in the argument with a loop over every line in all the input files, with the line (with trailing `CR`) stored in `$_`. The `-pe` option does the same, but adds an implicit `print $_` at the end of the loop.

A couple of trivial examples:

Extract unique IP addresses from your Apache log.

`perl -pe 's/^(\d+.\d+.\d+.\d+).*/$1/;' */access.log | sort -u` 

Poor man's grep with Perl regexes.

`perl -ne 'print if /admin\.php/;' access.log`
Exploring javascript
Tags: javascript
Published: 2020-03-17 20:44:56

#### Yet another free online book that I'm tho it is worth buying.

**Object.freeze** does exactly that except it is shallow

`ToObject` throws errors upon encountering **null** and **undefined** 

**0.1 + 0.2 !== 0.3** floating point numbers can't be represented accurately. Although numbers close to 0 can be stored more accurately

Accurate Math Functions. `Math.expm1` `Math.log1p` 
Used for asm.js `Math.fround` `Math.imul`

Bitwise operations `Math.clz32(0b0000001)`

You can represent bytes/hex/octal by adding `0b` `0x` `0o` respectively to the beginning of a string

To avoid versioning -- that thing that happened with python -- javascript made itself backwards compatible. Which proved to be difficult since old code could break upon changing. So they added "strict mode" which gives you all the new errors and enhancements to the language. This is enabled by default in classes and in modern web frameworks, you can however enable it in a single function only by adding `"use strict"`. 

[Add mixins to JavaScript](https://javascript.info/mixins)

There is the capability of making `factories` or `lazy generators` in JavaScript

Iterators with `Symbol.Iterator`

You can extend an Error class in javascript.

There are maps in javascript

BigInt in javascript

Static method to Number. `IsSafeInteger` `Number.MAX_SAFE_INTEGER` `Number.parseInt` `Number.parseFloat` `Number.isNAN` `Number.EPSILON` `Number.isInteger` `Number.isFinite` 

[Implementing tag functions](https://exploringjs.com/es6/ch_template-literals.html#sec_implementing-tag-functions)

[JavaScript Symbols](https://exploringjs.com/es6/ch_symbols.html)

##### why const prevents the weird closure bug

const creates one binding per iteration, var creates one binding per loop. That is why const solves the closure bug.
[https://exploringjs.com/es6/ch_variables.html#sec_rationale-per-iteration-bindings](const in loops)

[https://exploringjs.com/es6/ch_variables.html#sec_rationale-per-iteration-bindings](Parameter default values don't see the scope of the body)

Cool websites about Javascript

[javascript.info](https://javascript.info)
[v8.dev](https://v8.dev)
[Crossing realms with symbols](https://exploringjs.com/es6/ch_symbols.html#sec_symbols-crossing-realms)
Why you should read Tech books!
Tags: books, css, html, javascript
Published: 2020-03-17 20:37:04

Believe it or not, you should read Tech books! 
One of the most important overlooked technology sources are books, sure online courses, YouTube tutorials and online bootcamps are important and an essential step, but by time you will discover that only books can save your day.
I myself am very academic, maybe that is why I am writing this post, but believe me even if you don't like reading you will find yourself in deep need of a book , journal or a magazine storing pieces of precious information that you can refer to whenever needed.

A month ago, I was watching a YouTube video [ Real Tough Candy ] and she was talking that book in the cover picture , the JavaScript and jQuery book , and she gave pretty positive review about that book. 

As I live in Poland, the access to English written tech books is impossible; so I ordered these two books through Amazon and I did not know that the publisher is Wiley [ www.wiley.com] which is the same publisher of all of my university four years accounting and finance books! 

Then I opened both [ HTML,CSS & JavaScript,jQuery ]  and glanced over them and I was amazed by the quality and the elegance of how information is very well organized in a neat clean way that actually opens your appetite to devour the whole thing!.
And how beautiful the book is visually structured which helps tremendously way in fixing the information inside your brain cells!

My advice to you besides online courses, reading other people code, practicing with online instructors is this : The More You Read , The Better You Are Informed! So, please read a book or two in whatever language you're learning or already working with; I am sure you will learn something that others don't know about. Books always hold secrets that the majority of instructors and pros didn't know that it exists , and this is a big power that you can hold which can increase your self confidence and allows you to achieve excellence in bigger leaps.
Conceptual Integrity
Tags: programmersstone, reciprocality
Published: 2020-03-17 20:36:29

---
title: Conceptual Integrity
published: true
description: Programmer's Stone, Programmer at Work
tags: #programmersstone, #reciprocality
---

In The Mythical Man Month, Fred Brooks emphasizes the importance of conceptual integrity in design. Our deep view of programming suggests some practical ways to achieve conceptual integrity.

First, we know the importance of mental maps. If every member of the team shares a mutually-agreed mental map of the system being constructed, then it is possible for everyone's' contribution to be in the spirit of the overall design. If they don't, then it isn't, because a style guide detailed enough to allow someone to get everything right without knowing what they are doing would be much harder for the architect to write than the system itself would be.

Secondly, we have a picture of the programmer optimizing a series of design choices to produce a minimal solution and control complexity. So we need to look at the kinds of constructs the programmers cook with, and ensure that they are shared. Such a project style guide indicates a coherent collection of variable naming conventions, error-handling strategies, example idioms for using the subsystems' APIs, even the comment style. One might say that by controlling the shape of the bricks, the architect can constrain the shape of the house while leaving flexibility in the hands of the designer. The structure of the code then ensures that the code between the canonical examples is predictable and elegant. So code examples in style guides control structure, and structure controls code. Here we see another echo of the Knight's Fork - if we use the right structure, we can bring necessary and sufficient syntax into play and write minimal text. Conversely, the more twisted the stuff gets, the more of it you get, to be twisted up.

A final benefit of conceptual integrity that is very valuable to the professional programmer is very practical. Imagine you are on a roll. You've seen the way to divide up your functionality, you've got a really elegant way of catching all the odd ways the OS can signal failure, you're halfway through coding up all the cases, and you need a new variable name. Your head locks up, overloaded by a triviality! The exponential benefits of getting focused and staying that way are as great as the exponential benefits of minimizing the code size, so every silly distraction you can get rid of is worth it. On sites where everyone stops work every ten minutes to argue about administration, the benefits of real focus can never emerge anyway, but where external conditions have been sorted out, having a style guide to let you pretty much derive this kind of stuff on the fly can dramatically improve effective productivity.
Selenium Can Make Hi-DPI, Retina Style Screenshots (Firefox and Chrome)
Tags: selenium, firefox, chrome, retina
Published: 2020-03-17 22:30:33

---
title: Selenium Can Make Hi-DPI, Retina Style Screenshots (Firefox and Chrome)
published: true
date: 2020-03-17 20:36:15 UTC
tags: selenium,firefox,chrome,retina
canonical_url: https://www.simplecto.com/selenium-can-make-hi-dpi-retina-style-screenshots/
---

With just a single line of code you can modify your Selenium browser to operate in (x.x) density mode. This means you can take higher-DPI screenshots as you might on retina screens.

* * *

### Firefox Code Sample
<!--kg-card-begin: markdown-->
```
my_dpi = 2.0

profile = webdriver.FirefoxProfile()
profile.set_preference("layout.css.devPixelsPerPx", str(my_dpi))

```
<!--kg-card-end: markdown-->

Yes kids, it is this simple. All you need to do is set a preference on your profile.

**NOTE:** The gotcha here is that you have to cast the float to a string using `str()`. That is non-obvious and will save you a ton of time in debugging. Otherwise it is silently ignored.

* * *

### Chrome Code Sample

Chrome is a little different. There is not a preferences profile that you tweak with various settings. In this case you simple pass in a command line option when launching the browser.

<!--kg-card-begin: markdown-->
```
my_dpi = 2.0
options = ChromeOptions()
    # ... other options..
    options.add_argument(f"--force-device-scale-factor={my_dpi}")

```
<!--kg-card-end: markdown-->

### Full Code Sample

This is an export from my Jupyter Notebook. Note, you will need to `pip install selenium` as well as have the `firefox-geckodriver` installed with brew or whatever linux flavor.

<!--kg-card-begin: markdown-->
```
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.common.exceptions import NoSuchElementException, WebDriverException
from time import sleep

my_dpi = 2.0

profile = webdriver.FirefoxProfile()
profile.set_preference("layout.css.devPixelsPerPx", str(my_dpi))

options = Options()
options.headless = True
driver = webdriver.Firefox(options=options, firefox_profile=profile)
driver.set_page_load_timeout(60)
driver.set_window_size(1440, 800)

driver.get('https://www.simplecto.com')

driver.save_screenshot("simplecto-dpi2.0.png")
driver.quit()

```
<!--kg-card-end: markdown-->

**NOTE** : This was not tested on Windows. Sorry not sorry.

You can try DPI at `1.0` and `2.0` to see the sizable difference in disk space and memory required. This becomes a little more work for a CPU when running full-size page screenshots.
Detailed Design Document
Tags: programmersstone, reciprocality
Published: 2020-03-17 20:25:52

---
title: Detailed Design Document
published: true
description: Programmer's Stone, Programmer at Work
tags: #programmersstone, #reciprocality
---

The DDD is a message in a bottle. It tells the reader about how the original author planned the implementation so that the code is intelligible. The detail of exposition must take over where the ADD leaves off, and take the reader to the point where the code can stand for itself. Sometimes, this explanation can be assisted by pseudo-code, but this need not be the case. The DDD should be regarded as amendable. During implementation, design details like the organization of code into modules will emerge. If these details are not captured for our colleagues in the DDD, where will they be captured? This simple omission causes far too much unnecessary trouble, as engineers pick up parts of systems that they can see is well documented, if only they knew where to start! Your final DDD should tell your successor whatever they need to know in order to pick up the system and change it.
Test Plan

A test is the most context-sensitive of the document types, but the following observations are useful guides within the imperatives of the situation. The test strategy aims to stress the system. It will not get much leverage out of doing this entirely at random, so the issue is to find one or more models of the system, that can give us an indication of likely typical and stress conditions. A useful structure is, therefore, to describe the model, derive the stress conditions, and then list them.
Architectural Design Document
Tags: programmersstone, reciprocality
Published: 2020-03-17 20:22:56

---
title: Architectural Design Document
published: true
description: Programmer's Stone, Programmer at Work
tags: #programmersstone, #reciprocality
---

It is in doing the work captured in the ADD that the hard work of a design has to be done. It is also in the ADD that the greatest opportunity to fudge it exists. While we deliberately omit design detail from the ADD, sometimes so as to retain portability, sometimes just to avoid clouding the big picture, we must still be convinced that our design is in fact implementable. The engineer should know of at least one acceptable way to implement each feature before calling for it and should have thought about the conceptual integrity of the collection of all the code required to implement the features.

The proposition that architectural design should not consider detailed design, we suggest is misguided. If we cannot consider implementation, we can't be very good engineers, because any fool can design the unbuildable. It is by considering the implementation that we discover the limitations of our designs and learn the difference between good and bad. We are able to see alternatives, compare them and select the best. If we cannot consider implementable reality, one design is as good as another, and this critical stage of cognition becomes a typing exercise to see how fast one can `write the document', and never mind what is written!

The ADD is a didactic document. It teaches the reader how to see the problem and solution in the way that the author sees them.
How to Write Documents
Tags: programmersstone, reciprocality
Published: 2020-03-17 20:14:03

---
title: How to Write Documents
published: true
description: Programmer's Stone, Programmer at Work
tags: #programmersstone, #reciprocality
---



In many software engineers' view, much of their lives consist of writing documents. From the perspective of this course, we would prefer to say that their lives consist of performing work to gain understanding, which will be delivered to their colleagues according to the protocol specified in their process. Hence we are aware that the work is always understanding, and the process tells what understanding we need to convey to them. It, therefore, indicates the suitable language for each document. These considerations can inform a description of the actual job to be done with each of the documents; User Requirement, Software Requirement, Architectural Design, Detailed Design, and Test Specification, that an engineer produces.

There are two more general points that should be made. Firstly, the job does not consist of producing reams of unintelligible gobbledegook that no-one will ever read, that looks like `engineering documents'. The first person to quote a reference, full of slashes and decimal points, in the main text when it should have been in an appendix if anywhere, wasn't just being rude to his or her readers, they were setting a trend that has devalued the whole of our art. Use simple, normal language (including specialist terminology where necessary, but not made up for the sake of it), to tell the reader what they need to know.

The second point regards the format. In any stage of the software engineering process, people use understanding to find and propose pattern. If they knew what they were going to find, they wouldn't have the job, because somebody would be setting up a COTS product instead. So we don't necessarily know what the worker will need to present, so how can we tell them how to present it? Standard formats in processes should not be taken as exclusive. All decent ISO 9001 processes have provisions to tailor the required sections of a document where appropriate. Make proper use of these, and if the structure of the document emerges during the writing, you can still put an insertion in the Project Management Plan to describe your chosen format. This is what ISO 9001 is all about.
Virtual (Sanal) Metot
Tags: c, sanalmetod, sanalmetot, virtual
Published: 2020-12-26 13:44:42

---
title: Virtual (Sanal) Metot
published: true
date: 2020-03-17 20:13:00 UTC
tags: C,sanalmetod,sanalmetot,virtual
canonical_url: 
---

Sanal metot; temel sınıfı içerisinde yazılan metodu, miras alan sınıflarda override edilerek (ezilerek), yeniden yazılmaya müsait yapılarda ki metotlara verilen genel isimdir.

Sanal metotlar; sıradan metotların önüne “ **virtual** ” anahtarı eklenerek oluşturulurlar. Kullanım amacı, oluşturulan metodun değiştirebilirliğini, ihtiyaca göre yeniden yazılabileceğini belirtir.

Şöyle gerçek dışı ama basit bir örnek ile anlatmaya çalışacak olursam, **Islem** adında bir sınıfımız olsun ve bu sınıfımız içerisinde de **Topla(int** a **, int** b**)** adında bir metodumuz olsun. Bu Topla metodumuz verilen iki değeri toplayan bir metot. Islem sınıfımızı miras alarak oluşturduğumuz **Farklı : Islem** sınıfında Topla metodunu ezip toplamı 100 ile çarpmak istiyoruz. (psikopatız var mı ?) Örnek her ne kadar saçma olsa da anlatımı çok sade tutmaya çalıştım. Aşağıda bu durumu resmetmeye çalıştım.

``` csharp

    class Islem
    {
        public virtual int Topla(int a, int b)
        {
            return a + b;
        }
    }

    class Farkli : Islem
    { 
//Bir class’ın virtual metotolarını görmek ve ezmek için, ezilmek istenilen alanda override yazmak yeterlidir.
        public override int Topla(int a, int b)
        {
            return (a + b) * 100;
        }
    }

```

Aşağıda ki şekilde de kullanıp sonucu görmek mümkündür.

``` csharp

namespace VirtualMethods
{
    class Program
    {
        static void Main(string[] args)
        {
            Islem islem = new Islem();
            Console.WriteLine(islem.Topla(2, 5).ToString()); // 7

            Farkli farkliIslem = new Farkli();
            Console.WriteLine(farkliIslem.Topla(2,5).ToString()); // 700

            Console.ReadKey();
        }
    }
}

```