teleren/devto huggingface dataset:
Instance property vs parameter in Swift 
Tags: swift, parameter, property, instance
Published: 2017-09-13 12:17:21

---
title: Instance property vs parameter in Swift 
published: true
description: 
tags: swift, parameter, property, instance
---

Original post https://github.com/onmyway133/blog/issues/72


The other day I was refactor my code. I have

```swift
extension MainController: TabBarViewDelegate {

  func buttonDidPress index: Int) {
    let initialIndex = tabBarView.selectedIndex
    let wholeAppContentView = updateWholeAppContentView()
    view.addSubview(wholeAppContentView)
  }
}
```

The delegate method does not look right, as it's hard to tell between required delegate method, or just instance method. Also it lacks a subject. I like this post [API Design](https://mattgemmell.com/api-design/), you can read section `Rule 19: Always say who’s talking`

> This is a simple rule, and an equally simple mistake to make. In your delegate methods, always pass the sender as a parameter. Always. Even for singletons. Even for things you cannot conceive would ever be used more than once simultaneously. No exceptions.

So I refactor the delegate, and conform to it.

```swift
extension MainController: TabBarViewDelegate {

  func tabBarView(_ view: TabBarView, buttonDidPress index: Int) {
    let initialIndex = tabBarView.selectedIndex
    let wholeAppContentView = updateWholeAppContentView()
    view.addSubview(wholeAppContentView) // This is the culprit âš ï¸
  }
}
```

Even with just 1 line change in `MainController.swift`, the whole UI breaks, as all the views were added to the tab bar. Strange ðŸ˜¡ .

It didn't take long until I remember that `parameter` takes precedence over `instance property` if they have same name. So in this case, the compiler, without warning, assume you're dealing with `view` from `TabBarView` âš ï¸ 

That's why you often use `self` to disambiguate. 

```swift
struct User: Codable, Equatable {
  let firstName: String
  let lastName: String

  init(firstName: String, lastName: String) {
    self.firstName = firstName
    self.lastName = lastName
  }
}
```

Back to our code. The workaround is to specify `self` to specify `view` of `MainController`

```swift
self.view.addSubview(wholeAppContentView)
```

Well, you may say, who should add view again in case of tab bar changes ðŸ˜¬  This is a bad example, but the lesson is  learned ðŸ˜‡
Pushing to gist 
Tags: git, gists
Published: 2017-09-13 11:55:32

---
title: Pushing to gist 
published: true
description: 
tags: git, gists
---

### Creating a new gist

- Go to https://gist.github.com/ and create a new gist
- Note that you need to include `filename` + `extension` to enable automatic language markup
- Click `Add file` to add more files

### Cloning the gist

- If you've enabled `2 factor authentication`, you need to use `personal acccess token` with `https`, or use `ssh`. 

> If you have enabled two-factor authentication, or if you are accessing an organization that uses SAML single sign-on, you must provide a personal access token instead of entering your password for HTTPS Git.
- You should enable `2 factor authentication`. Read more https://help.github.com/articles/https-cloning-errors/#provide-access-token-if-2fa-enabled
- For example with my gist https://gist.github.com/onmyway133/c486939f82fc4d3a8ed4be21538fdd32 the `ssh url` is `git@gist.github.com:c486939f82fc4d3a8ed4be21538fdd32.git`
- Run git commands as normal

```
git remote add origin git@gist.github.com:c486939f82fc4d3a8ed4be21538fdd32.git
git clone
```

- You have branch `master` by default

```
git push origin master
```

### Ignoring directories

> remote: Gist does not support directories.

- In my cases I'm using node, so I need to ignore `node_modules` directory
- Also need to untrack if necessary 

```
git rm --cached -r .
git add .
```

---

❤️ Support my app ❤️ 

- [Push Hero - pure Swift native macOS application to test push notifications](https://www.producthunt.com/posts/push-hero-2)
- [Quick Access - Organise files in the Mac menu bar](https://www.producthunt.com/posts/quick-access)
- [Frame recorder - Recorder gif and video with frame](https://www.producthunt.com/posts/frame-recorder)
- [Other apps](https://onmyway133.github.io/projects/)

❤️❤️😇😍🤘❤️❤️
Introducing the SMArt building language
Tags: smart, showdev
Published: 2017-09-13 01:16:54

---
title: Introducing the SMArt building language
published: true
description: building language
tags: smart, showdev
---

I found dev.to from a link, this is my first post, and I'd like to share the [SMArt](https://github.com/duzy/smart) building language to friends here. Please review this tool. Looking forward positive comments. :)
How to handle validations involving several fields?
Tags: react, javascript, form, forms
Published: 2018-01-12 14:42:24

---
title: "How to handle validations involving several fields?"
published: true
tags: React, JavaScript, form, forms
canonical_url: https://goshakkk.name/validations-several-fields/
cover_image: https://goshakkk.name/assets/images/validate-several-cover.png
---

It’s often enough to validate each field in isolation:

- email should contain a `@`;
- password should be more than four characters.

But every once in a while, you need to validate several fields together:

- password confirmation should match password;
- phone number’s length depends on the country code from a separate input.

It’s hard or impossible implement that with [field-level validations](/y-no-field-level-validations/) without unnecessarily complicating the code. However, with a simple validation architecture from the [other articles](/instant-form-fields-validation-react/), it’s pretty trivial.

A function that validates the entire form is simple:

```
function validate(email, password) {
  // true means invalid, so our conditions got reversed
  return {
    email: email.length === 0,
    password: password.length === 0,
  };
}
```

I mean, what could be simpler? And yet, it’s very powerful. Validating several fields together is easily achievable:

```
function validate(email, password, passwordConfirm) {
  // true means invalid, so our conditions got reversed
  return {
    email: email.length === 0,
    password: password.length === 0,
    passwordConfirm: password !== passwordConfirm,
  };
}
```

Try entering different passwords now:

[JS Bin on jsbin.com](https://jsbin.com/dunukov/2/embed?js,output)<script src="https://static.jsbin.com/js/embed.min.js?4.0.4"></script>

Once again, controlled inputs saved our day 🐶


_This post was originally published on [goshakkk.name](https://goshakkk.name/validations-several-fields/)_

---

[I blog about forms](http://goshakkk.name/on-forms-react/) in React specifically, and other React-related things.
If you like what you see here, [subscribe here](http://goshakkk.name/subscribe/) to make sure you don't miss out on my next post.
What is the most confusing thing to you in Python?
Tags: discuss, python, beginners
Published: 2017-09-12 21:12:26

---
title: What is the most confusing thing to you in Python?
published: true
description: 
tags: discuss,python,beginner
---

Just some traps and pitfalls that took me a while to get used to in Python. 

### List methods vs. built-in methods
```Python
# sort(), sorted(), reverse(), reversed()
# sort() modifies the existing list and is a function of the list object
# sorted() returns a new list and is a built-in function

a = [5,2,8,1,9,3]
sorted(a) # ok -> [1, 2, 3, 5, 8, 9]
a.sort()  # ok -> [1, 2, 3, 5, 8, 9]
a.sorted() # ERROR

# however, min() and max() are only built-in functions
a.min() # ERROR
min(a) # ok -> 1

# unless you work with numpy, where min() and max() do exist :S
import numpy as np
n = np.array([5,2,4,9,1,7])
n.min() # ok -> 1
```

### string.join()
```Python
# I have to call .join() on a string to concatenate a list = confusing.

# concatenating a list of strings
", ".join(["apple", "banana", "cherry"]) # 'apple, banana, cherry'

# even uglier, when list is not a string
", ".join([str(s) for s in [1,2,3,4]])   # '1, 2, 3, 4'
```

### List of lists
```Python 

# The wrong way
a = [[]] * 5
# [[], [], [], [], []]
a[0].append(1)
# [[1], [1], [1], [1], [1]]

# The right way
a = [[] for _ in range(5)]

```

### 'is' and '==' on ints
```Python
# Internally some int objects are cached. When you compare 2 ints, you should use ==. 
# However, using 'is' can also work in some cases.

x = 2000
y = 2000
x is y # False -> good, because this should not be allowed anyways.

x = 5
y = 5
x is y # True -> But this works....
# See also
# https://stackoverflow.com/questions/306313/is-operator-behaves-unexpectedly-with-integers
```

Did you find any interesting or funny things in Python, that confused you the first time you saw them? Share them in the comments below.
Cross Platform Development Without JavaScript
Tags: android, ios, beginners, programming
Published: 2017-09-12 20:57:43

---
title: Cross Platform Development Without JavaScript
published: true
description: Cross Platform Development without having to be a guru in JavaScript
tags: #Android #IOS #Beginners #programming  
---


We all know there are cross platform development masters who use languages like JavaScript and CSS to create beautiful mobile apps. If you are like me who has little experience in those areas and does not want to start a full JavaScript course what would you do? 

Do not get me wrong -- JavaScript is wonderful and I do have at least little experience with it. The truth is it can really scare someone who is just starting out, there are so many frameworks we have React, Angular, jQuery, Vue, Mercury, Deku, Riot.js 😕...... obama.js, just kidding 😊, but you get what I am saying.

For someone who might want something different let me introduce Flutter to you. Flutter is a new mobile app SDK to help developers and designers build modern mobile apps for iOS and Android. If you don't have any mobile development experience, Flutter is an easy and fast way to build beautiful mobile apps. If you are an experienced iOS or Android developer, you can use Flutter for your views and leverage much of your existing Java/ObjC/Swift investment.


Also note that with Flutter you can access native features and SDKs on iOS and Android. So you might be asking what programming language Flutter uses, well it uses Dart.

Dart is an application programming language that’s easy to learn, easy to scale, and deployable everywhere. Believe me Dart is really nice, in order for you to have a great experience the IDE I would advice you to use is Intelij IDEA which works great with Dart. 

Below is are sample codes using Dart:

```Dart
// Define a function.
printNumber(num aNumber) {
  print('The number is $aNumber.'); // Print to console.
}

// This is where the app starts executing.
main() {
  var number = 42; // Declare and initialize a variable.
  printNumber(number); // Call a function.
}
```


```Dart
class Point {
  num x;
  num y;

  // Syntactic sugar for setting x and y
  // before the constructor body runs.
  Point(this.x, this.y);
}
```


I think the code is self explanatory, it's very similar to Java and also other languages.

You can check the [Flutter](https://flutter.io/) website to check it out, also the installation is straight forward, it will be wise to also checkout [Dart](https://www.dartlang.org/) which is what you will be using and there are [codelabs](https://codelabs.developers.google.com/codelabs/from-java-to-dart/#0) for you to try it out, if you have any issue you can always contact me.
Azure Functions
Tags: softwaredevelopment, azure, development, devops
Published: 2020-02-07 05:59:17

---
title: Azure Functions
published: true
date: 2017-09-12 19:33:49 UTC
tags: SoftwareDevelopment,Azure,development,devops
canonical_url: https://www.funkysi1701.com/posts/azure-functions-301k
---

I recently blogged about using [Azure Web Jobs](https://dev.to/funkysi1701/using-azure-webjobs-to-automate-stuff-gio-temp-slug-977885), Azure Function is another way of doing the same thing, lets look at how they work.

(Sorry its been a while since I blogged but I suspect an erratic schedule will continue for the next few months.)

To create an Azure Function go to the Azure portal and click add new and search for “Function App”

Give your app a name and select the usual resource group and location settings.

Now when you open Function Apps you should see your new app.

I want my Function App to run on a schedule so I clicked the + next to functions and selected TimerTrigger. I am a c# programmer so I selected this option as well.

Give your function a name and specify using the usual cron notation how often it should run. I want mine to run at 9.30pm each night so use 0 30 21 \* \* \*

Now comes the code bit. By default you get a window with the following code in it

<style>.gist table { margin-bottom: 0; }</style>

It is entirely up to you what you get your function to do. In my case I just wanted to call a URL on a schedule so I created some code that used httpclient.

<style>.gist table { margin-bottom: 0; }</style>

Once you have created your app and it has run you can use the monitor section to view success and failures.

There is loads more you can do with Azure Function but this is a good place to start.

The post [Azure Functions](https://www.funkysi1701.com/2017/09/12/azure-functions/) appeared first on [Funky Si's Tech Talk](https://www.funkysi1701.com).
Creating a Docker image and upload it to Docker Hub
Tags: docker
Published: 2017-09-12 15:58:18

---
title: Creating a Docker image and upload it to Docker Hub
description: How to create your own images for applications, tasks, or commands you always wanted to have at hand.
tags: docker
published: true
---

## Creating the Docker image

I'm going to use a Docker image to be able to use multiple github accounts from the same machine without so much trouble. To keep the image small I will use Alpine as a base image and only install the basics: git, vim, openssh-client.

In order to build the image we need to create a new file called Dockerfile and write the following:

```
FROM alpine:latest

LABEL maintainer="@ech0Server"

RUN apk update
RUN apk add git vim openssh-client
```

Then, to build the docker image run:

```
docker build -t username/imagename:latest .
```

This command not only will build the image but it will tag it with the -t option, for my case I did:

```
docker build -t ech0server/multigitaccount:latest .
```


I will assume that you already have a Docker Hub account or create a docker hub account, then:

``` sh
$ export DOCKER_ID_USER="username"
$ docker login #it will prompt you for your username and password
```

If you followed the previous instructions your image should be already tagged, if not then you can tag your image by:

```
docker tag my_image $DOCKER_ID_USER/my_image
```

Finally we can push the Docker image to the Hub:

```
docker push ech0server/multigitaccount:latest
```

After that is completed you can go to: [https://hub.docker.com/u/username](https://hub.docker.com/u/username) and see that the image was successfully uploaded.

My image can be found here: [https://hub.docker.com/r/ech0server/multigitaccount/](https://hub.docker.com/r/ech0server/multigitaccount/)

And you can pull it by doing:
```
docker pull ech0server/multigitaccount
```
Created A bluewhale game on a learning Weekend
Tags: showdev
Published: 2017-09-12 09:39:47

---
title: Created A bluewhale game on a learning Weekend
published: true
tags: showdev
cover_image: https://thepracticaldev.s3.amazonaws.com/i/7n1xv9rnrv82l22c61ew.png
---

Hey Guys as I have started learning Game development in HTML5 on weekends so I've learn to make a simple game which is very basic till now. But you can play the game at:

https://shahroznawaz.com/bluewhale/

The Phaser frameworks uses javascript to play with animations and transitions and give some builtin components which you can use to develop games.

The game is bit newbie but I would love your advice and contributions on it :)
Basic UNIX commands 
Tags: commandline, unix, terminal, beginners
Published: 2017-09-12 08:26:43

---
title: Basic UNIX commands 
published: true
description: I started learning commands lines
tags: commandline, unix, terminal, beginners
cover_image: https://thepracticaldev.s3.amazonaws.com/i/bp96twlhnwdx6q3q9iub.jpg
---

Lately, I started learning commands lines. I mean, I used `npm install` or `gulp`, but no more.

So I started using commands lines and I have to say that I like it. A lot.

I wanted to share with you what I learned. 

## `cd`

The `cd` command is used to change the current directory. 

> _cd_ stand for __change directory__

```
cd path/of/directory
```

> To move up by one directory you can hit `cd ..` [Source](https://stackoverflow.com/a/3267526)

## `ls`

The `ls` command list all files of a type other than directory, found in the current directory.

> _ls_ stand for __list segments__

```
ls
```
 
## `man`

The `man` command display the online manual pages. We can specify a section as parameter. The section is normally the command, function or file name.

> _man_ stand for __manual__.

```
man name_of_command
```

> To exit the __manual__ you can hit `q`, `:q`, `Q`, `:Q` or `ZZ`.

## `mkdir`

The `mkdir` command is used to create a new directory. The directory would be create in the current directory.

> _mkdir_ stand for __make directories__.

```
mkdir name_of_directory
```
 
## `rmdir`

The `rmdir` command is used to remove an empty directory.

> _rmdir_ stand for __remove directories__.

```
rmdir name_of_directory
```

We can pass an `-p` option. In this case each directory argument will be treated as a single path and will be removed if they are empty.

```
rmdir -p name/of/directory
```

## `mv`

The `mv` command is used to move a file into a given directory.

> _mv_ stand for __move__.

```
mv name_of_file name/of/directory/destination/
```

## `open`

The `open` command is used to open a file or a directory

```
open name_of_file
```

I know, it's very basic, but you have to start somewhere. ðŸ˜… 

I created a [Gist](https://gist.github.com/19h47/5b9bf949d999a47426df6443dbfb2bad) where I add what I learn.

And you, what are your favorite commands?
Localizing Go to JavaScript
Tags: go, javascript, webdev, showdev
Published: 2017-09-12 01:36:24

---
title: Localizing Go to JavaScript
published: true
description: A Go package for localizing Go data structures to front-end JavaScript.
cover_image: http://foresthoffman.com/wp-content/uploads/2017/09/golang-banner_2.jpg
tags: go, javascript, webdev, showdev
---

While working a Go backend for a side-project, I implemented a custom templating system among other things. For my project, I needed to be able to pass nonce values down to my JavaScript. I realized that keeping the data in the front-end up-to-date with the backend would require a lot of leg work. In order to save time and effort, I built the [`localize`](https://github.com/foresthoffman/localize) package.

This package takes a pre-defined Go data structure and recursively translates it to JavaScript primitives. The JavaScript that is spit back out can be used in just about any fashion, but it is designed to work best with the `html/template` package. Since the `html/template` package provides support for calling functions assigned to data passed to the `template.Template.Execute()` function, templates can fire off the localization process themselves. Once you have a template setup to utilize the localize package, it's a fire and forget situation. The best kind, in my opinion.

Here's a simple example of the syntax:

```Go
import(
    "github.com/foresthoffman/localize"
)

func main() {
    // Generates a new localization map with the provided data.
    dataMap, err := localize.NewMap(
        // This will tell the localizer to assign the data to
        // the "_localData" global JavaScript variable.
        "_localData",
        localize.Data{
            "motd": "Hello world, welcome to a new day!",

            // "nonce" will hold an object with an element with
            // the key, "login", and the value,
            // "LaKJIIjIOUhjbKHdBJHGkhg"
            "nonce": map[string]string{
                "login": "LaKJIIjIOUhjbKHdBJHGkhg",
            },
        },
    )

    // ...proper error handling, data manipulation, etc.
}
```

EDIT (08/11/19): [`test/template.go`](https://github.com/foresthoffman/localize/blob/master/test/template.go) provides a very handy example of using `localize` with an actual HTTP server.

That's it! :)
Explain Rust like I'm five
Tags: rust, explainlikeimfive, discuss
Published: 2017-09-12 08:25:42

---
title: "Explain Rust like I'm five"
published: true
description: I see the term RUST here and there and I nod internally to myself that I know it's a development language or something.  But I really don't know anything about RUST.
tags: RUST, explainlikeimfive, discuss
---
I see the term RUST here and there and I nod internally to myself that I know it's a development language or something.  But I really don't know anything about RUST.

* What are RUST's strong points?  
* Why and when would I want to use it?  
* And (importantly) will i earn lots of money if I invest my time with it?
XojoTalk 033 – Talking from Tomorrow
Tags: podcast, windows, xojo, xero
Published: 2017-10-31 15:47:06

---
title: "XojoTalk 033 – Talking from Tomorrow"
published: true
tags: podcast,Windows,Xojo,Xero
canonical_url: https://blog.xojo.com/2017/09/12/xojotalk-033-talking-from-tomorrow/
---

Paul talks with Wayne Golding of Axis Direct about how his company uses Xojo, Xojo 2017 Release 2, New Zealand and more.

Download [mp3](http://cdn.xojo.com//Podcasts/XojoTalk-033.mp3).

[Subscribe to XojoTalk](http://feeds.feedburner.com/xojotalk)

### Show Notes

- [Axis Direct](http://www.axisdirect.nz)
- [Xero online accounting](https://www.xero.com)
- [Wayne’s posts on Medium](https://medium.com/@waynegolding)
- [Axis Direct Xojo videos on YouTube](https://www.youtube.com/channel/UCE7XhJsloXAlIOpGe1mPqWQ)
- [Windows 10 Fall Creators Update](https://blogs.windows.com/windowsexperience/2017/09/01/create-and-play-this-holiday-with-the-windows-10-fall-creators-update-coming-oct-17/)
- [Xojo 2017r2 Override Class Default Values feature](http://developer.xojo.com/override-system-class-default-values)
- [Raspbian Stretch](https://www.raspberrypi.org/blog/raspbian-stretch/)
- [Great Lake Taupo, New Zealand](http://www.greatlaketaupo.com)
- [XDC 2018](https://xojo.com/xdc/)
 ![](http://feeds.feedburner.com/~r/xojotalk/~4/POVPeFlRT8s)
A Fun Little Bug
Tags: shell, bugs
Published: 2017-09-12 03:20:15

---
title: A Fun Little Bug
published: true
description: Or, what we can infer from a program given a peculiar hiccup
tags: shell, bugs
---

Today I ran into a fun little bug while debugging the shell I've been working on, while also using my VT420.

My terminal has been weird for a while, and will sometimes fail to backspace on things such as password inputs. In this case, with my shell, it would print `^H` instead of actually deleting a character.

So, what happens if you run `ls -l foo ^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H`?

You get the wonderful `: No such file or directory`. But it should be listing the contents of `foo`. What's going on?

From this, we can infer some code in `ls`.

```c
printf("%s: cannot access %s: No such file or directory\n", command, filename);
```

As we can see, because the `filename` string has backspace characters in it, C will print it out, _including_ the backspace characters, thus deleting the printing about the command being run and the filename.

Thankfully, this wasn't an issue with my shell, but rather my terminal. Changing firmware settings for the backspace key fixed things, including backspacing on password input.