teleren/devto huggingface dataset:
Ruby: Getting Collect, Map, and Select Set Straight
Tags: ruby, beginners
Published: 2018-10-29 00:21:13

In one of my Flatiron coding challenges, I had to make an anagram tester that would test which words in an array were anagrams of the target word. Possible anagrams were passed to a `#match` method through an array. The `#match` method would then be called on an Anagram object and “collect” all the words that matched as an anagram. For example:

```ruby
listen = Anagram.new("listen")
listen.match(%w(enlists google inlets banana))
 
# => ["inlets"]
```

As I wanted to “collect” all the matches, at first I attempted to use `#collect` on the array.

```ruby
class Anagram
  attr_accessor :word
  
  def initialize(word)
    @word = word
    @letters = @word.split("").sort
  end
  
  # find anagram matches given an array of words
  def match(possible_anagrams)
    possible_anagrams.collect do |possible_anagram|
      @letters == possible_anagram.split("").sort
    end
  end
end
```

The problem with `#collect`, however, is that it collects *all of the return values produced by the code in the block*, so I was getting an array full of the values that were returned by the block's expression.

With `#collect`, the `listen.match(%w(enlists google inlets banana))` was returning `=> [false, false, true, false]`. What I really needed was to *get just the items in the array that made the code block return true*.

Guess who can do that? You guessed it: `#select`! Switching out `#collect` for `#select` solved the problem:

```ruby
class Anagram
  attr_accessor :word
  
  def initialize(word)
    @word = word
    @letters = @word.split("").sort
  end
  
  # find anagram matches given an array of words
  def match(possible_anagrams)
    possible_anagrams.select do |possible_anagram|
      @letters == possible_anagram.split("").sort
    end
  end
end
```

Now only the items that made the block true would be included in the returned array: => ["inlets"].

The difference is super clear if you check the Ruby documentation:

- [#collect](https://ruby-doc.org/core-2.2.0/Array.html#method-i-collect): “Creates a new array containing the values returned by the block.”
- [#select](https://ruby-doc.org/core-2.2.0/Array.html#method-i-select): “Returns a new array containing all elements of the array for which the given block returns a true value.”

Okay, so what about `#map`? It turns out #map is the exact same thing as #collect. A lot of times you’ll hear that certain functions do the same thing, but in truth there are actually slight differences. In the case of `#map` and `#collect`, though, they are identical down to the source code. Check for yourself by clicking the “click to toggle source” under the [#collect](https://ruby-doc.org/core-2.2.0/Array.html#method-i-collect) and [#map](https://ruby-doc.org/core-2.2.0/Array.html#method-i-map) documentation!

*Edit: Initial code refactored based on discussion comments below (thank you!)*
Haskell hack: find the function you need with Hoogle.
Tags: haskell, hoogle, hack
Published: 2018-10-28 20:43:18

---
title: Haskell hack: find the function you need with Hoogle.
published: true
description: Haskell surprises me again.
tags: haskell, hoogle, hack
---

Today I was solving a problem on Codewars. I somehow forgot about a very simple function that can check if an element is a member of a list.

![Alt searching for a Haskell function](https://thepracticaldev.s3.amazonaws.com/i/vj2vlzmkrr9kxfi6kvjq.png)

This of course led me to stackoverflow. You can find an interest hack there that was posted by [AtnNn](https://stackoverflow.com/users/243581/atnnn):

First find the type of the function you need.

To "Check if" means to return either True or False, a Bool.

So the function takes an Int, a list of Int (aka [Int]) and returns Bool:

Int -> [Int] -> Bool

Now ask [hoogle](https://www.haskell.org/hoogle/?hoogle=Int+-%3E+[Int]+-%3E+Bool).

elem :: Eq a => a -> [a] -> Bool

Hoogle is a very useful tool. You can integrate it with ghci.

*****************************

This hack to use type signatures on Hoogle is such a wonderful thing. It makes Haskell even more intuitive.

What kind of Haskell hacks do you use?

P.S. If I remembered the function "elem" I wouldn't probably find out about that hack for a long time.
IBM is acquiring Red Hat
Tags: news, discuss, opensource, linux
Published: 2018-10-28 20:25:49

Big news in open source/cloud.

## [IBM will acquire open-source cloud software company Red Hat](https://www.theverge.com/2018/10/28/18035086/ibm-red-hat-acquisition-open-source-cloud-software-company)

> IBM announced this afternoon that it will acquire open-source software company Red Hat for $34 billion. The deal will help IBM expand its reach as an enterprise cloud computing provider.
Shifting gears from part time, self taught to full time bootcamp student.
Tags: beginners, career
Published: 2018-10-28 20:11:48

---
title: Shifting gears from part time, self taught to full time bootcamp student.
published: true
description: I got accepted into a fulltime bootcamp and I am trying not to freak out about it.
tags: #beginners, #career
---

##Taking the plunge.

Let's start this with a little story. I first became interested in working in tech when I went back to school at age 30. I was lucky enough to have a great teacher in my intro to programing class. I loved solving those first problems, and thought if I could do this for a living I totaly would, I had not yet learned what direction I was going to go for, so I started planning to go for the long haul and get a CS Degree. 

Long story short, I took an internship as an IT Help Desk Technician and I have been working in the field ever since. At many times I have been close to my goal of working as a Developer full time. There was the time I used my skills to figure out how to automate emails to new hires at my company, and help the hr department track all the odds and ends needed to bring on new people. I currently work for an IT service center where the stress and work load are very high and I have been working very hard to leave that behind. There was the time I was hired by a local agency as a freelance front end Developer all the while scrambling to keep up with my fulltime day job. And I made it all work, somehow, subjected myself to the late nights, and finally worked my way up to be able to work one day a week on the website project at my current job, its good experience sure.I don't exactly know how many years of experience I act have since it's not fulltime but hey I have been doing this stuff for over five years all told.

So what did I decide to do. I ended up applying for and getting accepted into a fulltime bootcamp. I had always considered them as completely outside of the realm of possibility. But I started thinking about how I might make it work, without any real savings, I could not afford to pay upfront, or take out a loan. I found an online bootcamp with a deferred payment model and started trying to figure out how to make it happen. I have a family with a wife and two kiddos, so it is extremely important that I keep them in mind in making any decision that affects them. Luckily my wife has a fulltime teaching job, it doesn't pay much but it covers some bills and healthcare. I will continue freelancing for the IT firm I work at now on the website but that will be hit and miss. And I guess I will cash in on my small retirement to make ends meet. 

This is an extremely difficult thing to do, a gamble and could end up being disastrous for my family. I question whether I am doing the right thing often, but keep coming back to the benafits of having all the time to devote to writing code. I know I can build things pretty well, and I know how to work with people. I honestly can't wait to take the next step on this journey. Am I not considering something? Would love your feedback or questions.

Thanks to the Dev.to community for all its collective support.
Stateless Components
Published: 2018-10-28 20:07:46

---
title: Stateless Components
published: true
description: 
tags: 
---

When first starting out in React, and even beyond, I had mostly made all of my components stateful, even though the component had no need to maintain a state. But is that a bad thing? Well, short answer is yes, and for more reasons than one. 

A stateless component is something that can be declared as a function, and can act as a full on stateful component, granted it’s given the necessary props. Besides the obvious of not retaining it’s own state, stateless components also don’t adhere to the component lifecycle methods. It also has no backing instance (object in memory where the state is stored). So essentially, a stateless component is just a function that’s returning JSX expressions. 

Being able to create stateless components allows us to not only save memory, which is always a good thing, but it allows us to keep our code clean and simple. Recently I was working on a React Application that required a navbar, and prior to exporting the nav into it’s own stateless component, it looked like this:


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

However, now, what we do, is we simply create a new file, and remove the html located within, and move it to a stateless component, and call it as a function like so:

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

Notice that when i call it as a function, i use the function key word as opposed to arrow functions, the reason being that with arrow functions, we bind this, which we don't want in this particular instance. Now, we can simply replace all that code in App.js and insert our new stateless component.

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

The reason I’m using .call(this) is to bind the context of this in App.js to the child, so we can access things like this.state from App.js. 

Stateless components have really changed the way that I write in React, and I plan on using them as much as possible to save memory for my applications. Perfection!
Unit testing, Docker and Django -- a podcast episode
Tags: startup, django, unittesting, podcast
Published: 2018-10-28 19:46:04

---
title: Unit testing, Docker and Django -- a podcast episode
published: true
description: Rebooting my product development podcast to be more tech focused
tags: startups, django, unittesting, podcast
---

This is a sneak peak at the next episode of my product development podcast, Platform. It originally existed to chart the development of my product, and morphed into discussions on podcasting in general. Now I'm rebooting it to focus specifically on the tech involved in building a web product, without the benefit of VC funding or incubators.

[![Waveform image](https://thepracticaldev.s3.amazonaws.com/i/ccufeyynbqa3zmnqi0at.png)](https://platform.podiant.co/e/36bd174da61e2c/)

If you're interested in the show, you can get the RSS feed at http://feeds.podiant.co/platform/rss.xml or find it in your favourite podcast app.

In the episode I talk about my adventures in migrating a fairly large app from running inside Vagrant and VirtualBox to running in Docker, and share my thoughts on unit testing and the -- to my mind -- unhelpful rhetoric around it.

The episode will go out on Sunday 4th, and I've got a few topics lined up for the next one, but would love your feedback.

Thanks!
THE SCRIPT KIDDIE HOLE OF DOOM (aka the ESP8266 honeypot)
Tags: micropython, dweet, esp8266, honeypot
Published: 2018-10-28 19:41:54

---
title: THE SCRIPT KIDDIE HOLE OF DOOM (aka the ESP8266 honeypot)
published: true
description: My project to create a simple honeypot that runs on the ESP8266 microcontroller.  Version 1 was released today, suggestions on new features are welcome!! 
tags: #micropython #dweet #esp8266 #honeypot
---

This project is designed to make a simple honeypot that runs a Telnet server.  The server is then port forwarded so it can be accessed by anyone.  I wanted to see if people would still bother scanning or hacking Telnet devices since most scanning tools are automated now.  Please feel free to suggest any additions or changes, v1 is now out (Honeyboi 1).  Project link [here](https://github.com/gbafana25/esp8266_honeypot)
React Native Check Text Input Is Empty Or Not In Android
Tags: react, reactnative, android, javascript
Published: 2018-10-28 18:36:39

---
title: React Native Check Text Input Is Empty Or Not In Android
published: true
description: React Native Check Text Input Is Empty Or Not In Android
tags: #react #reactnative #android #javascript
---

Post Link : <a href="https://www.skptricks.com/2018/10/react-native-check-text-input-is-empty-or-not.html" > React Native Check Text Input Is Empty Or Not In Android </a>

This tutorial explains how to check TextInput Component entered value in react native application and also we add validation checkpoint in TextInput Component to check whether input value is empty or not. In our previous tutorial we have discussed about TextInput component and their uses in react native application. If you still not remember, then check out the below link for the reference.

<a href="https://www.skptricks.com/2018/10/react-native-check-text-input-is-empty-or-not.html" > React Native Check Text Input Is Empty Or Not In Android </a>

<img src="https://3.bp.blogspot.com/-oKCW-wle18M/W9X_e-qec8I/AAAAAAAACFg/tHyVXtBo6Zs0182HKPgmyiKy_6T6YpB2QCLcBGAs/s640/te.png" />
How To Avoid Back Pain While Sitting In Front Of Computer
Published: 2018-10-28 17:54:38

---
title: How To Avoid Back Pain While Sitting In Front Of Computer
published: true
description: 
tags: 
---
Computer usage is top reason have neck and back pain. Try these couple of basic tweaks to improve your pose at the office and put a stop to neck and back pain.

<img src="https://thepracticaldev.s3.amazonaws.com/i/s5oe7ronlb6u55f03k8l.jpg">

<b>Keep your head up</b>

Focus on aligning your head as well as neck right above your shoulders; prevent stressing onward.

<b>Be choosy with your chair</b>

Choose one that allows your lower back to relax versus a back support. Then tilt the back of the chair so it's really a little reclined.

<b>Sit within reach</b>

Your upper body should have to do with an arm's length away from the display, which ought to be 2 to 3 inches over eye level.

<b>Plant your feet</b>

Maintain them level on the floor and shoulder-width apart to quiet stress in your knees and also ankles.

<b>Find the best angle</b>

Position your knees at 90 levels, directly over your ankles; this will keep your spinal column easily upright.

<b>Stretch your shoulders</b>

Roll them back as well as down, as well as square them over your hips. Picture that you're balancing a plate on your head, and also you don't want it to fall off.

<b>Don't cross your legs</b>

Sitting cross-legged makes it challenging to keep your spine right and also shoulders made even, and you risk overstretching the muscle mass around the hips, upping your risk of varicose blood vessels by interrupting blood flow. So uncross and unwind.

<b>Take a breath from your stomach</b>

On each inhale, consider drawing your navel toward your back; that involves the core muscle mass as well as supports the top body.

<b>Take bed mattress when you resting</b>

When you take rest on your bed then try <a href="https://comfymattress.reviews/lucid-vs-zinus/">chose right mattress</a> like Lucid or Zinus for body balance and by laying on your back.

<b>Take breaks</b>

Rising a minimum of when a hour to go to the shower room or just do some shoulder rolls reduces pressure on back disks and increases flow. Payback: you'll be a lot more limber and much less stressed.
Nobody can ever teach you something
Tags: devhelp, career, mindset, university
Published: 2018-10-28 16:58:52

---
title: Nobody can ever teach you something
published: true
description: A mindset change when it comes to learning
tags: devhelp, career, mindset, university
---

Most people go to university with an attitude that "It will teach me how to program", they get there and, what do you know? Almost everything is taught in such a boring manner that it all feels utterly useless and you just remain (yes, passively) 3 years or more so you can pass all the classes.

## Nobody can ever **teach** you something

Read this a few more times and drill it into your head. If the teacher is entertaining and the subject looks useful you start learning but when the teacher is as monotone as Microsoft Sam or the subject looks completely useless what do you do?

Should you blame the teacher, faculty, university and everything in between that you are not being taught properly OR take matters into your own hands and start learning because **nobody can ever teach you something**?

You are the one making the **effort** of paying attention and processing the information you are being given. Yes, you are the one **learning** it's just that, sometimes it doesn't feel like effort on our part. 

Be it from a teacher, from a book or from a YouTube video understand that you are always the one responsible for paying close attention and it mostly depends on **you** for learning something.

Of course, if the teacher spouts nonsense related to the subject get another source of information or if the subject *looks* useless analyze it closely, it might not be as useless as it sounds. It all depends on you!
A Lightning Talk about Pry and a Blogpost about Lisp
Tags: lisprubytips
Published: 2018-10-28 15:36:59

---
title: A Lightning Talk about Pry and a Blogpost about Lisp
published: true
description: 
tags: lisp ruby tips
---

This week was quite busy (for things other than work). My co-workers at [Runtime Revolution](https://www.runtime-revolution.com/) had just enough of me. On Tuesday my post [_Four things about Pry_](https://revs.runtime-revolution.com/four-things-about-pry-a0ebb10c6c2e) was published on our [blog](https://revs.runtime-revolution.com/). It is about a handful of features which I useful for debugging Ruby code.

And then on Thursday I made a lightning talk about Lisp. In it I attempt to give some insight some of Lisp's often joked and praised about features:
- Parenthesis
- Prefix notation
- Recursion
- Functional programming

Had to remove **Macros** due to time restrictions.

Slides were made on [Remark](https://remarkjs.com/) and you find them [here](https://bjacquet.github.io/extras/lisp-speech-therapy/presentation.html). Remark is great for quick and simple slides but had a really hard time making a PDF out of it.
Why is an IDE for Interpreted Languages "Overkill?"
Tags: discuss
Published: 2018-10-28 14:55:39

---
title: Why is an IDE for Interpreted Languages "Overkill?"
published: true
description: Why do compiled languages merit an IDE where an interpreted language does not?
tags: #discuss
---

So often I hear the words "an IDE is overkill for Python/Ruby/JavaScript, just use Vim/Emacs/Nano/IDLE."

Why is that? I write interpreted languages as much as the next guy, but in my experience, I

- still want a debugger
- still want tag definitions for demystifying framework "magic"
- still want types
- despise "print statement debugging"

OK, so your fancy vim setup has ctags/cscope for tag definitions and you "know your code so well you don't need types." What about in 6 months when a bug crops up? Still remember what `a` is? `i`? `j`? `temp`?

So the root of my question is, where did this mantra that you don't need IDEs for interpreted languages come about? You don't *need* an IDE for any language, but what about compiled languages makes them so much more desirable?
Codetip - Javascript: Hide Dependency to a Data Structure
Tags: javascript, codetip
Published: 2018-10-28 14:00:35

---
title: Codetip - Javascript: Hide Dependency to a Data Structure
published: true
description: Hide Dependency to a Data Structure
tags: javascript, codetip
---

Many times we encounter situations where our code depends on a complicated data structure or a data structure that has implicit semantics. For example, let’s say we create a chart and the data that we have to use is a response from a server (we can’t change the structure of the response). The response from the server looks like this:

```js
[
 ["2018-12-02", 1000], 
 ["2018-11-02", 900], 
 ["2018-10-02", 200], 
 ["2018-09-02", 300]
]
```

This structure has an implicit meaning, it is an array of arrays, each of which has two values, the first represents a date and the second one a value. The naive approach is to use this structure directly in our code, like:

```js
class Chart {
  constructor(data){
    this.data = data;
  }
 
  createDomains(){
    x.domain(d3.extent(this.data, d => d[0])); // date
    y.domain(d3.extent(this.data, d => d[1])); // value
  }
 
  createLine(){
    d3.line()
      .x(d => d[0]) // date 
      .y(d => d[1]); // value
  }
 
  formatDate(){
    this.data.forEach(d => {
      d[0] = parseTime(d[0]); // date
    });
  }
}
```

The problem with this approach is that, if the server decides to change the order of the values, or introduces a new one in the first or second place of the array, our code we break, let’s say the structure changes to look like:

```js
[
 ["Dinos", "2018-12-02", 1000], 
 ["Nikos", "2018-11-02", 900], 
 ["Petros", "2018-10-02", 200], 
 ["Giannis", "2018-09-02",  300]
]
```

Now our class is broken, every single method of it is broken. We have to update every method to fix the problem. A better approach would be to not depend on the structure of the response.

```js
class Chart {
  constructor(data){
    this.data = data.map(dataPoint => ({
      date: dataPoint[0],
      value: dataPoint[1],
    }));
  }
 
  createDomains(){
    x.domain(d3.extent(this.data, d => d.date));
    y.domain(d3.extent(this.data, d => d.value));
  }
 
  createLine(){
    d3.line()
      .x(d => d.date)
      .y(d => d.value)
      .values(this.data) 
  }
 
  formatDate(){
    this.data.forEach(d => {
      d.date = parseTime(d.date);
    });
  }
}
```

If the server decides to change the passed data structure, we will have to update our code only in a single place, the constructor, leaving every other method untouched.