teleren/devto huggingface dataset:
LeetCode in Ruby: 70. Climbing Stairs
Tags: leetcode, ruby, dynamicprogramming
Published: 2019-02-26 03:06:01

---
title: LeetCode in Ruby: 70. Climbing Stairs
published: true
description: Solution + explanation for Problem 70
tags: #leetcode, #ruby, #dynamicprogramming
series: LeetCode in Ruby
---

# Dynamic Programming

```ruby
def climb_stairs(n)
  p = 1
  q = 1

  (n - 1).times do
    temp = q
    q += p
    p = temp
  end

  q
end
```

This problem can be solved by using dynamic programming. We define f(n) as the number of ways you climb to the nth step from:

1. one step from `n-1`th step
1. two steps from `n-2`th step

Therefore, `f(n) = f(n-1) + f(n-2)`, which is the same as the Fibonacci sequence. We have two bases cases: `f(1) = 1` and `f(2) = 2`. The lines 4 and 5 are the first two numbers of the Fibonacci sequence. To get the nth number, we add up the numbers up to nth number. Here, we optimize the performance the just storing the previous two numbers.

_Time complexity_: `O(n)`

_Space complexity_: `O(1)`
Quick Tip: Managing event listeners with bound callbacks
Tags: javascript, performance, memory, tips
Published: 2019-02-26 01:50:19

---
title: Quick Tip: Managing event listeners with bound callbacks
published: true
description: You should always remove your event listeners after use, but it can be difficult to do so when using bind on a callback 
tags: javascript, performance, memory, tips
cover_image: https://coresites-cdn.factorymedia.com/mpora_new/wp-content/uploads/2016/01/Arty-knot-Photo-iStock-com.jpg
---

## Always remove your event listeners

It's important to remember to remove event listeners after you're done using them. This is good for performance and allows code to be garbage collected and removed from memory when no longer needed. 

### The problem

Consider some code like 

```thing.addEventListener('click', this.func.bind(this))```

Unfortunately, you cannot remove the event listener in the same manner. I.E:


```thing.removeEventListener('click', this.func.bind(this))```

Won't work at all. ** sad trombbone **

## Why doesn't this work?

This doesn't work because every time bind is used, [a new function is created](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind)!

This means that when it's time to call ``removeEventListener``, the callback function no longer matches the original that was used in ``addEventListener`` (anonymous functions will behave this way too).

## The fix

```js
const func = doStuff.bind(this);
thing.addEventListener(func);

/** later on **/

thing.removeEventListener(func);

```
Organized, clean approach to SCSS variables
Tags: css, scss
Published: 2019-02-26 00:48:42

I am a lazy man with a lot on my plate. I like clarity and efficiency, and I dislike memorizing things. 

There's an approach to SCSS variables I use in all my projects -- an approach which works with my mind's habits and saves me typing. 

An example of the technique, applied:

    p {
      color: c(body-text);
    }

The data structure and SCSS function making this possible:

    // the data map
    $colors: (
      body-text: rgba(#000, 0.9),
      body-link: #33c,
      // etc.
    )

    // the function
    @function c($the-color) {
      @return map-get($colors, $the-color);
    }

I use this with colors `c(color)`, with breakpoints `bp(phone-landscape)`, with "magic numbers" - `n(w-desktop-max-width)` etc.

DRYs the project, keeps the namespace clean and makes it easy to look stuff up.

Happy coding and let me know if you use similar tiny time-savers!
After you start a new job as a software developer/engineer, how long it took before you feel you are very productive? 
Tags: discuss, career, webdev
Published: 2019-02-26 00:29:39

---
title: After you start a new job as a software developer/engineer, how long it took before you feel you are very productive? 
published: true
tags: discuss, career, webdev
---

First questions is your personal experience, how long did you feel it took you before you are ramped up. (Since for most of us, we join a company with often large existing code base, of course, some product, the code base is simple, but some can be highly complex.)

Also what are your expectations for when you hire software developers/engineers? How quickly do you expect them to be ramped up? For junior vs senior developers.
ReasonML Warning: Unimplemented primitive used
Tags: reason, functional, errors
Published: 2019-02-26 00:21:37

---
title: "ReasonML Warning: Unimplemented primitive used"
published: true
description: Compiler error writing reason code.
tags: reason, fp, error
---

If you run into the issue `Warning: Unimplemented primitive used:put` or whatever `put` is for you, it's probably because you forgot to include the `[@bs.module "<library>"]` or any other FFI before your wrapping.

For example:

```
external putJson: (string, Js.Json.t) => request = "put";
```

which gave me the error above ^. The fix?

```
[@bs.module "superagent"] external putJson: (string, Js.Json.t) => request = "put";
```

At least that was the case for me. (:
Who's looking for open source contributors? (Feb 25th edition)
Tags: discuss, opensource, contributorswanted
Published: 2019-02-25 23:39:38

---
title: Who's looking for open source contributors? (Feb 25th edition)
published: true
description: 
tags: discuss, opensource, contributorswanted
---

Find something to work on or promote your project here.

Please shamelessly promote your project. Everyone who posted in previous weeks is welcome back this week, as always. 😄

Happy coding!
New Feature: Organization Notifications!
Tags: changelog, meta
Published: 2019-02-25 23:26:33

---
title: New Feature: Organization Notifications!
published: true
description: Organizations now receive notifications for new comments, reactions, and followers!
tags: changelog, meta
---

Organizations can now receive notifications! 

If you are a member of an organization, you will be notified of any new comments or reactions to your organization's posts, as well as any new followers to your organization. You can find them in your [notifications page](https://dev.to/notifications).

Nitty gritty details and the technical implementation can be found in the pull request:

{% github https://github.com/thepracticaldev/dev.to/pull/1762 %}

Happy coding!
What are Your Tips for Successful Pair Programming Sessions?
Tags: discuss, webdev, productivity
Published: 2019-02-25 22:56:58

---
title: What are Your Tips for Successful Pair Programming Sessions?
published: true
description: I'm putting together a piece on tips pair programming success. Do you pair program at your company? What have you learned along the way that others could benefit from?
tags: discuss, webdev, productivity
---
![Pair programming](https://thepracticaldev.s3.amazonaws.com/i/r6y8vn9pb1ijuz0qdb12.jpg)

There are so many thoughts and opinions on pair programming out there. But for many companies, pairing is part of the culture and will be around long-term. If you work for one of these companies, what is it about pair programming that makes it so successful? If you pair program, what tips do you have for someone who may be new to it or may feel uncomfortable with the idea?

I'd love to quote your experience in an upcoming blog post on the topic. Leave your tips below to share with others, and I'll get in touch to see if you're up for being quoted (with a link to your social/company name!)
Monocle Reader - Beta Preview
Tags: rss, newsreader, showdev, webdev
Published: 2019-02-25 22:25:38

---
title: Monocle Reader - Beta Preview
published: true
description: Serious progress, totally happy with how it's going!
tags: rss, newsreader, showdev, webdev
cover_image: https://backgroundcheckall.com/wp-content/uploads/2017/12/the-matrix-background.png
---

__Websites you follow, at a glance__
_Twitter, YouTube, blogs and feeds, all in one place._

![Shut up and take my money meme](http://www.perusmart.com/wp-content/uploads/2015/07/shut_up_and_take_my_money_by_lolikips-d34yx16.png)

You can put your wallet down now, that's just what the new Monocle motto will be.

Okay so, I've been coding a lot of the newer features to be implemented in the Beta release next month and also thinking about marketing, pricing strategies and such but right now I just wanted to take a little break and show a bit of the progress and maybe hope to get some hype before the big launch.

The general look and feel is way more Material, simpler, nicer and content-focused.
![General Preview](https://i.imgur.com/4p0sj3u.jpg)

There will also be some handy folder view screens, so you can view all of a folders content in one page, instead of having to click on each feed individually. There's this ultra compact horizontal scrolling option:
![Horizontal FolderView Preview](https://media.giphy.com/media/NTgjvhM8erSxpJgI4k/giphy.gif)

Or if you're more into verticalicious scrolling, there'll be that option too:
![Vertical FolderView Preview](https://i.imgur.com/yamaPae.jpg)

Probably the biggest feature will be the addition of the Saved (or Read Later) section, where you can save sites to, you guessed it, read later. Of course this comes along with a nice browser extension (Chrome & Firefox) to save those links that you get when you're in the middle of something and can't read inmediately.
![Read Later Browser Extension](https://media.giphy.com/media/3ODiSd41Fms8eRqZ5i/giphy.gif)

That's all for now, but there's many more in the workings, and now that I've quit my job, I can dedicate most of my time to developing Monocle! (I still have to eat so there's freelance clients too)

If you're curious and can't wait, you can already use the Alpha version @ [monoclereader.com](https://monoclereader.com/)

Feedback appreciated!
GCP: Managing IAM Access Control Across Projects -- The Simpler Version
Tags: gcp, authorization, iam
Published: 2020-05-06 21:33:16

---
title: GCP: Managing IAM Access Control Across Projects -- The Simpler Version
published: true
date: 2019-02-25 22:20:00 UTC
tags: gcp,authorization,iam
canonical_url: 
---

GCP resources are organized into projects -- all resource IDs and IAMprinciples are grouped under a project ID. This means that by default rolesassigned to a principle (e.g. a user or service account) are scoped only toproject resources. This can be tricky if say your images are in one project'sstorage bucket and your app is running in another

If you want to provide a service principle in one project access to resourcesin another , the approach is not obvious, nor is it well documented.

Below we'll talk about the most direct way, which works for projects that are not part of an organization. This is good for projects managed by different teams or GCP projects that are part of a personal account (without gsuite)

## Use Case -- Allow an Outside App Engine App Access Build Status

For this example, the app engine app running in `${SOURCE_PROJECT_ID}` needs to access build status in `${GOOGLE_CLOUD_PROJECT}`.

This can easily be done using the cloud shell activated for the project id = `${GOOGLE_CLOUD_PROJECT}`

### Grant a Role to An Outside Service Principle

```
gcloud projects add-iam-policy-binding $GOOGLE\_CLOUD\_PROJECT \--member=serviceAccount:${SOURCE\_PROJECT\_ID}@appspot.gserviceaccount.com \--role=roles/cloudbuild.builds.viewer \
```

## How Does This Work?

GCP Access control for projects is an ACL mapping members -> roles. The abovecommand refers directly to the app engine service account(`PROJECT_ID@appspot.gserviceaccount.com`) in the outside account, andattaches the `cloudbuild.builds.viewer` role

e.g. You can view the entire project-level ACL this way

```
gcloud projects get-iam-policy `${GOOGLE\_CLOUD\_PROJECT}`bindings:- members: - serviceAccount:XXXXX@cloudbuild.gserviceaccount.com - serviceAccount:local-dev@XXXXXX.iam.gserviceaccount.com role: roles/appengine.appAdmin- members: - serviceAccount:XXXXXX@cloudbuild.gserviceaccount.com
```

## Won't this Get Messy?

Any sane person can see that this doesn't scale well. It can work if the deps are often one way, but once you get two-way dependences it would be a disaster. At that point look into [creating an organization and manaing the ACL at the organization level](https://cloud.google.com/resource-manager/docs/access-control-org)

## How is this Better or Worse Than AWS IAM?

There are pros and cons to project-based resourcing. On the plus side, aproject works like a c++ namespace so all resources are implicitly granted toprinciples in the same project. AWS policies contain an explicit resourcepattern match, which makes every grant more complex.

Security is also improved by default since deny is the default among projects.

## How About Larger Projects?

**tl;dr** , don't put all of your resources in one project, and when yourprojects start having two-way deps, think about moving those into a starpattern and using a GCP organization for the ACL
First Posts Are Always Tests
Published: 2019-02-25 21:03:31

---
title: First Posts Are Always Tests
published: true
description: 
tags: 
---

I think everyone wants to see how it looks before they commit to writing something really long. Like, right now I see a tag indicating if this post is published. What happens if I save? It looks like that saved the post in a private manner, but still gave it a URL to point to. Neat.

I've been learning Vue and some other JS things recently, and as I was pestering people on that forum I realized a lot of my questions come in the form of, "I didn't know if this approach sucked, so I tried it, and I still don't know." I'd ask some questions, then hack away, and end up answering the questions before other people responded, then the forum post got awkward.

So I don't have an idea for a real topic, but figured a blog format is convenient for typing out my thoughts as I poke around? Maybe I'll post more, or maybe I'll forget dev.to is here. Time will tell.
Angular 9|8|7 NgIf, Else, Then – Work Like a Pro
Tags: angular, angular987, ngif, else
Published: 2020-01-31 21:54:21

---
title: Angular 9|8|7 NgIf, Else, Then – Work Like a Pro
published: true
tags: Angular ,Angular 9|8|7, NgIf, Else
canonical_url: https://www.positronx.io/angular-7-ngif-else-then-work-like-a-pro/
---

The post [Angular 7 NgIf, Else, Then – Work Like a Pro](https://www.positronx.io/angular-7-ngif-else-then-work-like-a-pro/) appeared first on [positronX.io](https://www.positronx.io).

**Angular 7 Ngif Else** is the not-so-simple version of conditional if else in Angular. **Angular 7 ngif else** allows you to switch between content from a conditional expression. As we have already mentioned, it is not as simple as you would assume. Angular ngif else is a far better version of regular if else since it comes with many helpful syntaxes. Asynchronous objects also make Angular ngif else look better.

Let’s take a closer look at Angular ngif else and learn how we can make better use of this in Angular apps.

[Click here to read more](https://www.positronx.io/angular-7-ngif-else-then-work-like-a-pro/)
IBM has released Unit Testing for Mainframes.
Tags: development, unittest, news
Published: 2019-02-25 18:50:26

---
title: IBM has released Unit Testing for Mainframes.
published: true
description: IBM recent announced that is has created a Unit Testing tool for Mainframe computers. This is an amazing step for legacy support within modern development practices.
tags: development, unit-test, news
cover_image: https://thepracticaldev.s3.amazonaws.com/i/y9dn8wpt0vr65fylyfsj.jpg
---

Originally posted on [my personal blog](https://blog.davidjeddy.com/2019/02/25/ibm-has-released-unit-testing-for-mainframes/).

<!-- wp:paragraph -->
<p>IBM recent announced that is has created a Unit Testing tool for Mainframe computers. Remember those big, bulky, COBOL / FORTRAN machines running UNIX you read about in high school textbooks? Those beasts are STILL part of every monetary transaction even now. Recently the programs running on those machines now get to benefit from the unit testing process.</p>
<!-- /wp:paragraph -->

<!-- wp:core-embed/wordpress {"url":"https://devops.com/ibm-adds-automated-testing-tool-for-mainframe-to-devops-portfolio/","type":"wp-embed","providerNameSlug":"devops-com","className":""} -->
<figure class="wp-block-embed-wordpress wp-block-embed is-type-wp-embed is-provider-devops-com"><div class="wp-block-embed__wrapper">
https://devops.com/ibm-adds-automated-testing-tool-for-mainframe-to-devops-portfolio/
</div></figure>
<!-- /wp:core-embed/wordpress -->

<!-- wp:paragraph -->
<p>This is great. I was very intrigued by the article and the concept that unit testing has reached into the once thought of 'not possible' environment of mainframes. Maybe one day soon banks will be able to process cheques faster than 5 days.</p>
<!-- /wp:paragraph -->
Passing parameters to arrow function in react js
Tags: react, reactnative, android, javascript
Published: 2019-02-25 18:17:41

---
title: Passing parameters to arrow function in react js
published: true
description: Passing parameters to arrow function in react js
tags: #react #reactnative #android #javascript
---

--
source : <a href="https://www.skptricks.com/2019/02/passing-parameters-to-arrow-function-in-react-js.html" > Passing parameters to arrow function in react js</a>
--

This tutorial explains how to pass parameters to arrow function in react js application. Implementation of passing parameters to arrow function is bit different in react application. Lets see the below example that helps to build more understanding on arrow function.

Passing single parameter in arrow function :
oneParameter = a => e => {
    alert(a);
  };

Passing two parameters in arrow function :
twoParameter = (a, b) => e => {
    alert(a + b);
  };

<img src="https://4.bp.blogspot.com/-atlN9jHQeJg/XGrO6q7EZOI/AAAAAAAACdE/a82lDyexKIUrKbY-e06aoL5KRImD7oWWQCLcBGAs/s400/arrow.png" />
How to custom a create context menu in html, css and javascript
Tags: react, reactnative, android, javascript
Published: 2019-02-25 18:16:12

---
title: How to custom a create context menu in html, css and javascript
published: true
description: How to custom a create context menu in html, css and javascript
tags: #react #reactnative #android #javascript
---

--
source : <a href="https://www.skptricks.com/2019/02/how-to-custom-create-context-menu-in-html-css-javascript.html" >How to custom a create context menu in html, css and javascript </a>
-----

This tutorial explains how to custom a create context menu in html, css and javascript. A context menu is a menu in a GUI that appears upon user interaction, such as a right-click mouse operation. A context menu offers a limited set of choices that are available in the current state, or context, of the operating system or application. Usually the available choices are actions related to the selected object.

<img src="https://3.bp.blogspot.com/-OAnIQ5bMMls/XGqLWEOpoLI/AAAAAAAACc4/grgagH3DRV8o6BslC2RnfQ1rZVmisK2hQCLcBGAs/s640/context.png" />


Download Link : 
<a href="https://www.skptricks.com/2019/02/how-to-custom-create-context-menu-in-html-css-javascript.html" >How to custom a create context menu in html, css and javascript </a>
React Native Sketch Canvas Android or IOS Example
Tags: react, reactnative, android, javascript
Published: 2019-02-25 18:14:19

---
title: React Native Sketch Canvas Android or IOS Example
published: true
description: React Native Sketch Canvas Android or IOS Example
tags: #react #reactnative #android #javascript
---

-------
source : <a href="https://www.skptricks.com/2019/02/react-native-sketch-canvas-android-or-ios-example.html" > React Native Sketch Canvas Android or IOS Example</a>
------

This tutorial explains how to design sketch and canvas in react native application. This is very helpful for drawing, designing layout and capturing the user signature in android or iOS application with help of react native application. This React Native component for drawing by touching support on both iOS and Android.

<img src="https://1.bp.blogspot.com/-PfAIAEwTveQ/XGaZ9q2E67I/AAAAAAAACck/Q6gBHr_yoNMhmoYAbxLcsUzLjNztx-evgCLcBGAs/s640/canvas.png" />

Lets see the below features of react-native-sketch-canvas.
Support iOS and Android
Stroke thickness and color are changable while drawing.
Can undo strokes one by one.
Can serialize path data to JSON. So it can sync other devices or someone else and continue to edit.
Save drawing to a non-transparent image (png or jpg) or a transparent image (png only)
Use vector concept. So sketches won't be cropped in different sizes of canvas.
Support translucent colors and eraser.
Support drawing on an image (Thanks to diego-caceres-galvan)
High performance 
Can draw multiple canvases in the same screen.
Can draw multiple multiline text on canvas.

Download Link :
<a href="https://www.skptricks.com/2019/02/react-native-sketch-canvas-android-or-ios-example.html" > React Native Sketch Canvas Android or IOS Example</a>
How to Install React Native on MAC step by step
Tags: react, reactnative, android, javascript
Published: 2019-02-25 18:12:31

---
title: How to Install React Native on MAC step by step
published: true
description: How to Install React Native on MAC step by step
tags: #react #reactnative #android #javascript
---

----------
source : <a href="https://www.skptricks.com/2019/02/how-to-install-react-native-on-mac-step.html" >How to Install React Native on MAC step by step </a>
---------

React Native has fast become one of the hottest frameworks for building cross platform mobile apps. Based on JavaScript and Facebook’s React Library it focuses on performance and tight integration with the native platforms supports. With Facebook invested in the framework and React’s learn once, write anywhere philosophy, React has a bright future.React native is now doing what is impossible few years back but now its a complete game changer technique, which would soon change the development arena and any one can developer both android and iOS apps using single language.

<img src="https://4.bp.blogspot.com/-ndH5fokvD7I/XGENk7vZBnI/AAAAAAAACbc/ciaPLKKY84Ugy1BfrIbKoEbYkiYlghg6ACLcBGAs/s640/mac.png" />

Download Link :
<a href="https://www.skptricks.com/2019/02/how-to-install-react-native-on-mac-step.html" >How to Install React Native on MAC step by step </a>
Job Posting: Lead Developer (FE-Focus, React & Node)
Tags: career, jobs
Published: 2019-02-25 17:22:25

---
title: Job Posting: Lead Developer (FE-Focus, React & Node)
published: true
description: Hilton Digital Enterprise Platforms & Products is looking for a Lead Developer with background in Frontend and some experience with React & Node. 
tags: career, careers, jobs
---

The Dreaming Team here at Hilton Digital Enterprise Platforms & Products is looking for a full-time Lead Developer with a focus on Frontend stacks: primarily React -- some Node experience necessary to consume our backend.

If you're interested, please check out this [link to the job posting](https://jobs.hilton.com/job/Lead-Front-end-Developer/J3V3SK6940D4BG75YCP)