teleren/devto huggingface dataset:
How To Code Simple Data — Week 1a
Tags: learningtocode, p1xtguides, racket
Published: 2020-01-14 00:00:04

---
title: How To Code Simple Data — Week 1a
published: true
date: 2017-09-14 17:44:44 UTC
tags: learning-to-code,p1xt-guides,racket
canonical_url: 
---

#### A recap of what I learned in the first part of the edX/UBCx course [HtC: Simple Data](https://courses.edx.org/courses/course-v1:UBCx+HtC1x+2T2017/course/)

Moving far far away from the “familiar” land of JavaScript, we take a step aside to learn a new language, Racket. The first part of Week 1 for this course teaches the fundamentals of “Beginning Student Language” a subset of Racket Language. Racket is a run-time compiled language (like JS) that is most easily written and run in the Dr Racket open source software. It is a whole lot different than JS.

Racket has different types from JS, and seems to be strongly typed. We have strings, booleans, images, numbers. We start all our calls with a paren, and the notation is a bit funny. To add two numbers we write (+ 2 2). With more math we can write (+ 2 (\* 3 2)) which gives 8. To compare if six is more than two we write (\> 6 2) and that would give a boolean true. We can define constants: (define image1 (circle 10 "solid" "red)). The IDE is a bit tough, as it doesn’t close parens automatically.

However when you make a mistake, the error reports are generally quite helpful about what you did wrong, _usually a forgotten or misplaced paren_. The software also has a great stepper tool for debugging! It also has (so far) thorough and helpful docs.

This course is aimed at those who have never programmed much, but it steps up the game pretty quickly. So far I am enjoying it, even if it’s another white male teaching :)

I will close with this bit of positivity from Professor Kiczales:

> One of the great things about computer programming is these machines are not fragile. If you make a mistake, you get an error message, not quite the right thing happens, you just fix it.  
> I’m not saying we shouldn’t worry about errors in our programs. The design method we’re going to learn is going to help us prevent and find such errors.  
> All I’m saying is, if you get an error while you are working, don’t worry about it.
Efficient developers write programs for themselves
Tags: devtips, productivity
Published: 2017-09-14 15:23:37

---
title: Efficient developers write programs for themselves
tags: devtips,productivity
published: true
description: The shoemaker's son always go barefoot.
cover_image: http://danlebrero.com/images/blog/efficient-write-programs.jpg
canonical_url: http://danlebrero.com/2017/08/03/efficient-developer-write-programs-for-yourself/
series: Efficient Development
---

It saddens, and surprises me the amount of manual work that we developers put up with. It is paradoxical that we are paid to automate other people’s work, yet fail do so the same with our own.

I am not just talking about automating tasks that can take you hours or days to do. A five second task that is repeated often enough may well be worth automating. 

Automation saves time, enables repeatability, avoids mental overhead, and [can be rewarding](http://danlebrero.com/2017/04/06/documenting-your-architecture-wireshark-plantuml-and-a-repl/#content).

## One off tasks

Your attitude before starting any task, no matter how small, should be: can I write a program to do this? 

A word of caution, though: set a time limit for the task, as you can really get lost down the rabbit hole. Once that time limit has elapsed, you have to be willing to let it go and do the task manually. This requires a surprising amount of discipline.

## Beware the GUI

GUIs, like the Sirens, lure you with an easy first time experience, but then enslave you in their own isolated world, away from other programs.

You want to use tools that compose. You want to use programs that you can glue together with other programs. Programs that can be inside a for loop. 

GUIs do not compose. Free yourself.

## Automation Tools

For quick and easy things, there is nothing like a good old Bash shell. It is the only tool that has remained constantly useful in my 17 years of working experience.

For more complex tasks, just use whatever your production programming language is. It probably has tons of libraries available which you are already very proficient with.

Or maybe you could use that “forbidden” language, the one that you actually love, thus making the task doubly enjoyable.

Remember that **you are a developer**. So develop. Write programs. Free yourself.
Given When Then in Swift tests
Tags: swift, tests, bdd
Published: 2017-09-14 11:56:52

---
title: Given When Then in Swift tests
published: true
description: 
tags: swift, tests, bdd
---

### Spec

Using `spec` testing framework like [Quick](https://github.com/Quick/Quick) is nice, which enables `BDD` style.

```swift
describe("the 'Documentation' directory") {
  it("has everything you need to get started") {
    let sections = Directory("Documentation").sections
    expect(sections).to(contain("Organized Tests with Quick Examples and Example Groups"))
    expect(sections).to(contain("Installing Quick"))
  }

  context("if it doesn't have what you're looking for") {
    it("needs to be updated") {
      let you = You(awesome: true)
      expect{you.submittedAnIssue}.toEventually(beTruthy())
    }
  }
}
```

But in case you don't want additional frameworks, and want to live closer to Apple SDKs as much as possible, here are few tips.

### Naming

This is from the book that I really like [The Art of Unit Testing](http://artofunittesting.com/). If you don't mind the underscore, you can follow [UnitOfWork_StateUnderTest_ExpectedBehavior](http://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html) structure

```
func testSum_NegativeNumberAs1stParam_ExceptionThrown()
func testSum_NegativeNumberAs2ndParam_ExceptionThrown()
func testSum_simpleValues_Calculated()
```

### Given When Then

This is from BDD, and practised a lot in [Cucumber](https://github.com/cucumber/cucumber/wiki/Given-When-Then). You can read more on https://martinfowler.com/bliki/GivenWhenThen.html.

First, add some more extensions to `XCTestCase`

```swift
import XCTest

extension XCTestCase {
  func given(_ description: String, closure: () throws -> Void) throws {
    try closure()
  }

  func when(_ description: String, closure: () throws -> Void) throws {
    try closure()
  }

  func then(_ description: String, closure: () throws -> Void) throws {
    try closure()
  }
}

```

Then, in order to test, just follow `given when then`

```swift
func testRemoveObject() throws {
  try given("set to storage") {
    try storage.setObject(testObject, forKey: key)
  }

  try when("remove object from storage") {
    try storage.removeObject(forKey: key)
  }

  try then("there is no object in memory") {
    let memoryObject = try? storage.memoryCache.object(forKey: key) as User
    XCTAssertNil(memoryObject)
  }

  try then("there is no object on disk") {
    let diskObject = try? storage.diskCache.object(forKey: key) as User
    XCTAssertNil(diskObject)
  }
}
```

I find this more interesting than comments. All are code and descriptive. It can also be developed further to throw the `description` text.

❤️ Support my apps ❤️ 

- [Push Hero - pure Swift native macOS application to test push notifications](https://onmyway133.com/pushhero)
- [PastePal - Pasteboard, note and shortcut manager](https://onmyway133.com/pastepal)
- [Quick Check - smart todo manager](https://onmyway133.com/quickcheck)
- [Alias - App and file shortcut manager](https://onmyway133.com/alias)
- [My other apps](https://onmyway133.com/apps/)

❤️❤️😇😍🤘❤️❤️
Checking generic type in Swift
Tags: swift, generic, type
Published: 2017-09-14 11:56:11

---
title: Checking generic type in Swift
published: true
description: 
tags: swift, generic, type
---

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

When dealing with generic, you shouldn't care about the types. But if you need, you can

```swift
 func isPrimitive<T>(type: T.Type) -> Bool {
  let primitives: [Any.Type] = [
    Bool.self, [Bool].self,
    String.self, [String].self,
    Int.self, [Int].self,
    Float.self, [Float].self,
    Double.self, [Double].self
  ]

  return primitives.contains(where: { $0.self == type.self })
}
```
How do you maintain entity state in Golang
Tags: go, designpatterns, question, discuss
Published: 2017-09-14 11:25:27

---
title: How do you maintain entity state in Golang
published: true
description: Is this the best way in Go to create an Entity that can't be set into an invalid state?
tags: golang, design patterns, question, discuss
---

Is this the best way in Go to create an Entity that can't be set into an invalid state?

Here's an example of how I might implement it. I'm unsure if this is very idiomatic.

```go
package custom_subdomain

import (
	"errors"
	"regexp"
)

type domainReg struct {
	domainName string
	// Other values ...
}

func NewDomainRegistration(domainName string) (*domainReg, error) {
	reg := &domainReg{}
	if err := reg.SetDomainName(domainName); err != nil {
		return nil, err
	}

	return reg, nil
}

func (r *domainReg) GetDomainName() string {
	return r.domainName
}

func (r *domainReg) SetDomainName(domain string) error {
	matches, err := regexp.Match("\\.example.com$", []byte(domain))

	if err != nil {
		return err
	}

	if !matches {
		return errors.New("all domains must be sub-domains to .example.com")
	}

	r.domainName = domain

	return nil
}

type DomainRegistration interface {
	GetDomainName() string
	SetDomainName(domain string) error
}
```

```go
package main

import (
	"fmt"
	"github.com/purplebooth/entity-state-example"
	"log"
)

func main() {
	
	reg, err := custom_subdomain.NewDomainRegistration("test.example.com")
	
	if err != nil {
		log.Panic(err)
	}
	
	fmt.Println(reg.GetDomainName())

}

```
Automatically generate API documentation from RSpec tests
Tags: opensource, rspec, testing, rails
Published: 2017-09-14 11:24:00

---
title: Automatically generate API documentation from RSpec tests
published: true
description: Automate your documentation writing proces! Dox generates API documentation from RSpec controller/request specs in a Rails application. It formats the tests output in the API Blueprint format.
tags: opensource, rspec, testing, rails
---

Manual documentation maintenance can be time-consuming and error-prone, and nobody likes to do it. Due to human error, things are often overlooked, forgotten or accidentally replaced. Most developers were involved in unnecessary debugging sessions because API was changed but the documentation was not properly updated.

We've built a gem for generating documentation from RSpec tests for Rails - [Dox](https://github.com/infinum/dox). It uses the request/response information from your test examples and you only need to write some metadata using the Dox DSL. It generates [API Blueprint](https://apiblueprint.org/) formatted markdown. To see it in action, check out the [demo app](https://github.com/infinum/dox-demo).

It should take you no time to plug it in your Rails/RSpec API app and start enjoying the extra time.


*Read the full article on [The Capsized Eight blog](https://infinum.co/the-capsized-eight/generate-api-documentation-from-rspec-examples-with-dox)*.
Looking for advice on projects to learn c# and .net
Tags: discuss, career
Published: 2017-09-14 09:28:48

---
title: Looking for advice on projects to learn c# and .net
published: true
description: Learning c# 
tags: #discuss #career 
---
Hi there,

A few months ago I decided that I'd like to quit my current field of work and get a job within the software industry. It's a  big step for me as I have no background in actual software development, no work experience and last but not least no education in the field.
 
In the mean time I'm studying as much as possible from the Microsoft Visual studio Academy and am now approaching the point where I'm not sure what direction to follow. 

I'd like to work on 1 or 2 projects that would teach me more about software development and be useful in a real world situation. 
I'm struggling to come up with these as I lack the experience of working in a company on a daily basis.

Any suggestions and idea's would be greatly appreciated, please keep in mind that I'll be working on these by myself so they have to be realistic goals.

I've worked on real time interactive installations for over 7 years now with programs like Max msp, Touch designer and Processing, so the concepts of basic code,logic and programming is familiar to me.

Thanks for your time.
Do you use the ðŸ¤” reaction on dev.to seriously?
Tags: discuss, meta
Published: 2017-09-13 17:44:54

---
title: Do you use the ðŸ¤” reaction on dev.to seriously?
published: true
description: deep questions
tags: discuss, meta
---

Every time I get one of these ðŸ¤” reactions to my posts here, I can't help but think that people are throwing shade ðŸ˜ƒ.

![](https://thepracticaldev.s3.amazonaws.com/i/r62vlbbjr2bf0niljx81.png)

Am I alone?
I'm a Git Master, Ask Me Anything
Tags: ama, git
Published: 2017-09-13 17:16:07

---
title: I'm a Git Master, Ask Me Anything
published: true
description: I've been programming for 20 years. I'm very passionate about what I do and lately I've been on a mission to empower developers to master Git. So I'm glad to answer any and all of your Git questions (or anything else).
tags: ama, git
cover_image: https://thepracticaldev.s3.amazonaws.com/i/h57ibe3l5s60cx57yklu.png
---
Hi, I'm [Jason McCreary](https://jason.pureconcepts.net). I go by _JMac_.

I'm a full stack and iOS developer who likes building products and services. Recently this includes services like [Laravel Shift](https://laravelshift.com) and [Getting Git](https://gettinggit.com).

I've been programming for 20 years. I'm very passionate about what I do and lately I've been on a mission to empower developers to master Git. So I'm glad to answer any and all of your Git questions (or anything else).

My AMA will start at 2PM ET today, September 13th, so please feel free to _Ask Me Anything_!
The day I broke Gab.ai
Tags: gab, social, media, network
Published: 2017-09-13 08:11:54

---
title: The day I broke Gab.ai
published: true
description: (or how not to fetch user timelines)
tags: 
- gab
- social
- media
- network
---
## Intro
As a social network, [Gab](https://gab.ai) is trash... but a great way to learn from other people's mistakes, and that's what this post is all about!
They have a JSON API (only used internally, they don't talk about it anywhere) for basically everything, and most things are not rate limited.
Obviously, I wanted to see what I can do.

## The beginning
Once I wrote PHP functions for everything the API had to offer, I made a simple bot that would take the messages people sent, passed them through Cleverbot and posted the answer...
Until it wasn't working anymore, my IP was blocked from viewing my notifications. Forever.
I thought about all the bot accounts that followed me as soon as I created my account. They probably don't limit when you follow people!
And turns out they don't. And looking at your timeline isn't limited. My plan: Follow every single user and look at my timeline to see if anyone mentioned the bot.

## The mess
I set it up so my bot follows about 100 users every 5 minutes, I looked at my follow count from time to time then went to bed.
2 March 2017, Gab is having trouble loading, other people are starting to report the problems, I just think they are getting ddossed by some skid.
The next day, everyone was getting 502 or 504 errors, meaning we could not message [@support](https://gab.ai/support) to ask what was going on.

## The aftermath
After a week or so, everything was back to normal.
I went to tweak some things on my bot, but the account disappeared, that's when I realised I was probably the cause of this.
It followed 145k accounts at a slow pace, and all it was doing was check its timeline like a normal user would.


**Lessons learned: check if your whole website can be killed by simply following a lot of people, limit your API even if you think you will be the only one using it.**

*Note: This can still be done, it doesn't look like they fixed anything.*
How do you make it easier to search through version control for deleted code?
Tags: discuss
Published: 2017-09-13 16:20:29

---
title: How do you make it easier to search through version control for deleted code?
published: true
tags: discuss
---

The basic instruction is that one should delete dead code and find it later in version control if it is needed, but this requires the step of making it reasonably easy to find it. What are the steps you go to to ensure this task is straightforward?
Master your IDE
Tags: devtips, productivity
Published: 2017-09-13 16:10:17

---
title: Master your IDE
tags: devtips,productivity
published: true
description: A professional developer should look professional while using his main tool.
canonical_url: http://danlebrero.com/2017/08/02/efficient-developer-master-your-ide/
cover_image: http://danlebrero.com/images/blog/efficient-master-ide.jpg
series: Efficient Development
---

As a developer, you are going to spend thousands of hours working with your IDE or editor of choice. It is your main tool, you need to know how to get the most out of it.

Using your IDE 8 hours a day is not enough, you need to make a conscious and deliberate effort to master it. As a wise man once said:

>[Wax on, Wax off](https://youtu.be/SMCsXl9SGgY?t=1m17s)
<cite>Master Miyagi, The Karate Kid.</cite>

You must learn:

1. The shortcuts for all the functionality that you regularly use. You should rarely need to use your mouse.
2. Its features: read the release notes, watch online tutorials or follow some expert that blogs about it.

If you happen to use Intellij IDEA, the Key Promoter plugin will help to learn the shortcuts and JetBrains provides a ton of online material. Follow their [blog](https://blog.jetbrains.com/idea/) and [youtube channel](https://www.youtube.com/user/intellijideavideo). 

But the most effective way of learning your IDE is to do pair programming. As part of your daily job, each of your partners will teach you different features, and you will have the chance to teach them to others, creating a nice cross-pollination effect.

And you can always ask your partner to slap you every time that you reach for the mouse. A win-win situation.
Grab Your GitHub URLs Without Leaving The Command Line
Tags: git, github, bash
Published: 2017-09-13 16:00:09

---
title: Grab Your GitHub URLs Without Leaving The Command Line
published: true
description: Here's a quick and easy way to access your GitHub urls without booting up the browser.
cover_image: https://thepracticaldev.s3.amazonaws.com/i/uws86acmrtyf1yivjpdv.jpg
tags: git, github, bash
---

In keeping with my previous post about [initializing, populating, and posting a repo to GitHub in just one step](https://dev.to/cmilr/initialize-populate-and-post-your-git-repo-to-github-in-a-single-step), I thought I'd share a quick one-liner bash alias I use for listing my GitHub urls on the command line.

```
alias ghrepos="curl -s -i -H 'Authorization: token $GHUB_TOKEN' \
    https://api.github.com/user/repos | grep -o 'https://github.com[^\"]*.git'"
```
To use the above alias, you'll just need to replace $GHUB_TOKEN with your own ***Personal Access Token*** from GitHub.

There are many benefits to having this function at your fingertips—you can use it to quickly: 
* Navigate to a repo's url.
* Clone a repo to your local machine.
* Or just peruse your remote repos in one simple list, like this:

```
$ ghrepos

https://github.com/cmilr/Atom-Prefs.git
https://github.com/cmilr/Bash-Prefs.git
https://github.com/cmilr/Blender-Playground-v1.1.git
https://github.com/cmilr/Blender-Prefs.git
https://github.com/cmilr/CMillerCo-HTML.git
https://github.com/cmilr/CMillerCo-Rails.git
https://github.com/cmilr/DeadSimple-Blender-3D-Cheat-Sheet.git
https://github.com/cmilr/DeadSimple-Pixel-Perfect-Camera.git
https://github.com/cmilr/Git-Beautify-For-MacOS-Terminal.git
https://github.com/cmilr/HTML-Essential-Training.git
https://github.com/cmilr/iOS-Postprandial-Timer.git
https://github.com/cmilr/iOS-Programming-Big-Nerd-Ranch.git
https://github.com/cmilr/iOS-SwiftCalc.git
https://github.com/cmilr/Learning-iOS-App-Dev-1.git
https://github.com/cmilr/Learning-iOS-App-Dev-2.git
https://github.com/cmilr/Learning-iOS-App-Dev-3.git
https://github.com/cmilr/Unity2D-Components.git
https://github.com/cmilr/Unity3D_ImporterDefaults.git
https://github.com/cmilr/Visual-Studio-For-Mac-Dark-Syntax-HoneyBees.git
https://github.com/cmilr/VS-Prefs.git
https://github.com/cmilr/Xcode-Prefs.git
```

I hope you find this as useful as I do.

## Thanks for stopping by!
Localname - Secure Access to Your Local Development Server
Tags: development, localhost, remote, showdev
Published: 2017-09-13 13:25:06

---
title: "Localname - Secure Access to Your Local Development Server"
published: true
description: No longer fiddle with router configurations, IP's or ports. Localname provides a single URL that just works.
tags: development, localhost, remote, showdev
canonical_url: https://mobilejazz.com/blog/introducing-localname-our-latest-product/
---

<img src="https://mobilejazz.com/blog/wp-content/uploads/2017/04/localname-1.jpg" alt="" width="1200" height="630" class="aligncenter size-full wp-image-5066" data-wp-pid="5066" />

At <a href="http://mobilejazz.com/" target="_blank">Mobile Jazz</a>, we’re always <a href="https://mobilejazz.com/products/opensource" target="_blank">innovating new utilities</a> which help our clients, and tools such as <a href="https://www.bugfender.com/">Bugfender</a> to assist developers around the world. Today, we’d like to introduce you to our latest product, <a href="http://www.localname.io/" target="_blank">Localname</a>.

<h2>What is Localname?</h2>

Localname is a native Mac app for developers that creates a single url that grants access to their local development machine.

<strong>What Does This Mean?</strong>

Oftentimes it can be useful for a developer to show a client the development progress of a project. This can be tricky at times, requiring complex router IP and port configurations.

Localname does the hard work for you, providing a single url that allows your designer, client or project manager to review your progress.

<img src="https://mobilejazz.com/blog/wp-content/uploads/2017/04/localname-2.jpg" alt="" width="1200" height="630" class="aligncenter size-full wp-image-5067" data-wp-pid="5067" />

<h2>Why Did We Create It?</h2>

As a mobile app and web development agency, we find tools that aid collaboration to be incredibly useful, both amongst ourselves and with our clients. Aside from projects reviews, we actually built Localname with a few more use cases in mind:

<strong>Mobile App Testing</strong>

As Localname provides a secure tunnel to your local development machine, it enables you to easily test your mobile application’s backend from real devices.

<strong>Webhooks</strong>

Testing webhooks become a lot easier when you can provide a callback url that leads to your development machine.

<strong>Remote Debugging</strong>

Localname project reviews also double us as a great live debugging sessions whilst on a conference call.

<img src="https://mobilejazz.com/blog/wp-content/uploads/2017/04/localname-3.jpg" alt="" width="1200" height="630" class="aligncenter size-full wp-image-5068" data-wp-pid="5068" />

<h2>How Does It Work?</h2>

Localname is a native macOS application. When opening the application, you’ll be prompted to create a url and Localname will simply do the rest. It will create a secure tunnel to your local development machine, granting access to anyone with the url you created.

<h2>Where Can I Get Started?</h2>

To download, head to <a href="http://localname.io">localname.io</a> and sign up today.