teleren/devto huggingface dataset:
Digit grouping in Swift
Tags: swift, digit, group
Published: 2017-08-11 11:51:31

---
title: Digit grouping in Swift
published: true
description: 
tags: swift, digit, group
---

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

When working on [Scale](https://github.com/onmyway133/Scale) I think it's good to have a way to group the digit so that it is easier to reason

Luckily, Swift already supports this. See [The Swift Programming Language - Numeric Literals](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html#//apple_ref/doc/uid/TP40014097-CH5-ID309)

> Numeric literals can contain extra formatting to make them easier to read. Both integers and floats can be padded with extra zeros and can contain underscores to help with readability. Neither type of formatting affects the underlying value of the literal

```swift
let paddedDouble = 000123.456
let oneMillion = 1_000_000
let justOverOneMillion = 1_000_000.000_000_1
```

Talking about grouping digits after the decimal point, it is interesting too [Convention of digit grouping after decimal point](http://math.stackexchange.com/questions/182775/convention-of-digit-grouping-after-decimal-point)

So now we have

```swift
public enum MetricUnit: Double {
    case nano = 0.000_000_001
    case micro = 0.000_001
    case milli = 0.001
    case centi = 0.01
    case deci = 0.1
    case base = 1
    case deka = 10
    case hecto = 100
    case kilo = 1_000
    case mega = 1_000_000
    case giga = 1_000_000_000
    case tera = 1_000_000_000_000
    case peta = 1_000_000_000_000_000

    static var defaultScale: Double {
        return MetricUnit.base.rawValue
    }
}
```
Initializing Enums With Optionals in Swift
Tags: swift, enum, optional
Published: 2017-08-11 11:49:57

---
title: Initializing Enums With Optionals in Swift
published: true
description: 
tags: swift, enum, optional
---

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


Today someone showed me https://medium.com/@_Easy_E/initializing-enums-with-optionals-in-swift-bf246ce20e4c which tries to init enum with optional value.

```swift
enum Planet: String {
  case mercury
  case venus
  case earth
  case mars
  case jupiter
  case saturn
  case uranus
  case neptune
}

extension RawRepresentable {
  init?(optionalValue: RawValue?) {
    guard let value = optionalValue else { return nil }
    self.init(rawValue: value)
  }
}

let name: String? = "venus"
let planet = Planet(optionalValue: name)
```

One interesting fact about optional, is that it is a monad, so it has `map` and `flatMap`. Since `enum` `init(rawValue:)` returns an optional, we need to use `flatMap`. It looks like this

```swift
let name: String? = "venus"
let planet = name.flatMap({ Planet(rawValue: $0) })
```

ðŸŽ‰
Test for viewDidLoad
Tags: swift, test, unit, controller
Published: 2017-08-11 11:48:41

---
title: Test for viewDidLoad
published: true
description: 
tags: swift, test, unit, controller
---

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

Suppose we have the following view controller

```swift
class ListController: UIViewController {
  override func viewDidLoad() {
    super.viewDidLoad()
    view.backgroundColor = .white
  }
}
```

### Get to know `viewDidLoad`

We know that `viewDidLoad` is called when view is created the first time. So in the the Unit Test, if you use `viewDidLoad` to trigger, you will fall into a trap

```swift
func testSetup() {
  let controller = ListController()
  controller.viewDidLoad()
}
```

### Why is `viewDidLoad` called twice?

- It is called once in your test
- And in your `viewDidLoad` method, you access `view`, which is created the first time, hence it will trigger `viewDidLoad` again

### The correct way

The best practice is not to trigger events yourself, but do something to make event happen. In Unit Test, we just access `view` to trigger `viewDidLoad`

```swift
func testSetup() {
  let controller = ListController()
  let _ = controller.view
}
```
Please, Give Public Speaking a Try
Tags: career, publicspeaking, leadership, communication
Published: 2017-08-11 11:45:53

---
title: Please, Give Public Speaking a Try
published: true
description: 
tags: Career, Public Speaking, Leadership, Communication
---

![The fear of public speaking](https://thepracticaldev.s3.amazonaws.com/i/mls6xey3sr35wim1fkaq.PNG)

When I talk to people about [public speaking](https://www.youtube.com/watch?v=aPSvHT9USO8), I tell them of the opportunities it opens up to travel to fun places, and meet awesome people. I have had some amazing adventures in the last several years, all because I got up the courage to get up and speak to a bunch of geeks like myself.

I've done things like:

* Soaked in an outdoor hot tub with snow falling on my face in Sandusky, Ohio
* Sunned with my toes in the sand at Atlantic Beach, Florida
* Scoped the beautiful [Biltmore Estate](http://www.biltmore.com/) in Asheville, North Carolina
* Studied Norwegian history at the [Norsk Folkemuseum](http://norskfolkemuseum.no/en/) in Oslo, Norway
* Savored late night street food and laughs in Montevideo, Uruguay
* Stood in awe and reverence in the [Westminster Abbey](http://www.westminster-abbey.org/) in London, England
* Strolled under a canopy of strange and beautiful trees in the Blue Mountains near Sydney, Australia

...and so many more things that me-of-10-years-ago would have never dreamed of doing.

As awesome as all the places are, it's the people I've met, relationships that have formed, and experiences I've shared with friends and family that are the most precious.

Public speaking has made my world bigger, more colorful, and more accessible.

## Make a Goal of Three

I love the feeling of helping other people in the community *more* than the anxiety caused by public speaking. It didn't take long for me to get hooked.

Give a lunch-and-learn talk at your company. Give a show-and-tell or short presentation at one of your local [meetups](https://www.meetup.com/). Talk about something you're learning, or something you like to geek out about.

If after three tries you're still not convinced, no harm done. You will have accomplished far more than most people. You'll also have new skills and knowledge that will continue to pay dividends going forward.

Who knows where it could take you?

## Next Steps

Want some tips and secrets? [Watch my presentation](https://youtu.be/aPSvHT9USO8) from [Nodevember](http://nodevember.org/) 2016. 

Check out my [Public Speaking Resources](https://github.com/reverentgeek/public-speaking/blob/master/README.md).

Need more evidence? Read Cory House's article, [Public Speaking Transformed My Life... and Can Change Yours, Too](https://medium.freecodecamp.org/public-speaking-transformed-my-life-and-can-change-yours-too-ca8acdbcc188).

Get out there and be awesome!

![](https://thepracticaldev.s3.amazonaws.com/i/qm90jslkihkjb6cf8b9i.PNG)
def of_ready(*args, **kwargs)
Tags: dor, agile, techcoach, dev3l
Published: 2017-08-11 05:54:23

---
title: def of_ready(*args, **kwargs)
published: true
description: Agile Fundamentals - Definition of Ready (DoR)
tags: DoR, Agile, TechCoach, DEV3L
---
## TL;DR
- **Definition of Ready (DoR)** defines a agile story's “ready state”
- Considerations before an item is pulled into owned value stream
- Direct impact on the 8 Wastes of Lean
- Does not mean story is 100% defined with zero unknowns
- Summed up in a radiated checklist
- Reference Blog Post (Shameless Plug): [Definition of Ready](https://softwaredev3loper.wordpress.com/2016/03/01/definition-of-ready/)

---

# Definition of Ready - DoR
Ideally, DoR should be applied to every unit of work entering your section of the value stream. The *Scrum Agile Lean DevOps* (SALD) model teaches us to **optimize for downstream**. Thus, if your organization is a permutation of SALD, it is fair to ask internal customers/team members to do the same.

In reality, we need to work with our customers (product owners) to create a common understanding of the minimum sufficient amount of details necessary to not waste either parties time. *(Excess Processing)*
'I don't have time now' directly translates into 'waste'. It explicitly implies WIP is too large. *(Inventory Excess)*
DoR prevents churn, misunderstandings, and bottlenecks! *(Motion, Defects, Transportation, Overproduction, Waiting)*
Brain surgeons don't work in reception. *(Not utilizing talent)*

# Radiation
If you cannot directly point to your team's explicit definition of ready from your individual work space, you *may* not have a definition of ready...

# DoR Checklist
- Value is understood
- Acceptance criteria are clear and testable
- Shared understanding within the team (NO SILOS)
- Known dependencies
- Similar features for reference
- Size is sufficiently small
- Testing effort is considered and/or discussed
- Non-functional requirements
- How to demonstrate the story's work
- Defects are reproducible with fixtures
A Good Manager Is Like a Gardener
Tags: management, leadership
Published: 2017-08-10 20:31:37

---
title: A Good Manager Is Like a Gardener
published: true
description: My favorite metaphor from a Management 3.0 workshop
tags: management, leadership
cover_image: https://team-coder.com/images/good_manager_dev_to.jpg
canonical_url: https://team-coder.com/good-manager
---

Since I attended a Management 3.0 workshop a couple of weeks ago there is one thing that I cannot get out of my mind. It was a simple metaphor: A good manager is like a gardener. Imagine a garden full of vegetables, fruits and other plants. The gardener’s job is to create as much value as possible out of the garden. Value might be the fruits that the plants create. The more tomatoes, strawberries and potatoes grow the more value comes out of the garden.

What can the gardener do to create more value? Would it be helpful to go to the tomato plant and tell it to grow faster? To create more tomatoes? Definitely not. Are there any benefits the gardener should offer the tomato plant for growing faster? I don’t think so. But what can the gardener do? He can change the environment. He can create an optimal environment for the tomato plant and all the other plants to grow and create fruits. The gardener can give them water, maybe also a little bit of fertilizer. He can rearrange the plants if he realises that two of them have a bad influence on each other. Maybe one of them is too dominant and represses the other one. He can also protect the plants from too much direct sun light by creating some shadow areas.

In my opinion, a good manager should do what a gardener would do: Not telling his people what to do but helping them to grow. Creating an environment where everybody is save and where everybody can improve, be productive and be happy.
Hello, I'm Sammy!
Tags: introductions
Published: 2017-08-10 18:35:54

---
title: Hello, I'm Sammy!
published: true
description: 
tags: introductions
---
Hello! I'm Sammy. I'm a software developer currently at Precision Infinity in Orlando, FL.

Most of what I enjoy is web development and design. I also do photography, you should check that out too!
How does your team handle 'on call' evening/weekend hours?
Tags: meta, discuss
Published: 2017-08-10 14:28:08

---
title: How does your team handle 'on call' evening/weekend hours?
published: true
description: 
tags: meta, discuss
---

As Ben pointed out in his post, ["I've been de facto on call 24 hours a day since starting dev.to but this weekend I'm going camping"](https://dev.to/ben/ive-been-de-facto-on-call-24-hours-a-day-ever-since-starting-devto-but-this-weekend-im-going-camping-), we clearly don't have a fair schedule for handling late night or weekend emergencies, yet. 

I know some teams rotate weekend duty and get a weekday off here or there, but I'd really like some real world recommendations or what to or not to do.
The Bug lives on!
Tags: bugs, musings
Published: 2017-08-10 11:56:21

---
title: The Bug lives on!
published: true
description: A frustrated developer's musing. 
tags: bugs, musings 
---

You will be fine. 

Even though you tried all day, unsuccessfully, to fix that annoying bug before the close of work. You left work really late. You walked briskly and held on to your backpack with every atom of strength left. Looking from left to right, ensuring that your Macbook got home safely with you.

You got home, turned on the TV, continued G.O.T from where you left off last night. But your eyes slowly dim. You were really tired. But all you could dream about was that same ðŸž. ðŸ˜”

You woke up around 2:00 am, Determined to see the downfall of this annoying ðŸž. You powered on your Macbook, Docker is still active, containers running perfectly, Sublime text in `Distraction Free Mode`. But still, 7:00 am, ðŸž still walking wild and free.

Deprived of sleep, you decided to close your eyes for few minutes. The loud music from your neighbors flat woke you up. The time is 9:00 am.

You signed in to work remotely. Another day to fix that ðŸž.

You will be fine.   
....
Primary key in Realm
Tags: swift, realm, key, primary
Published: 2017-08-10 07:43:03

---
title: Primary key in Realm
published: true
description: 
tags: swift, realm, key, primary
---

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

Realm is great. But without primary key, it will duplicate the record, like https://github.com/realm/realm-java/issues/2730, http://stackoverflow.com/questions/32322460/should-i-define-the-primary-key-for-each-entity-in-realm, ... So to force ourselves into the good habit of declaring primary key, we can leverage Swift protocol

Create primary constrain protocol like this

```swift
protocol PrimaryKeyAware {
  var id: Int { get }
  static func primaryKey() -> String?
}
```

and conform it in out Realm object

```swift
class Profile: Object, PrimaryKeyAware {

  dynamic var firstName: String = ""
  dynamic var lastName: String = ""
  dynamic var id: Int = 0

  override static func primaryKey() -> String? {
    return "id"
  }
}
```

This way, when using that object in out `RealmStorage`, we are safe to say that it has a primary key

```swift
class RealmStorage<T: Object> where T: PrimaryKeyAware {
  let realm: Realm

  init(realm: Realm = RealmProvider.realm()) {
    self.realm = realm
  }

  func save(_ objects: [T]) {
    try? realm.write {
      realm.add(objects, update: true)
    }
  }
}
```

The usage is like this

```swift
let profile = Profile()
let storage = RealmStorage<Profile>()
storage.save([profile])
```
Composition in Realm
Tags: swift, realm, composition
Published: 2017-08-10 07:42:25

---
title: Composition in Realm
published: true
description: 
tags: swift, realm, composition
---

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

There is time we have models that have some kind of inheritance, like `Dog`, `Cat`, `Mouse` can be `Animal`. We can use composition to imitate inheritance, we just need to make sure it has unique primary key

## Cat and Dog

These are pretty much basic Realm objects

```swift
class Dog: Object {
  dynamic var id: Int = 0

  required convenience init(json: [String: Any]) {
    self.init()
    id <- json.integer(key: "id")
  }
}

class Cat: Object {
  dynamic var id: Int = 0

  required convenience init(json: [String: Any]) {
    self.init()
    id <- json.integer(key: "id")
  }
}
```

## Animal

Here `Animal`  can contain either `dog` or `cat`, we can add more if there are many other "inheritance" of `Animal`. The `required init` makes sure Animal can only be init with 1 type of `child` class

```swift
class Animal: Object {
  dynamic var id: Int = 0

  dynamic var cat: Cat?
  dynamic var dog: Dog?

  required convenience init(cat: Cat) {
    self.init()
    self.cat = cat
    self.id = cat.id
  }

  required convenience init(dog: Dog) {
    self.init()
    self.dog = dog
    self.id = dog.id
  }
}
```
Junior Developer title?
Tags: beginners, career, discuss
Published: 2017-08-10 07:40:51

---
title: "Junior Developer title?"
published: True
description: 
tags: beginners,career, discuss
---

Those of you who hire, considering a candidate who is the absolute greenest, and in hiring on an entry-level job, would you consider the title of someone's cv as "Junior Developer" a good idea? What would that say about the person to you? Is that a phrase that you tend to avoid or is it appropriate? I've read mixed reviews on this.

It's definitely what I would consider myself.

-Ryan Norton
Go formatting with rgblog
Tags: go, showdev
Published: 2017-08-09 22:42:34

---
title: Go formatting with rgblog
published: true
description: A Golang package for formatting standard output.
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5puijrn0x6jgdz2bgpso.jpg
tags: go, showdev
---

One of my projects involves a lot of console output, and to make it readable, I added some color. Cyan for important messages, red for errors, and yellow for normal (everything is fine) logs.

The short of it is: I wanted to do the same somewhere else, so I published it.

If you're a Go developer and want some quick and easy functions to color things, check it out.

Here's the [GitHub repo](https://github.com/foresthoffman/rgblog) if you want to see the README. Or, you can just `go get github.com/foresthoffman/rgblog` and use it right away.

If you'd like to see what the colors would look like, without downloading the package, you can run the following in your shell:

```bash
echo -e "
\033[0;37mNormal Colors\033[0m
Black\t\033[0;30mThe quick brown fox jumped over the lazy dog\033[0m
Red\t\033[0;31mThe quick brown fox jumped over the lazy dog\033[0m
Green\t\033[0;32mThe quick brown fox jumped over the lazy dog\033[0m
Yellow\t\033[0;33mThe quick brown fox jumped over the lazy dog\033[0m
Blue\t\033[0;34mThe quick brown fox jumped over the lazy dog\033[0m
Magenta\t\033[0;35mThe quick brown fox jumped over the lazy dog\033[0m
Cyan\t\033[0;36mThe quick brown fox jumped over the lazy dog\033[0m
White\t\033[0;37mThe quick brown fox jumped over the lazy dog\033[0m

\033[1;37mBold/Bright Colors\033[0m
Black\t\033[1;30mThe quick brown fox jumped over the lazy dog\033[0m
Red\t\033[1;31mThe quick brown fox jumped over the lazy dog\033[0m
Green\t\033[1;32mThe quick brown fox jumped over the lazy dog\033[0m
Yellow\t\033[1;33mThe quick brown fox jumped over the lazy dog\033[0m
Blue\t\033[1;34mThe quick brown fox jumped over the lazy dog\033[0m
Magenta\t\033[1;35mThe quick brown fox jumped over the lazy dog\033[0m
Cyan\t\033[1;36mThe quick brown fox jumped over the lazy dog\033[0m
White\t\033[1;37mThe quick brown fox jumped over the lazy dog\033[0m
"
```

In mine it looks like this:

<img src="http://foresthoffman.com/wp-content/uploads/2017/08/ansi-color-table.png">

Cheers!

## Credits
Cover image by [Steve Johnson](https://unsplash.com/@steve_j?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/rainbow-letter?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)! :D
Explain OAuth2 like I'm five
Tags: explainlikeimfive, discuss, oauth, security
Published: 2017-08-09 21:30:13

---
title: Explain OAuth2 like I'm five
published: true
description: 
tags: explainlikeimfive, discuss, oauth, security
---

I've actually been curious about this for a while and can't seem to find anywhere that really talks about this. Especially the server end of it.
Hello I am Sebastian
Tags: hello, php
Published: 2017-08-09 20:35:28

---
title: Hello I am Sebastian
published: true
description: 
tags: hello, php
---

Sorry, this is my second article, must be the first but I published another before this.

I live in Olbia, Sardinia.

You can find me on Twitter as @SebastianR1982 or via e-mail at sebastian.rapetti@alice.it and I am currently working on github at https://github.com/linna

I am coding since 2002. I mostly speak PHP, but if needed C, C++ and every C like language, I will wish learn Python and Go.

I'm learning everything I can :), programming for me is an hobby, however calling it hobby is reductive, I see programming like an art, the code like a sculpture. A raw piece of stone after hard work becomes art, a raw piece of code, a function or a class after optimizing become art.

I am developing not for job, only for passion.

Nice to meet all.
I'm Wes Bos, Ask Me Anything!
Tags: ama, javascript
Published: 2017-08-09 17:06:59

---
title: I'm Wes Bos, Ask Me Anything!
published: true
description: I'm Wes Bos, a full stack developer from Canada who makes some really great online courses like JavaScript30, React For Beginners, What The Flexbox?!, ES6 for Everyone and Learn Node.
tags: ama, javascript
cover_image: https://thepracticaldev.s3.amazonaws.com/i/lfvcxdft4dct2z43iig5.png
---

I'm [Wes Bos](https://wesbos.com), a full stack developer from Canada who makes some really great online courses like [JavaScript30](https://javascript30.com/), [React For Beginners](https://reactforbeginners.com/), [What The Flexbox?!](https://flexbox.io), [ES6 for Everyone](https://es6.io/) and [Learn Node](https://learnnode.com/).

I'm pretty active on twitter [@wesbos](https://twitter.com/wesbos) and I've just started a podcast with Scott Tolinkski called [Syntax](https://syntax.fm)


I'm pretty fortunate to have turned my love of web development and business into a career so I'd love to chat about either of those topics (or anything else really!). My AMA will start at 2PM ET today, August 9, so please feel free to Ask Me Anything!
The dev.to tech stack
Tags: ourstack, meta
Published: 2017-08-09 16:23:19

---
title: The dev.to tech stack
published: true
description: All the libraries, APIs, services, and infrastructure we use to serve the platform.
tags: ourstack, meta
---

## Here's our stack:

### Open Source
- Ruby on Rails
- Mostly VanillaJS with PreactJs for some components
- Postgres (hosted on Heroku)

### Infra/Services

- [Heroku](https://heroku.com)
- [Fastly](https://www.fastly.com/)
- [Airbrake](https://airbrake.io/)
- [Skylight](https://www.skylight.io)
- [Sendgrid](https://sendgrid.com/)
- [Amazon S3](https://aws.amazon.com/s3/)
- [Google Analytics](https://analytics.google.com)
- [Stream](https://getstream.io/)
- [Algolia](https://www.algolia.com/)
- [Algorithmia](https://algorithmia.com/)
- [Timber](https://timber.io)
- [Codeship](http://codeship.com/)
- [Codeclimate](https://codeclimate.com)
- [GitHub](https://github.com)
- [Pusher](https://pusher.com)
- [Twilio Video](http://twitter.com/video)
- [DaCast](https://www.dacast.com/)

Sometimes it's hard to say where to delineate the line of services that are part of the "stack" vs ones that are more just part of the business, but this is a list of tech we use that seems to fit the "stack" bill. I've also omitted a couple services that we have integrated but don't actively use at the moment. I've also omitted some stuff that seems to just be part of the Heroku default bundle. I also might have forgotten about something.

Anyway, feel free to ask us anything about what we use.