teleren/devto huggingface dataset:
The easiest way to handle UIAlertController in Swift
Tags: swift, uialertcontroller
Published: 2019-08-12 06:58:40

---
title: The easiest way to handle UIAlertController in Swift
published: true
description: The easiest way to handle UIAlertController in Swift. The default UIAlertController requires the foreground UIViewController to show, and sometimes another UIViewController covers the alert view.
tags: Swift, UIAlertController
cover_image: https://thepracticaldev.s3.amazonaws.com/i/qxk7eku8n59fvy24rzog.png
---


UIKit provides UIAlertController, but it is sometimes annoying to use. You have to get the top UIViewController. I will introduce an easier way to handle UIAlertController.


```swift
// AlertController.swift

UIKit 

class AlertController: UIAlertController {
    private lazy var alertWindow: UIWindow = {
        let window = UIWindow(frame: UIScreen.main.bounds)
        window.rootViewController = ClearViewController()
        window.backgroundColor = UIColor.clear
        window.windowLevel = UIWindow.Level.alert
        return window
    }()
    
    /// Shows a custom alert controller.
    func show(animated flag: Bool = true, completion: (() -> Void)? = nil) {
        guard let rootVC = alertWindow.rootViewController else { return }
        alertWindow.makeKeyAndVisible()
        rootVC.present(self, animated: flag, completion: completion)
    }
}

private class ClearViewController: UIViewController {
    override var preferredStatusBarStyle: UIStatusBarStyle {
        return UIApplication.shared.statusBarStyle
    }
    
    override var prefersStatusBarHidden: Bool {
        return UIApplication.shared.isStatusBarHidden
    }
}
```


You can use `AlertController` like following. This alert will allow you to show an alert view from anywhere easily. I mean, You don't have to call `present(viewControllerToPresent: UIViewController>, animated: Bool, completion: (() -> Void)?)` from UIViewController anymore.


```swift
func displayAlert() {
    let alert = AlertController(title: "Error", message: "Something happened", preferredStyle: .alert)
    let action = UIAlertAction(title: "OK", style: .default)
    alert.addAction(action)
    alert.show()
}
```

You might want to extend `Error` like below. You can show an error alert like `error.displayAlert()`. It's easy, isn't it?

```swift
extension Error {
    func displayAlert(completion: (() -> Void)? = nil) {
        let alert = AlertController(title: "Error", message: localizedDescription, preferredStyle: .alert)
        let action = UIAlertAction(title: "OK", style: .default)
        alert.addAction(action)
        alert.show(completion: completion)
    }
}
```
Enrich ELMAH errors using error filtering hook
Tags: aspnet, csharp, dotnet, elmah
Published: 2019-08-12 06:52:54

---
title: Enrich ELMAH errors using error filtering hook
published: true
description: In this post, I will show you how to enrich an error using error filtering with custom data before sending it off to the configured ELMAH store.
tags: aspnet, csharp, dotnet, elmah
canonical_url: https://blog.elmah.io/enrich-elmah-errors-using-error-filtering-hook/
---

I see a lot of questions from people asking for ELMAH hooks, to be able to modify errors before written to ELMAH. While the elmah.io client supports modifying messages, ELMAH in its open-source form doesn't.

With that said, there's still a way to achieve this. Let's say you want to override the user field on all errors, to a value fetched from your database. As a default, ELMAH annotates all errors with the value of `Thread.CurrentPrincipal.Identity.Name`, but that may not be what you want logged in all cases.

To hook into ELMAH, we'll use a hook really meant for something else: error filtering. Add a new method to `Global.asax.cs` named `ErrorLog_Filtering`:

```csharp
void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs args)
{
}
```

This method is called by ELMAH before logging all exceptions. We don't have access to the actual error object logged in this method, why we cannot just set a new username. But using a small trick, we can still achieve what we are looking to do:

```csharp
void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs args)
{
    var httpContext = args.Context as HttpContext;
    if (httpContext != null)
    {
        var error = new Error(args.Exception, httpContext);
        error.User = GetUserFromDatabase();
        ErrorLog.GetDefault(httpContext).Log(error);
        args.Dismiss();
    }
}
```

See what I did there? I simply create a new `Error` object and set the `User` property to the value of `GetUserFromDatabase`. The method is created for the example and can be anything from an in-memory variable to the result of a REST request.

When the new error is created, I call the `Log` method on ELMAH to log it to the configured store. To avoid logging two errors (the original error without the user and the new error including the user), it's important to call the `Dismiss`-method on the original error arguments.

That's it! All errors are now logged with a custom value in `User`. The same approach can be used for setting any variable on ELMAH's `Error` object.

## Would your users appreciate fewer errors?

elmah.io is the easy error logging and uptime monitoring service for .NET. Take back control of your errors with support for all .NET web and logging frameworks.

➡️ [Error Monitoring for .NET Web Applications](https://elmah.io/?utm_source=devto&utm_medium=social&utm_campaign=devtoposts) ⬅️

This article first appeared on the elmah.io blog at https://blog.elmah.io/enrich-elmah-errors-using-error-filtering-hook/
My summer projects with React and NodeJs
Tags: react, node
Published: 2019-08-12 04:58:39

Here are React and Nodejs projects that I built with my friend during the summertime. It's all very exciting as well as a great learning experience. 

I learned a lot while working on these projects

Check it out!

- React with Redux-observable + Styled-component:
 
https://github.com/vinhlee95/awesome-react-typescript-boilerplate/tree/feature/reduxObservable

- React with Redux-thunk + Sass: 

https://github.com/vinhlee95/awesome-react-typescript-boilerplate/tree/develop

- Nodejs:

 https://github.com/HuyAms/awesome-node-boilerplate
Objects Making Objects
Published: 2019-08-12 04:06:45

In this post, I'll be giving a little info on Prototypal Inheritance in JavaScript. Since it's a defining feature of the language, it's kind of important to understand. The examples given here will be kept simple, focusing more on overall concepts.


#Constructor Functions
![](https://thepracticaldev.s3.amazonaws.com/i/7dunpj9vqbpx3evucey6.png)
Using a Constructor is probably the most common way of taking advantage of Prototypal Inheritance. In this case, new instances of objects get created using a Constructor, which passes on its Properties to the new instance.


This example uses a pseudoclassical instantiation pattern. It's not the only way to do this same thing, but the concept is the same for functional and class instantiations. 
![](https://thepracticaldev.s3.amazonaws.com/i/rktoobkgpgpwnyhgusk3.png)
Because of inheritance, if we tried to access a property or method  that "bobject" doesn't contain, the lookup gets delegated to "bobject"'s prototype(the object that created "bobject"), in this case, the constructor function "Bob". If "Bob" didn't have the property or method we were looking for, the lookup would get delegated to "Bob"'s prototype, and so on...until the chain ended with finding what we were looking for, or with "null"(which would make the lookup fail). 
This delegation has nothing to do with instantiation pattern and constructor functions aren't the only way to take advantage of inheritance.

#Object Concatenation

Yes, concatenation isn't just for strings and arrays! It's possible to concatenate objects using "Object.assign()". 
![](https://thepracticaldev.s3.amazonaws.com/i/jj4ht83m6m9ch31jxjb6.png)

As you can see in this example, our newly created object, "bobCat" contains the properties and methods of the objects that created it. Unlike our other example, this one doesn't assign a "constructor"(other than the global Object) to "bobCat". 

#Closure

![](https://thepracticaldev.s3.amazonaws.com/i/1zmmwh87hvywfjcuvpya.png)
It might not seem obvious at first, but using closures is actually a form of inheritance. Since closures are created by a function that is referencing something outside of its own scope, any lookup for that reference will be delegated to the object containing the function!
![](https://thepracticaldev.s3.amazonaws.com/i/8pmsk9fagkdm0eptur8t.png)

In conclusion, Prototypal Inheritance is a key feature of JavaScript and should be treated accordingly!

while (life.left.length > 0) { 
life.do = coding(); 
}
How do I improve coding interview question? 
Tags: javascript, webdev, career, help
Published: 2019-08-12 03:05:12

I'm preparing for my first FrontEnd Web Developer job, I had practiced my JavaScript skills by building many small and few larger projects and I just fell confident about it but when it comes to coding challenges types of problems I still fell totally blank on how to solve it :( 

Any way how can I get good on such type of problems?


PS: I'm from non science background but I'm learning basic concept of Algo & DS
[my portfolio](http://shubhamkr.me)
Big O Notation
Published: 2019-08-12 02:56:00

Time complexity in computer science is the amount of time it takes for a machine to process an algorithm. Specifically we are interested in how processing time grows in relation to input size. Because processing time can differ for varying inputs of the same size, time complexity notation is factored considering a worst-case scenario. Since this can involve some very complicated mathematical computations, we use Big O notation as a shorthand for various levels of time complexity. Let's take a look at some of the common types of complexity we expect to see in programming, from best to worse performance.

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

###Constant Time O(1)###
Constant Time means that no matter what the input size, the time it takes for the algorithm to run will remain the same. A familiar example of a constant time algorithm is looking up a value in an array at a known index. 

###Logarithmic Time O(log n)###
Logarithmic Time means that as the size of your input grows, the processing time grows, but at an ever-reducing rate. A good example of this is a binary search tree. The reason for this being that the search field is reduced by half at every search cycle.

###Linear Time O(n)###
Linear Time means that as the input size increases, the processing time increases at a consistent rate. Common occurrences of linear time algorithms would be any function that may potentially have to loop over the entire input. Many higher-order functions such as map, filter, and forEach are examples of linear time algorithms.  

###Quadratic Time O(n^2)###
Quadratic Time is when processing time increases at a rate which itself increases multiplicatively. Common examples of this are nesting a loop within a loop. Put in simpler terms, as input increases in size, processing time increases by the size of the input raised to some power.

###Exponential Time O(c^n)###
Exponential Time algorithms are when processing time increases exponentially as the size of the input grows. One common example of this is brute-force cracking of a password. This means that as input size grows, processing time increases by some constant raised to the power of the size of the input.

There are many other types of time complexity that we won't discuss here, but understanding these few examples is crucial in developing performant algorithms in your programs. We should all strive to improve the time complexity of our applications.
5 Handy Bash Tricks in 2 Minutes
Tags: beginners, productivity, bash, linux
Published: 2019-08-12 01:53:30

---
title: 5 Handy Bash Tricks in 2 Minutes
published: true
description: 👨‍💻⏱
tags: beginners, productivity, bash, linux
cover_image: https://thepracticaldev.s3.amazonaws.com/i/bc364cl0pt8wt2gg6to3.jpeg
---

This article should only take you a couple of minutes to read, and you'll walk away with a handful of the bash tricks I constantly use.

### 1. Make a directory and navigate to it

```sh
mkdir /foo/bar && cd $_
```

In bash, `$_` is a reference to the last parameter that was used. It can come in handy all over the place. Generally, the best use for `$_` is to avoid repeating yourself in cases like the above example.

### 2. Backup a file without typing it twice

```sh
cp /some/path/to/file.txt{,.bak}
```

This feature of bash is called [brace expansion](https://www.linuxjournal.com/content/bash-brace-expansion), it has a ton of useful applications. This is just one I sometimes use when I want to create a copy of a file quickly.

### 3. Backup every file in a folder

```sh
for file in * ; do cp "$file" "$file".bak; done
```

In this oneliner, we are taking advantage of bash's ability to loop over the files in a directory.

Frequently, I find myself using this syntax to avoid using multiple lines.

### 4. Find a command by its description

```sh
apropos "some description"
```

`apropos` is a command that looks through the commands on your machine for one that has a description like the one you provided.

It can be extremely useful when you remember what a command does, but not its name.

### 5. Repeat the last command with sudo

```sh
sudo !!
```

`!!` is a quick way to repeat the last command. I do this a ton.

Feel free to add your own useful bash tricks in the comments. 🤠
Why should you attend tech conferences? 
Tags: womenintech, womenwhocode, technology, dddmelb
Published: 2019-08-12 00:41:55

---
title: Why should you attend tech conferences? 
published: true
description: tech conference, Melbourne tech
tags: #womenintech #WomenWhoCode #technology #DDDMelb
cover_image: https://thepracticaldev.s3.amazonaws.com/i/118n0d68a5kyk6q4g610.jpg
---
Why should you attend tech conferences especially if you're starting out in the tech sphere? 
In a sentence, because they are fun and gets you high on sugar and you get to learn more in few hours than you ever could have and you get to meet some of the amazing people in the industry probably doing what you are aiming to do. 

If you need more convincing continue reading about my experience at #DDDMelb2019. 

Started the day with a wonderful talk by Josh Richards on his one way mission to Mars. The people selected for the mission had a range of very diverse background with variety of experiences. Really liked his message about how being diverse and having a variety of experiences makes one more adaptable, which means they would be helping people wherever they're.

The women who code Melbourne #applaudher panel discussion was again and uplifting talk which touched upon the topic of Impostor Syndrome and how it engulfs the best of us, and a pretty efficient way to deal with it is by giving yourself a pep talk like you would give your friend when they were going to do something they weren't comfortable about and ask what you want, you don't get what you don't ask for. 

Also attended workshop on modern authentication, got to see a demo of how facial recognition works, learnt about how to share content on IoT devices using content as a service model, addressed one of the most important topic of an Ethical AI and how we can use fast.AI for our own ML models.

Ended the day with an inspiring talk about Aaron Powell on his journey from being afraid to be on stage and struggling to read to now have spoken on all DDD across Australia multiple times, it all started with a thought of let me give it a shot, how hard could it be.

And if you need more convincing which you really shouldn't, the after party was pretty amazing! :)
How reduce() function really works
Tags: devjourney, javascript, beginners
Published: 2019-08-11 23:01:30

---
title: How reduce() function really works
published: true
description: 
tags: #devjourney #javascript #beginners
---

Hello! New person alert! This is my first post on here and I am super excited. 

Today, I will be explaining what the reduce() function really looks like under the hood so beginners in Javascript can truly understand how it works. It's not enough to just use it, I think it's also cool understanding how it works.

First of all, the reduce() function is a higher-order function. HIGHER-ORDER FUNCTIONS are functions that take in other functions as parameters. It was introduced in ES2015 or ES6.

##WHAT DOES THE REDUCE() FUNCTION REALLY DO?
The reduce() function helps you turn an array of elements into a single value. In short, it sums up everything in an array. Cool, right? 😊


##HOW IT WORKS

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

That's some code on how reduce() works but now I will be showing you how it truly works under the hood.

Ready. Set. Go!

##Reduce() under the hood
![](https://thepracticaldev.s3.amazonaws.com/i/p4smdyrc817t86w0h8e0.png)

That is an expansion of the reduce() function.

Now, I will break it down into chunks for your own understanding as to how this came to be. It's simple math and in Javascript, it is called Augmented Addition/Sum.

##Breaking it into chunks
Remember we initialized accumulator to 0, it's the starting point of this entire code.

###To Add:
accumulator += myArrayToBeSumed which also means... accumulator = accumulator + myArrayToBeSumed. (+=) this is augmented sum/addition.

A quick breakdown: the value on the left is **accumulator** while the value on the right is **myArrayToBeSumed**
=> 0 += 2 also means 0 = 0 + 2 answer is 2. Accumulator is now 2.
=> 2 += 3, 3 is the next element in the array. Accumulator is now 5.
=> 5 += 4, accumulator is now 9.
=> 9 += 5, accumulator is now 14.
=> 14 += 6, accumulator is now 20.

Accumulator keeps adding everything in the array until it gets to the last element in the array then it stops.

P/S: accumulator is just a name chosen for my variable, it is not a keyword in Javascript.

Next post hopefully would be on using the reduce() function in real-life examples, not just numbers.

Hope with this, you can understand how reduce() works under the hood and why you are using it.  ♥️  ♥️  ♥️
2019 Goals — July Update
Tags: goals
Published: 2019-08-11 22:43:52

---
title: 2019 Goals — July Update
published: true
description: A progress update on my goals for 2019
tags: goals
cover_image: https://images.unsplash.com/photo-1563759553854-95ea771b8932?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1548&q=80
---

11 days into August, so I'm a bit late on my July update but better late than never! 😜


## Achievements

Here, I’ll share the goal followed by the related achievement of the month after the arrow.

### Intellectual
- Launch 2 projects on Product Hunt -> Made a lot of progress on new project 👀

The majority of July was spent working on my next project. It's a virtual coworking community for developers.

My goal is to launch the MVP by the end of August. Examining where I'm at right now, I should be on target to achieve this. The main task for this month will be building the landing page and setting up a sign up list. 

Keep an eye out for more info next month on [Twitter](https://twitter.com/jsjoeio)! 

### Financial 

- Start investing -> Rolled old 401K into Roth IRA 

My previous employer had a 401K match. I was able to transfer that money (about $4K) into a Roth IRA with Vanguard. Even though I haven't made a "huge" jump into investing, it feels like a step because now I have the Roth IRA, along with an old Simple IRA from another previous employer all in the same account. It feels consolidated, which makes me happy.

I'm hoping with my new job at Echobind, I can easily set up a way to contribute to the Vanguard Roth IRA each month. Once that's set up, then I'll feel like I've fully achieved this goal. 

- Start investing -> New Split Paycheck System

When I started my first full-time job, I set up an automatic paycheck split so that 15% of every paycheck went directly into my savings. This system has served me well in terms of saving money.

I've been reading a lot about financial independence, retiring early, etc. and one of the tips I remembered was to continue living the way you were even after you receive a pay raise. 

Since I started a new job on July 1st with a significant pay raise, I thought to increase the split of my paycheck. This month, I'm experimenting with a high percentage (50%), meaning 50% of each paycheck (I get paid 2x/month) will go into savings and 50% will go into my checkings. 

I'm fortunate enough to make enough to be able to do this and still be able to pay all the bills (the main ones being rent/food). If this proves to be sustainable, it should help me hit this $36K saving goal by the end of the year. 


## Updates

Not much from the update side. I am reading a book right now called "Atomic Habits" and one of the points the other makes is to focus on systems/habits rather than goals. 

Therefore, I may reevaluate the goals I set this year and see if I can reword them to focus more on systems/habits rather than goals. I want to read more of the book before I make that decision but thought it was a relevant piece to share here.

That's all folks! Until next month!

### 
[Photo by John Fowler on Unsplash]
Where can I start with NodeJS? Show me da wae!
Tags: node, explainlikeimfive, productivity
Published: 2019-08-11 22:42:58

Hey I have a question. Or some. 🤔

IDK if I’m actually going to get a conversation going here but it’s worth a try.


There are so many open source projects out there all doing so many beautiful things and they are being built by... Developers. Engineers. Etc.

I’m talking mostly about nodejs stuff. 

There seems to be a form of layers that all projects follow.

Projects like React, create-react-app, Apollo, Prisma, and not just using them but building them.

Projects that you build to be used by others.

Modularizations... Unit testings... Authentications... HOCs... config files... database this and that... handling files... I mean I could go on and on...

This all seems like rocket science with noodles(node_modules) as a beginner frontend developer who builds components with ReactJS. Who Uses firebase cause it’s so damn easy. Who maybe can build a hello world express server...

I know you don’t have to know everything.

My point is...

For all you awesome devs who work or are getting into backend development and building API’s and contributing to the open source community.

Where did you start?

If you could go back in time... Where would you start?

How long did it take (you) to be able to look at a project for the first time and start thinking about how you can contribute?

Sorry for the weird grammar. 🤪

Thanks for any input. 😇