teleren/devto huggingface dataset:
S3 Bucket Policy - NotPrincipal and Lambda Functions
Tags: aws, iam, lambda, s3
Published: 2019-07-01 22:23:46

---
title: S3 Bucket Policy - NotPrincipal and Lambda Functions
description: Using NotPrincipal in S3 bucket policies with assumed roles.
date: '2017-09-24 9:00:00'
published: true
tags: aws,iam,lambda,s3
canonical_url: https://blog.neverendingqs.com/2017/09/24/aws-lambda-notprincipal.html
---

AWS S3 bucket policies have a handy `NotPrincipal` element that allows you restrict actions to specific principals. For example, the following allows you only allow deletes from two specified roles:

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "DenyObjectDeleteWithWhitelist",
            "Effect": "Deny",
            "NotPrincipal": {
                "AWS": [
                    "arn:aws:iam::123456789012:role/SuperRoleOne",
                    "arn:aws:iam::123456789012:role/SuperRoleTwo"
                ]
            },
            "Action": "s3:DeleteObject",
            "Resource": "arn:aws:s3:::mybucket/*"
        }
    ]
}
```

But what if you want to restrict it to an assumed role? While working on a [Serverless Framework](https://serverless.com/framework/) project, I wanted to open up a S3 bucket to allow deletes from a Lambda function (and only that Lambda function).

Surprisingly, the following S3 bucket policy didn’t work:

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "DenyObjectDeleteWithWhitelist",
            "Effect": "Deny",
            "NotPrincipal": {
                "AWS": [
                    "arn:aws:iam::123456789012:role/my-lambda-role"
                ]
            },
            "Action": "s3:DeleteObject",
            "Resource": "arn:aws:s3:::mybucket/*"
        }
    ]
}
```

With a bit of digging and troubleshooting, I realized that the Lambda function assumes the role you provide, and that assumed role must also be added to the S3 bucket policy:

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "DenyObjectDeleteWithWhitelist",
            "Effect": "Deny",
            "NotPrincipal": {
                "AWS": [
                    "arn:aws:iam::123456789012:role/my-lambda-role",
                    "arn:aws:sts::123456789012:assumed-role/my-lambda-role/my-lambda-function"
                ]
            },
            "Action": "s3:DeleteObject",
            "Resource": "arn:aws:s3:::mybucket/*"
        }
    ]
}
```

This will prevent any entity from deleting from the S3 bucket except for your Lambda function.

If this isn’t your exact scenario, and/or you’re looking for more details, check out [How to Restrict Amazon S3 Bucket Access to a Specific IAM Role](https://aws.amazon.com/blogs/security/how-to-restrict-amazon-s3-bucket-access-to-a-specific-iam-role/) by AWS.
Programmatically get current git branch
Tags: git, bash, branch, ps1
Published: 2017-09-24 07:28:19

---
title: Programmatically get current git branch
published: true
description: Bye bye sed...
tags: git, bash, branch, ps1
---

Nice and easy. Works with git 1.6.3 and higher.

```bash
$ git rev-parse --abbrev-ref HEAD
master
```
From writing code in Ink & a Diary to organising the biggest Laravel meetup
Tags: inspiration
Published: 2017-09-24 06:00:27

---
title: From writing code in Ink & a Diary to organising the biggest Laravel meetup
published: true
description: Listen to the Laravel Podcast interview with Matt Stauffer where I talk about how I became a developer & challenges and all
tags: inspiration
---

![](https://thepracticaldev.s3.amazonaws.com/i/u3aeaykkgj1b6qqsrj4h.jpg)

In this podcast I talk about how I became a developer and the challenges I faced along the way. 

I also talk about how [I](https://neoighodaro.com) started the [Laravel Nigeria](https://laravelnigeria.com) meetup from zero to 350 RSVP and 150 on the waitlist; essentially making it [a meetup bigger than most conferences](https://dev.to/neo/laravel-nigeria--when-meetups-turn-into-conferences).

Go ahead listen up and please tell me what you think and if you were inspired.

Link to Podcast: [Laravel Podcast S3 Ep3](http://www.laravelpodcast.com/7b180dae)
Looking for Angular 2/4 Mentor
Tags: angular, material, html, scss
Published: 2017-09-24 04:03:58

---
title: "Looking for Angular 2/4 Mentor"
published: true
description: Hi awesome Dev community,I have started learning front end development recently. I need angular mentor to guide me on my side project. Thanks in advance for the reply.
tags: #angular #Material #HTML #scss
---
Dealing with command not found on linux/osx
Tags: bash, hash, linux, osx
Published: 2017-09-24 02:30:44

---
title: Dealing with command not found on linux/osx
published: true
description: Notes on shell PATH and hash command to find command to execute
tags: bash, hash, linux, osx
---

Most of us who familiar with linux or osx already knew the `PATH` environment variable that being used by shell program to find the where is the command we type. Every time we type command such as `virtualemv` and got error like:-

```
bash: virtualemv: command not found
```

We will check the `PATH` properly set. But with all the environment manager for different kind of language we use - rbenv, rvm, pyenv, conda, nix etc, they all append or prepend some paths to the `PATH` variable to make their magic work. And it all got messy after a while.

When we're not sure where certain command come from, usually we'll use the `which` command:-

```
which virtualenv
/Users/kamal/Library/Python/3.6/bin/virtualenv
```

The problem with `which` is that it's an external program, it only look for command within the `PATH`, it's not really a representative of what the shell will actually execute. The built-in shell command `type` or `hash` will be more accurate to report what command actually executed when you type the command in your shell.

Sometimes you got a mysterious `command not found` even `which` or `type` return a path to the command. This could be because the command has been pointed to a new executable but the shell internal hash still pointing to the old one. If using `bash`, you can type `bash -r` to rehash all the commands cache.

More info on this [Stackoverflow question](https://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script).
What are the best tech conferences you attend?
Tags: discuss, conferences, events
Published: 2017-09-23 23:46:44

---
title: What are the best tech conferences you attend?
published: true
description: 
tags: discuss, conferences, events
cover_image: https://thepracticaldev.s3.amazonaws.com/i/2nvp7tsmwq1mjulp0i9i.jpg
---

* Which conferences do you attend?
* Where are they held?
* What makes them the best? 
* What do you like about them?
Remember to click to the second page of search results
Tags: research, tips
Published: 2017-09-23 23:20:37

---
title: Remember to click to the second page of search results
published: true
description: Google and other discovery tools, like, say GitHub's internal search, try really hard to give you the thing you are looking for, and they are usually pretty good about it. But pretty good is where that ends. These engines rely on the same faulty metrics we try to remind people are faulty. GitHub stars are a very very very loose indicator of where to put your attention, and no metrics, however sophisticated, can give you the whole picture. Sometimes you just have to dig deeper.
tags: research, tips
cover_image: http://s3.amazonaws.com/digitaltrends-uploads-prod/2014/11/google-search.jpg
---

Google and other discovery tools, like, say GitHub's internal search, try really hard to give you the thing you are looking for, and they are usually pretty good about it. But pretty good is where that ends. These engines rely on the same faulty metrics we try to remind people are faulty. GitHub stars are a very very very loose indicator of where to put your attention, and no metrics, however sophisticated, can give you the whole picture. Sometimes you just have to dig deeper.

There are absolutely gems on the second, third, millionth page of Google results. It's a company that has been on a two-decade-long mission to get us to trust the first page. I just want to remind you, that you should keep using your human brain, consider doing ten minutes of deeper research when you might have otherwise turned away after a minute.

If you don't keep your research skills sharp, you become much more susceptible to convincing yourself that the thing you are looking for does not exist. This causes unnecessary reinvention and can contribute to "not-invented-here" syndrome out of good intentions. There is a lot out there. Train yourself to always look deeper before turning away in haste.

Happy coding. â¤ï¸
Unit Test Naming Convention
Tags: cleancode, unittest, namingconvention
Published: 2018-04-02 20:13:39

---
title: "Unit Test Naming Convention"
published: true
tags: Clean Code,Unit Test,Naming Convention
canonical_url: https://www.matheus.ro/2017/09/24/unit-test-naming-convention/
---


Naming classes, methods, variables are hard, perhaps one of the most difficult things in programming.

> There are only two hard things in Computer Science: cache invalidation and&nbsp; **naming things**. — Phil&nbsp;Karlton

I’m recently reading the book The Art Of Unit Testing, by Roy Osherove, an excellent book on how to develop sustainable, readable and reliable unit tests. Highly recommended to any developer who wanted to start learning about unit testing and delving deeper into the subject.

In one of the chapters, the author give some tips on how to naming unit tests to make them more readable and improve maintenance by other developers. From this reading, I decided to make this post to talk about naming conventions for unit tests, I’m going to talk about the naming convention from the book and two other approaches.

[Continue Reading...](https://www.matheus.ro/2017/09/24/unit-test-naming-convention/)

Original posted in [Unit Test Naming Convention](https://www.matheus.ro/2017/09/24/unit-test-naming-convention/)
My Take on Python Version 2 vs 3
Tags: python3, python2
Published: 2017-10-15 00:11:43

---
title: "My Take on Python Version 2 vs 3"
published: true
tags: python3,python2
canonical_url: http://scriptingwithpython.com/my-take-on-python-version-2-vs-3/
cover_image: https://thepracticaldev.s3.amazonaws.com/i/nipwuhn1vnoqydapbnde.png
description: It's a huge point of conversation.
---

It's a huge point of conversation.

The internet has been debating the merits of Python 2 vs Python 3 for years now. I am sure the Python foundation would love for everyone to have switched entirely to Python 3 by now. There are reasons to migrate to it and, at least some feel, reasons to stay on 2.7.

I'll summarize the differences then give my own opinionated take on the whole thing. (Hint: I think everyone should be using Python 3)

## Python 2.7

Python 2.7.13, the most recent version of the 2.x series, came out way back in 2010.

### Problems with Python 2.7

No new features have been introduced since that time. The Foundation releases bug fixes but new functionality will only be added to Python 3.

## Python 3.x

### Pros

- Iterators, generators
  - Many lists that would have been in memory lists with 2.7 are generators in Python 3. This make high memory functions much more efficient. There are some disadvantages but I won't go into detail here.
- True UTF8 support - all strings are _utf8_ by default (Huge win!)
- New features will be added to Python 3
- It is not 7 years since the last release

### Cons

- Some libraries have not yet been migrated over to support Python 3. This is a huge problem for some people that have code written to rely on these libraries. However, it is my opinion that if the library isn't popular enough to demand a Python 3 version then it may not be necessary. That or _get with the game people_.
  - I should note that it has been years since I ran into a library that I **wanted to use** that didn't work in Python 3.

## My Opinion

Use Python 3 unless you absolutely have to use Python 2 for some reason. Python 3 is faster and better supported. All of the solutions I share on [Scripting With Python](https://scriptingwithpython.com) are written with Python 3 first in mind. I may occasionally test them with Python 2 but I won't guarantee it.
What is Set?
Tags: set, javascript, es2015
Published: 2017-09-23 18:46:44

---
title: What is Set?
published: true
description: What is Set in JavaScript, and why would you use it?
tags: set,js,es2015,javascript
---

_Originally posted on [my blog](http://blog.zacanger.com)._

Someone recently asked in a Slack channel how they might clean up the following code:


```javascript
getNames (contacts) {
  let contacts_set = []

  contacts.forEach((contact) => {
    let firstName = get(contact, 'contactInfo.firstName')
    let lastName = get(contact, 'contactInfo.lastName')
    let fullName = `${firstName} ${lastName}`

    if (contacts_set.includes(fullName)) {
      return
    } else {
      contacts_set.push(fullName)
    }

    set(this, 'contactsSet', contactsSet)
  })
}
```

(Note that the `get` and `set` going on here seemed to be Ember-specific, or a `_.get` type of thing. I don't know Ember, so I'm not positive.)

And I said, how about this?

```javascript
getNames: (contacts) =>
  [...new Set(
    contacts.map(({ contactInfo: { firstName, lastName }}) =>
      `${firstName} ${lastName}`))]
```

I like this version because it's concise, readable (to me, at least?), mutation-free, and declarative.

And then someone else asked:

> Can some one eli5 what `Set` is that's referenced above?

Which made me realise that a lot of folks still aren't using a lot of the nice new things from ES2015, so I explained a bit. Here's how I understand it.

Set is a new (in ES2015) iterable builtin (like Array, String, TypedArray). Map is also new in 2015. Set is to Array as Map is to Object, kinda.

For practical usage Set is basically Array but unique, and with different methods. `add`, `has`, `delete`, `size`, and some others. There's a lot more info [on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set).

You can pass `Set` an iterable, which is why the thing I have above works (because the `contacts.map...` thing inside `new Set()` results in an array).

In that case `Set` isn't being used for too much besides just the fact that it's `Set` (so it only holds unique values). Someone else pointed out in the same channel that maybe it's not the best idea if you have a very large collection, because then you're creating a whole extra collection in the process, which is totally true.

There's a bit more background [here](https://en.wikipedia.org/wiki/Set_(mathematics)) on what JS's `Set` is supposed to be kind of like.

And underneath it sorta looks like this:

```javascript
class Set {
  constructor () {
    this.storage = []
  }
  add (a) {
    if (!this.storage.includes(a)) {
      this.storage.push(a)
    }
  }
  has (a) {
    return this.storage.includes(a)
  }
  remove (a) {
    this.storage.splice(this.storage.indexOf(a), 1)
  }
}
```

That's a lot of stuff, but mostly you can think of `Set` as a thing that's like `Array` but it only holds unique things.

There's also a `WeakSet` which can only hold objects. I haven't really found a valid use case for `WeakSet` and `WeakMap` yet, personally.

`Set` turns out to be pretty useful. Definitely play around with it!
What do you wish you knew when starting your last gig?
Tags: programming, career, advice, discuss
Published: 2017-09-23 17:04:22

---
title: What do you wish you knew when starting your last gig?
published: true
description: 
tags: #programming #career #advice #discussion
---

There is a lot of content written from a dev manager's perspective on how to increase the chances of success for a new developer. 

I'd like to flip the script for a moment and ask what are the things you as a developer need to know to be successful when starting a new job/project? What are the things you want to accomplish day one? Week one?

I suspect the answers are not going to be "I wish I had more standards documents to read".
Check Name Availability for Multiple Services
Tags: showdev, python
Published: 2017-09-22 20:02:22

---
title: Check Name Availability for Multiple Services
published: true
description: A little tool that helps me check availability of names for my projects.
tags: showdev,python
---

Hello everyone! This is going to be a little bit different than most of my posts in that it's quite short. I was searching for names for an Open Source project that I have been working on and found it very frustrating that the names I was searching for would be available on one platform and unavailable on another. This led to a lot of time being sunk into searching for a good name which could have been spent programming.

To aid me in this quest I whipped up a tool called Avail which is run from the command line and outputs whether the name you give it is available on a variety of platforms including GitHub, Dockerhub, npm, Twitter, .com, URL shortener available, and more!

You can install it via `pip` like so:

`python -m pip install avail`

And then use it like this:

`avail [NAME]` or like this `python -m avail [NAME]`

The tool's [source code is hosted on GitHub](https://github.com/SethMichaelLarson/avail) and is licensed under Apache-2.0. Pull requests and suggestions for more services are welcome!

I hope this tool is able to help you out, if only to save a few minutes of searching.
What do you learn when learning programming? 
Tags: discuss, learning, career, programming
Published: 2017-09-23 04:35:13

---
title: What do you learn when learning programming? 
published: true
description: Beyond technical skills, what else programming taught you?
tags: discuss, learning, career, programming
---

Despite not considering myself a programmer, I've being using it in my daily work on ecological and geographical analysis. But now I am starting a different project: teaching kids "programming". Actually, the goal of the project is not the technical programming skills, but the broad concept that comes with programming (this is why programming in quotation marks).

By thinking about this "broad concept" of programming, I could realized that I learned much more then automate boring stuff with R or Python...

So, I decided to spread the question and hear from you: **Which skills do you learn when learning programming?**
Sentri.io — errors handling
Tags: errors, springboot, sentry
Published: 2018-03-03 08:52:15

---
title: "Sentri.io — errors handling"
published: true
tags: error-handling,spring-boot,sentry
canonical_url: 
---

Today I want to talk about one service I’ve discovered for myself last week. As you probably already got from article title it is [Sentry.io](https://sentry.io/). This open source project helps you to aggregate and monitor information regarding errors happening in your application. Beside opensource version, there is also hosted [paid](https://sentry.io/pricing/)(with free Hobbyist plan) version which supposes to be the&nbsp;same.

This service provides wide support for different programming languages like Java, C#, Elixir, Go, Javascript, Node, Perl, PHP, Python, etc. The integration process is super easy — you just need to add proper dependency into your project and provide a little bit of [configuration](https://docs.sentry.io/clients/java/config/)(at least access token), and you are ready to&nbsp;go.

In my case, it was a **Spring-Boot** application with **logback** logging framework. Both those technologies are supported by Sentry.io. So, I’ve placed **io.sentry:sentry-spring** and **io.sentry:sentry-logback** libraries into projects **Gradle** script. Then I’ve created a new project inside Sentry’s dashboard and generated a token for it. Next step — configuration inside the project. And that is something I don’t like about all that story. Maybe there is some way around but I can’t find it — so, I had to duplicate configuration twice — for logback and for spring-boot respectively. I’ve added **sentry.properties** file in project’s resource folder with **dsn** key inside and **sentry.dsn** key to my **application.yaml**. Also, the configuration of logback appenders was updated with the following block:

{% gist https://gist.github.com/gimlet2/ac8b0fa6f29078b8d62ec1cd233b6545.js %}

And as a final step additional beans for Spring to handle unhandled exceptions and provide additional request context(yes, a little bit of&nbsp; **Kotlin** ):

{% gist https://gist.github.com/gimlet2/e623ff19af8e5afc60424ba8e934181f.js %}

That’s it.

But there is much more than just aggregation of errors. Sentry provides useful report channels integrations. For example, it can send notifications by **email** or to S **lack** when there is a new type of error. Or notify you if same error happened more then 100 times per hour. All those rules are extremely flexible and can be configured with Sentry’s dashboard.

And there is integration with popular issue trackers like **Jira**. So, it will create a new bug ticket for each new error with stacktrace and all context it has. That should make it easier to fix&nbsp;them.

So far looks&nbsp;good.
Star Trek is back with Discovery
Tags: startrek, discovery
Published: 2020-02-03 22:31:33

---
title: Star Trek is back with Discovery
published: true
date: 2017-09-22 22:00:41 UTC
tags: StarTrek,discovery
canonical_url: https://www.funkysi1701.com/posts/star-trek-is-back-with-discovery-4lab
---

In [November 2015](https://dev.to/funkysi1701/star-trek-is-back-in-2017-1f2l-temp-slug-695667) it was announced that a new Star Trek series was going to be launched. It has been a long wait with multiple delays but Star Trek Discovery is finally here.

Star Trek Discovery launches in the US on 24th September and in the UK on 25th September.

<iframe src="https://www.youtube.com/embed/UoV3kc05Nwc?rel=0" width="560" height="315" frameborder="0" allowfullscreen="allowfullscreen"></iframe>

Lets have a look back how we got here.

Star Trek was created by Gene Roddenberry in the 1960s. He imagined a show where we would explore the galaxy while also exploring the human condition. He described it as a wagon train to the stars. However it was cancelled after 79 episodes and three seasons due to budget cuts and low viewers.

After cancellation its popularity boomed in reruns. In the mid 1970s an animated series was created. But demand for Star Trek continued until a new Star Trek show was commissioned called Phase Two.

In 1977 Star Wars came out, and the phase two idea was cancelled and turned into a movie. In 1979 we got Star Trek The Motion Picture. It went massively over budget and failed to really capture the Star Trek spirit.

A much cheaper sequel was created in 1982 Star Trek II: The Wrath of Khan with Roddenberry taking more of a back seat. A film widely considered to be one of the best trek films. Four more feature films starring the original cast were made.

However in 1987 Gene Roddenberry teamed up with Rick Berman and The Next Generation was created with a brand new cast. The series ran for seven seasons set roughly a century after the adventures of Kirk and Spock.

Popularity of Star Trek soured and this led Rick Berman to help create the spin off series Deep Space 9, Voyager and lastly Enterprise along with four feature films continuing the adventures of the TNG cast. When Enterprise was cancelled in 2005, Star Trek appeared to be dead after 18 years on TV.

However in 2009 movie creator JJ Abrams recast the classic crew for the big screen. The film was big on action, but took place in an alternative timeline allowing for familiar characters to have new adventures without interfering with events depicted in the TV shows.

Two sequels to this film have been produced and are bringing Star Trek back into popularity. This has given rise to Discovery. Star Trek is returning to the TV screen and it is going to be great.

![Discovery](https://storageaccountblog9f5d.blob.core.windows.net/blazor/wp-content/uploads/2017/09/gqojtfz1dhmxoiri7g8p.png?resize=662%2C372&ssl=1)