teleren/devto huggingface dataset:
lightweight fzf usages
Tags: fzf, commandline
Published: 2019-02-18 04:57:18

---
title: lightweight fzf usages
published: true
description: 
tags: fzf,commandline
---

effective and core usage of [fzf](https://github.com/junegunn/fzf) is writing function in .bashrc or something like that.

this article focuses lightweight usages.


## open vim with fzf
```bash
vim $(fzf)
```

## open meld(diff tool) with fzf

```bash
 meld $(fzf -m)
```

## read json REST Api with fzf
```bash
curl ... | json_pp | fzf
```
Introduction To Testing By Writing A Simple Maths Lib
Tags: python, tdd, unittesting
Published: 2019-02-18 03:50:02

---
title: Introduction To Testing By Writing A Simple Maths Lib
published: true
description: time to try testing
tags: python, tdd, unittesting
cover_image: https://images.unsplash.com/photo-1538390416079-c89a38c8db42?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1054&q=80
---

At one time or the other, testing becomes a need. You can't afford to ship parts not working so ... you test to ensure that everything is as intended. You don't only test codes but also guis, apis and database functioning. In this post we'll be sailing in shallow waters to enable beginners to start testing, once for all.

## Our Maths Lib

Let us write a maths lib to solve common maths issues

- area of square
- area of triangle
- length of hypotenuse

for the name i've chosen complemaths as it complements the standard library 

Let us write our class

```python
class Complemaths:

    def area_square(length_, width_):
        return width_ * length_

    def area_triangle(base_, height_):
        return base_ * height_ * 0.5

    def hypotenuse(side1_, side2_):
        return sqrt(side1_**2 + side2_**2)
```

- 1 we did not add a constructor here as it was not needed.
- 2 also, side1_**2 could have been side1_*side1_
- 3 area_triangle and hypotenuse return floats

let us use our lib

## Usage

```python
print(Complemaths.area_square(2, 2))
print(Complemaths.area_triangle(5, 2))
print(Complemaths.hypotenuse(5, 5))
```
gives out
```python
4
5.0
7.0710678118654755
```
## An Overview Of Testing

It's not really necessary to have a framework. You can do something like that:

```python
def testing():
    if(Complemaths.area_square(2, 2) == 4):
        print('test1 ok')
    else:
        print('test1 fail')

testing()
```
or use assert

```python
def test_area_square():
    assert Complemaths.area_square(2, 2) == 4, 'should be 4'

test_area_square()
```
if all ok, no messages is displayed, else halts execution

but, a framework has some advanced capabilities. fortunately, python ships with it's own called unittesting, inspired by java's Junit

## Our Test With Unittesting

```python
class ComplemathsTests(unittest.TestCase):
    def test_area_square(self):
        self.assertEqual(Complemaths.area_square(5, 2), 10)

    def test_area_triangle(self):
        self.assertEqual(Complemaths.area_triangle(5, 2), 5.0)

    def test_hypotenuse(self):
        self.assertEqual(Complemaths.hypotenuse(3, 4), 5.0)


if __name__ == '__main__':
    unittest.main()
```

it gives us

```python
...
----------------------------------------------------------------------
Ran 3 tests in 0.001s

OK
```

testing by parts is called unit testing and using tests in your development is called test driven development, tdd.

---
Photo by Malcolm Lightbody on Unsplash
Calico Helm Chart for Kubernetes
Tags: githunt, kubernetes
Published: 2019-02-18 01:56:48

While ago I was looking for Calico helm chart and there were some deployment files floating around the web using `kubectl` etc, but I really like to automate things with press of a button. So here it is a Calico Helm Chart that needs some love in case you are into Kubernetes.

{% github mrzobot/calico-helm-chart %}
The Principal Developer
Tags: career, programming, story, experience
Published: 2019-02-17 14:48:25

---
title: The Principal Developer
published: true
tags: career, programming, story, experience
---

Today I had a phone conversation with my ex-colleague Alex. Alex works as a software developer in a fast-growing international organization.

Me: “How are things going?”

Alex: “My company is searching for a principal developer.”

Me: “Did you apply for that position?”

Alex: “I did, but my application has been rejected. CTO believes that I am not qualified for that role. He is searching for a better candidate.”

Me: “Do you think that you are good enough?”

Alex: “Of course! I have been writing code and solving intricate technology problems for more than seven years. I write clean code, proactively fix the technical debt and cut through JIRA tasks like a ninja. I am faster and better than other teammates”.

Me: “I guess this is the exact reason why you don’t qualify.”


[Continue reading...](https://sizovs.net/2019/02/15/the-principal-developer/)
PHP Enums
Published: 2019-02-18 08:38:51

---
title: PHP Enums
published: true
tags: 
canonical_url: https://stitcher.io/blog/php-enums
---

An enumeration type, "enum" for short, is a data type to categorise named values. Enums can be used instead of hard coded strings to represent, for example, the status of a blog post in a structured and typed way.

PHP doesn't have a native enum type. It offers a very basic [SPL implementation](http://php.net/manual/en/class.splenum.php), but this really doesn't cut the chase.

There's a popular package written by [Matthieu Napoli](https://mobile.twitter.com/matthieunapoli) called [myclabs/php-enum](https://github.com/myclabs/php-enum). It's a package I and many others have been using in countless projects. It's really awesome.

Today I want to explore some of the difficulties we encounter when solving problems like enums in userland. I'll talk about my personal take on enums, and we'll ponder on core support.

Continue reading on [https://stitcher.io/blog/php-enums](https://stitcher.io/blog/php-enums)
Use Vim as a Ruby IDE
Tags: ruby, vim, spacevim
Published: 2019-06-23 14:38:35

---
title: Use Vim as a Ruby IDE
published: true
tags: ["ruby", "vim", "SpaceVim"]
canonical_url: https://spacevim.org/use-vim-as-a-ruby-ide/
---

# Use Vim as a Ruby IDE

This is a general guide for using SpaceVim as a Ruby IDE, including layer configuration and usage.Each of the following sections will be covered:

<!-- vim-markdown-toc GFM -->
- Enable language layer
- Code completion
- Syntax linting
- Jump to test file
- running code
- Code formatting
- REPL support
<!-- vim-markdown-toc -->
### Enable language layer

To add Ruby language support in SpaceVim, you need to enable the `lang#ruby` layer. Press `SPC f v d` to openSpaceVim configuration file, and add the following snippet:

```
[[layers]]
  name = "lang#ruby"

```

For more info, you can read the [lang#ruby](https://spacevim.org/layers/lang/ruby/) layer documentation.

### Code completion

`lang#ruby` layer will load the Ruby plugin automatically, unless it’s overriden in your `init.toml`.The completion menu will be opened as you type.

![rubycomplete](https://user-images.githubusercontent.com/13142418/53355518-20202080-3964-11e9-92f3-476060f2761e.png)

### Syntax linting

The checkers layer is enabled by default. This layer provides asynchronous syntax linting via [neomake](https://github.com/neomake/neomake).It will run rubocop asynchronously.

Install rubocop via gem:

```
gem install rubocop

```

![rubylint](https://user-images.githubusercontent.com/13142418/53347011-32459300-3953-11e9-9ca2-3e07f832db5a.png)

### Jump to test file

SpaceVim use built-in plugin to manager the files in a project, you can add a `.project_alt.json` to the root of your project with the following content:

```
{
  "src/*.rb": {"alternate": "test/{}.rb"},
  "test/*.rb": {"alternate": "src/{}.rb"}
}

```

With this configuration, you can jump between the source code and test file via command `:A`

### running code

To run current script, you can press `SPC l r`, and a split windowwill be openen, the output of the script will be shown in this window.It is running asynchronously, and will not block your Vim.

![rubyrunner](https://user-images.githubusercontent.com/13142418/53300165-6b600380-387e-11e9-852f-f8766300ece1.gif)

### Code formatting

The format layer is also enabled by default. With this layer you can use key binding `SPC b f` to format current buffer.Before using this feature, please install rufo:

```
gem install rufo

```

![formatruby](https://user-images.githubusercontent.com/13142418/53301042-3c02c400-3889-11e9-9918-430ad6a7f08f.gif)

### REPL support

Start a `irb` inferior REPL process with `SPC l s i`. After the REPL process being started, you cansend code to inferior process. All key bindings prefix with `SPC l s`, including sending line, sending selection or evensend whole buffer.

![rubyrepl](https://user-images.githubusercontent.com/13142418/53347455-1098db80-3954-11e9-87c3-13a027ec88f6.gif)
Use the release phase to automate your release in your Laravel app
Tags: heroku, laravel
Published: 2019-02-21 19:23:56

---
title: Use the release phase to automate your release in your Laravel app
published: true
tags: heroku,laravel
canonical_url: 
---

#### Laravel on Heroku — Tip #2

On Heroku the [release phase](https://devcenter.heroku.com/articles/release-phase) allows you to run certain tasks before a new release of your app is deployed.

Release phase can be useful for tasks such as:

- Run the database migrations
- Clear cache
- Sending CSS, JS, and other assets from your app’s slug to a CDN or S3 bucket

In our Laravel app, we will run the database migrations and flush the application cache.

Add the following line to your _Procfile_:

```
release: php artisan migrate --force && php artisan cache:clear
```

The main advantage of using the release phase:

> If the release command exits with a non-zero exit status, or if it’s shut down by the dyno manager, the release _fails_. In this case, the release is _not_ deployed to the app’s dyno formation. You will receive an email notification in the event of a release phase failure.

### Want more tips like these?

You should follow me on [Twitter](https://twitter.com/AutoIdle)! And if you’re building on Heroku, you should check out [AutoIdle](https://autoidle.com) — the automated way to save money on your staging and review apps.
TIL: How does .chomp method works?
Tags: todayilearned, ruby, oop
Published: 2019-02-17 22:49:13

---
title: TIL: How does .chomp method works?
published: true
description: Actually, what chomp does, is removing the Enter character at the end of your string
tags: todayilearned,ruby,oop
---


As I'm learning Ruby on [Codecademy](https://www.codecademy.com) I've come across many methods and I'm learning many things. But as I want to master this language, I'm taking some time to dive into some new things I learn every day. Today I want to go in depth on:

## How does `.chomp` method work?
First of all, put in mind that Ruby is an Object Oriented language and everything in Ruby is an object. So, when we call the `.chomp` method on a value/object it removes the line break.

Actually, what `.chomp` does, is removing the Enter character at the end of your string. When you type _d e v t o_, each character at a time and then press Enter `gets` takes all the letters and the Enter. Remember that Enter is just another character in Ruby.

For example:
```ruby
input = gets # get a string
Bem Vindo
=> "Bem Vindo\n" # when you hit the enter keyboard it adds a character
```
Now let us remove that enter character

```ruby 
puts input.chomp
```

or we can remove right away when typing it
```ruby
input = gets.chomp # gets require a string as input and chomp will delete the line break that comes with that string
```

`gets` is your User's input. Also, it's good to know that gets or puts, mean *get string* or *put string* for `puts`. That means these methods are dealing with strings only.

We can even use the `.chomp` method to remove a substring of a string in that way.

```ruby
str = "Hello"

str.chomp("lo")
```

### Resources:
[What is Ruby](https://whatis.techtarget.com/definition/Ruby)
[Help and documentation for the Ruby programming language.](http://ruby-doc.com/docs/ProgrammingRuby/)
[Everything is object in Ruby](https://medium.com/@pk60905/everything-is-object-in-ruby-559475ce71dd)
[Chomp method - Ruby Docs](https://ruby-doc.org/core-2.2.0/String.html#method-i-chomp)


Thanks.
Use Heroku environment variables in your Laravel app
Tags: laravel, heroku
Published: 2019-02-20 11:43:38

---
title: Use Heroku environment variables in your Laravel app
published: true
tags: laravel,heroku
canonical_url: 
---

#### Laravel on Heroku — Tip #1

![](https://cdn-images-1.medium.com/max/1024/1*3z-4f6PlhJ2nv_gbyUZhzg.png)

On Heroku, you get environment variables for PostgreSQL, Redis, e.g.

You shouldn't add manually environment variables on Heroku for Database (like DB\_HOST, DB\_PORT, e.g.) and Redis (REDIS\_HOST, e.g.).

Because you have to change these if you upgrade/downgrade these Heroku add-ons.

And more importantly, **Heroku can change these environment variables at any time.**

A better solution would be, add the following lines at the beginning of _config/database.php_

{% gist https://gist.github.com/sgasser/81850ad446580e2f4a995cb95dc499f0 %}

### Want more tips like these?

You should follow me on [Twitter](https://twitter.com/AutoIdle)! And if you’re building on Heroku, you should check out [AutoIdle](https://autoidle.com) — the automated way to save money on your staging and review apps.
I developed "Party Finder" a Flutter app for implementing "Party finding concept" UI/UX design by Lorenzo Restuccia
Tags: flutter, ui, ux, app
Published: 2019-02-17 20:17:13

---
title: I developed "Party Finder" a Flutter app for implementing "Party finding concept" UI/UX design by Lorenzo Restuccia
published: true
description: This Flutter app is part of a collection of apps that I developed with the purpose of mastering the necessary skills for implementing custom UI/UX designs in Android and iOS.
tags: #flutter #ui #ux #app
---

This app is part of a collection of apps that I developed in Flutter with the purpose of mastering the necessary skills for implementing custom UI/UX designs in Android and iOS.

You can find the entire collection of apps in [this blog post](https://dev.to/crivasgomez/flutter-uiux-design-implementations-518i) and all the source code in [this GitHub repository](https://github.com/CRivasGomez/flutter-ui-ux-designs).

## Party Finding

### [Original design](https://www.uplabs.com/posts/party-finding-concept) by [Lorenzo Restuccia](https://www.uplabs.com/lorenzo_restuccia_8):

![Original design](https://thepracticaldev.s3.amazonaws.com/i/czgsqvf6isycsemqu2ii.png)

### iOS demo:

![iOS demo](https://thepracticaldev.s3.amazonaws.com/i/tx0bpr53y3aao73uw2yj.gif)

### Android demo:

![Android demo](https://thepracticaldev.s3.amazonaws.com/i/knbbkcin8bl0sp1e41kg.gif)
Hiding user accounts in MacOS
Tags: macos, productivity, systemadministration
Published: 2019-02-17 18:35:27

---
title: Hiding user accounts in MacOS
published: true
description: 
tags: MacOS, productivity, system administration
---
##Hiding User account in MacOS

1. Hiding user account from login window. — Simple
2. Hiding user account from login window and system preferences — Advanced 

###1. Simple version
The simple version hides the user account from displaying in the list of user accounts during the login process. The account can be visible from system preferences as well as /Users. Here is how to achieve this effect: 

`sudo defaults write /Library/Preferences/com.apple.loginwindow HiddenUsersList -array-add <username_to_hide>`

And now you can reboot and the username mentioned above will not appear in the login window. If you want to revert this, you can run the following command 

`sudo defaults delete /Library/Preferences/com.apple.loginwindow HiddenUsersList`

###2. Advanced version
There are multiple ways of achieving a totally hidden user account. This method involves creating a user account which is no longer visible in system preferences, creating a home folder other than /Users and hiding all shared mount points. This is a true ninja account. 

Creating a hidden user account with home directory other than /Users

`sudo dscl . create /Users/dummy NFSHomeDirectory /var/dummy`
`sudo dscl . delete "/SharePoints/Dummy's Public Folder"`

This command removes the Public Folder share point for the user with the long name "Dummy”
When should we use the appropriate way to set state?
Tags: react, beginners, explainlikeimfive, help
Published: 2019-02-17 17:56:46

---
title: When should we use the appropriate way to set state?
published: true
description: Trying to understand when and why we should choose one method over the other when setting state with ReactJS
tags: #react #beginners #explainlikeimfive #help
---

I'm still new with React and am trying to understand when we would use each of the, according to React team, correct ways of setting state. I've seen both methods used, but confused when one way would be used over the other. 

*Why wouldn't we always use Option 2 below?*


[Here is the link to the React Docs on this section](https://reactjs.org/docs/state-and-lifecycle.html#using-state-correctly)

### Do Not Modify State Directly (Option 1)
```js
this.setState({comment: 'Hello'});
```

### State Updates May Be Asynchronous (Option 2)

```js
this.setState((state, props) => ({
  counter: state.counter + props.increment
}));
```
![alt text](https://media.giphy.com/media/5XRB3Ay93FZw4/giphy.gif "Wondering...")
Learn C and its lower level interactively, in your browser (part 2).
Published: 2019-02-17 17:26:33

---
title: Learn C and its lower level interactively, in your browser (part 2).
published: true
description: 
tags: 
---

Hi everyone,



Today, I have just released part 2 of my tutorial series.

If you don't know what I am talking about, check out my last post [here](https://www.reddit.com/r/javascript/comments/aoskao/learn_c_and_its_lower_level_interactively_in_your/).



Get [notified](https://docs.google.com/forms/d/e/1FAIpQLSectFtg9jl4zkFZqPnQkSRChNG7-I0qzR3247NRzdmAqEHCZA/viewform) when new parts are released.

Join the discussion on our [subreddit](https://www.reddit.com/r/minic/comments/ap1jv4/what_is_this_sub_all_about/).

If you like this series, consider [supporting](https://github.com/vasyop/miniC-hosting/blob/master/support.md).



You can find part 2 [here](https://vasyop.github.io/miniC-hosting/?1).
Websockets with message callback
Tags: javascript, websockets, data
Published: 2019-02-17 17:24:21

---
title: Websockets with message callback
published: true
description: 
tags: javascript, websockets, data
canonical_url: https://github.com/aidv/websockets-callback
---

This is a part of a larger project that I've worked on and I figured other people might find it useful.

Project: https://github.com/aidv/websockets-callback

In my project I send data to a server using WebSockets and then waits for a response until the data has been processed.

Once a response is received a callback is executed and the user is notified.

My library simplifies such a flow a lot and code can be written like one would write any callback driven code.
Any WHMCS Developers out there ?
Tags: php, whmcs, discuss, webdev
Published: 2019-02-17 16:34:30

---
title: Any WHMCS Developers out there ?
published: true
description: Hello folks. Looking for Developers who have written modules or plugins for WHMCS or customized it any other way. Please comment.
tags: php,whmcs,discuss,webdev
---

Hello folks. Looking for Developers who have written modules or plugins for WHMCS or customized it any other way. Please comment.
Programming in the real world
Tags: discuss
Published: 2019-02-17 16:04:11

---
title: Programming in the real world
published: true
description: I have to give a talk to undergraduate CS students about real-work programming
tags: discuss
---

As part of a colaboration with a local university, I have to give a talk to undergraduate CS students about real-work programming. They are coming on-site to our webdev offices.

I want to convey the notion that requirements are constantly changing and much of the difficulty lies in managing complexity. Does anyone have any ideas for workshop style activities I could run on this topic?
High level view and logic separation in React
Tags: beginners, javascript, react
Published: 2019-02-17 15:45:09

---
title: High level view and logic separation in React
published: true
description: 
tags: beginners, javascript, react
---

One of React’s greatest strengths is the ability to separate the view from the logic. I like to take it a step further and create two separated _components_, one harboring view, and one – logic.

On the first sight, this might sound like an overhead. _Why should I create two files, when I can just utilize `render` method._ While true, this approach has many benefits. For starters, it allows two people to work on one thing simultaneously. One, a junior, can write styles and JSX markup, while a more experienced developer can write its logic handling. Another valid point is a separation of concerns – an entire view can be replaced without even touching the files with logic inside, as long as they use the same props. 

So, how do I approach such thing? Simple, really.

First thing is, I define the state. _The component should_ things, like – respond to mouse hover, distinguish its state between active and dormant and display text passed to it. Next, I write the logic. Most often this is a class with some internal methods:

```jsx
// containers/Thing/index.js

import View from "@src/ui/Thing";

class Thing extends React.Component {
  state = {
    active: false,
    hovered: false,
  };
  
  setActiveState = () => this.setState({ active: !this.state.active });
  
  setHoveredState = () => this.setState({ hovered: !this.state.hovered });
  
  render() {
    return (
      <View
        active={this.state.active}
        hovered={this.state.hovered}
        onClick={this.setActiveState}
        onMouseEnter={this.setHoveredState}
        onMouseLeave={this.setHoveredState}
        text={this.props.text}
      />
    );
  }
}
```

So much for logic. There can be a lot more, of course, but for the sake of illustration, it will suffice.

Next, the view.

```jsx
// ui/Thing/index.js

const Thing = (props) => {
  const {
    active,
    hovered,
    onClick,
    onMouseEnter,
    onMouseLeave,
    text,
  } = props;
  
  return (
    <div
      onClick={onClick}
      onMouseEnter={onMouseEnter}
      onMouseLeave={onMouseLeave}
      style={{
        background: active ? "tomato" : "transparent",
        color: hovered ? "yellow" : "black",
      }}
    >
      {text}
    </div>
  );
};
```

Again, this is it. Very simple and concise. 

This pattern works great in teams with junior and middle developers, as they can work on the target goal while not staying behind due to either lack of knowledge in more complex logic matters, or to lack of interest in writing views. 

—

- A minimal example can be seen on [CodeSandbox](https://codesandbox.io/s/3y7nl6z7mm);
- Full example of this architecture can be found in [my project](https://github.com/tomekbuszewski/Videoplayer).