teleren/devto huggingface dataset:
Servidor HTTP simples em Java
Tags: java, ptbr
Published: 2020-02-21 11:43:27

---
title: Servidor HTTP simples em Java
published: true
date: 2020-01-28 23:30:28 UTC
tags: java,pt-br
canonical_url: https://www.paulocollares.com.br/programacao/servidor-http-simples-em-java/
---
![Servidor HTTP simples em Java](https://www.paulocollares.com.br/wp-content/uploads/2020/01/Internet1.svg_-1024x824.png)

Neste post iremos montar um servidor HTTP simples em Java. Útil para obter informações simples de uma aplicação rodando um background por exemplo.

O projeto completo pode ser baixado no Github: [https://github.com/pcollares/exemplos-blog/tree/master/SimpleHTTPServer](https://github.com/pcollares/exemplos-blog/tree/master/SimpleHTTPServer)

O primeiro passo é criar uma instância do servidor http nativo:

```
HttpServer servidor = HttpServer.create(new InetSocketAddress(8080), 0);
```

Nesse exemplo ele irá executar na porta 8080.

Agora adiciono um novo contexto e uma classe, que criaremos abaixo que será quem irá resolver as requisições.

```
servidor.createContext("/", new Root());
```

Bastando iniciar o servidor agora

```
servidor.start();
```

Nesse exemplo, a classe Root que irá responder as requisições feitas para o contexto ‘/’ e deve implementar a interface HttpHandler para que o método handle prepare o retorno que será enviado no corpo da resposta http.

Para isso, crio um StringBuilder para facilitar a concatenação das Strings:

```
StringBuilder out = new StringBuilder();

out.append("<html>");
out.append("<head>");
out.append("<title>Ola mundo").append("</title>");
out.append("</head>");
out.append("<body>");
out.append("Olá mundo");
out.append("</body>");
out.append("</html>");
```

E escrevo essa saída como um array de bytes:

```
he.sendResponseHeaders(200, out.toString().length());

try (OutputStream os = he.getResponseBody()) {
    os.write(out.toString().getBytes("ISO-8859-1"));
}
```

O resultado pode ser visto acessando http://localhost:8080/

No código completo no Github, adicionei mais uma página de exemplo (/stats) que demonstra como pode ser útil para obter informações do Hardware e do sistema operacional, como memória, uso do disco, processador, threads, etc…

![](https://www.paulocollares.com.br/wp-content/uploads/2020/01/servidor-http-simples-em-java-memoria-processador-sistema-operacional.png)<figcaption>Exemplo de resposta do servidor http simples em Java</figcaption>

[]’s
Flutter or Native? 
Tags: dart, flutter
Published: 2020-01-29 09:40:43

Hey everyone, I just wanted to know whether I should go with flitter or native for development of applications, I'm a student with some knowledge of back-end dev, but a school project of mine requires an app to be built. I messed around with both native and flutter a bit, I just loved the way flutter does things. But considering the job market and everything, As I shall invest a lot of time on learning one of the platform pretty well, what should I follow?
Which JavaScript Framework Will Take Lead in 2020?
Tags: javascript, node, reactnative
Published: 2020-01-29 09:39:19

There are loads of JavaScript frameworks already in the market and still, there is no dearth of new ones that are jointing the league of Javascript frameworks. While some are enjoying outstanding popularity and acceptance among the developer community, there are several others that enjoy popularity among niche <a href="https://www.cmarix.com/hire-front-end-developers.html">frontend app developers</a>. Just because there are too many choices, you are likely to find making choice difficult. Considering this, here we are going to shortlist the top Javascript frameworks for frontend development in 2020.

<b>Angular</b>

Angular is probably the only Javascript framework that evolved for so long a time and went through so many phases of improvements. In the coming year, we are going to have Angular 9, the upcoming update of the framework. The new Angular 9 is likely to make the Ivy compiler usable for all apps. The principal benefit of this framework is that it can reduce the app size to a great extent.

Angular in recent years has become very popular for frontend development thanks to the modularity and adaptability. Angular being always a highly flexible framework slowly became an ideal framework for front-end development projects. From the Angular 2 and successive versions, developers could get the Model View Controller (MVC) architecture which further gave Angular a positive push.

Some of the key components of Angular include the following.

-> For using zones within Angular apps, the developers have access to the Zone.js JavaScript library.

-> AngularJS boasts of both TypeScript and CoffeeScript languages for programming.

-> Angular bets on RxJS and the Observable pattern for all server-side communication.

-> For debugging purposes, Angular uses the Augury library.

-> For building server-side apps Angular uses Angular Universal.

<a href="https://www.cmarix.com/which-javascript-framework-will-take-lead-in-2020/">Read More...</a>
rails query
Tags: rails
Published: 2020-01-29 09:34:50

## First of all, Scope is same as Class method

```ruby
def self.with_suger
  where("suger > 0")    
end
```

This is same as

```ruby
scope :with_suger, -> {
  where("suger > 0")    
}
```

and then, use it as class method.

```ruby
BendingMachine.with_suger
```

---
cut in

## #{table_name} is useful 😎
- I'd recommend you to use this, otherwise, you will see this error message when you join and merge the scope with another model scope.
- Especially, when your model name and table name is different, you easily go into confusing. But this way, you'll be still in Object World.

```sh
ActiveRecord::StatementInvalid:
  Mysql2::Error: Column 'created_at' in where clause is ambiguous:
```

```ruby
scope :created_until_the_day, -> (date) {
  where("#{table_name}.created_at < ?",  date)
}
```

---

## 👍 Simple Scope
```ruby
scope :creator_filter, -> {
  where(creator: true)
}
```

```ruby
scope :over_x_years_old, (x)-> {
  where('age >= ?', x)
}
```


## 🦄join table
It makes "Inner Join" on with the relation.
```ruby
scope :with_authored_book, -> {
  joins(:book)
}
```

## 🦄🦄join Multi Scope
```ruby
scope :with_authored_book_and_laptop, -> {
  joins(:book, :laptop)
}
```


## 🐔🐥Hierarchy Scope
```ruby
scope :with_authored_book_of_abc_publisher, -> {
  joins(book: :publisher)
}
```

### 🐔🐥🦄🦄 Hierarchy and multi Scope
```ruby
scope :with_authored_book_of_abc_publisher, -> {
  joins(:laptop, {book: :publisher})
}
```

### 🐔🐥 WHERE with Hierarchy scope
You can write both ways.

```ruby
.where(User.table_name => {name: 'john connor'})
.where("#{User.table_name}.name = ?", 'john connor')
```

## Merge
### without merge
```ruby
joins(:user)
.where("#{User.table_name}.name = ?", 'john connor')
```

or

```ruby
joins(:user)
.where(User.table_name => {name: 'john connor'})
```

### With Merge
```ruby
joins(:user)
.merge(User.where(name: 'john connor'))
```


## EXISTS

```sql
WHERE NOT exists (
  SELECT *
  FROM users
  WHERE users.company_id = :company_id
    AND users.story_id = stories.id
)
```


```ruby
.where(User.joins(:company, :story).where(comapny_id: company_id).exists.not)
```
Wanted: Front-end developer @Yummygum in Amsterdam
Tags: career
Published: 2020-01-29 08:51:19

Are you looking for a front-end position that doesn't feel like work, work!? Somewhere where you bring the nicest designs to life using the latest tech stack? We got you!

> **Note:** The position is not for remote peepz and due to visa restrictions, we can only recruit European Union citizens.


# About us
We're a design studio from Amsterdam. We help startups and established businesses to refine, design and build their digital products. We help clients their business by taking their product to the next level through consult and the craft of design. We love walking the thin line between stunning and usable products. We love forging the bridge from our design to development. With years of experience in front-end development we can turn gorgeous designs into live products with clean code that is on par with todays standards.

# Now about you!
You've finished the first levels of HTML(5) & CSS and you dream of beating the final boss one day. JavaScript and JS Frameworks is what really gets you out of bed in the morning. You know how to commit, push and send Pull Requests and on top of that your team communication skills are on point. You usually think ahead before diving straight into tackling a problem. Some CSS/JS animation experience is a plus.

## You'll be working on
- Code web apps in React and Vue
- Learn how to work in an agile way using JIRA
- Experiment with React Native to code mobile apps
- Manage states using Redux or Vuex
- Style away with Sass
- Generate static websites using Gatsby
- Play with Lighthouse to optimize performance
- Build and test components using Storybook
- Learn how to break your code with E2E and unit testing

## At Yummygum...
- You work with a super modern tech stack
- The office hours are super chill
- We can discuss remote hours
- Everything is a team effort
- You get to work on a lot of different projects
- You get a travel allowance
- You get a competitive salary
- We enjoy a good lunch together (lunch is on us)
- We'll shower you with Yummygum swag


# Get in touch!
Do you think you are the front-end developer we're looking for to join our team? Send us an email including your motivation, your résumé and a link to your GitHub.

[Apply Now](https://yummygum.com/careers/front-end-developer)
Typescript Tips and Tricks
Tags: typescript, oop, productivity
Published: 2020-01-29 08:50:46


Here are two Typescript tricks to make your life as a software developer easier.


## Make an interface that has any number of attributes of a specific type
Ever wondering if you can find a middle ground between the `any` type and of a specific type/interface ?

The answer is yes! 
You can make an interface that contains any number of attributes of a specific type while having the ability to have any attribute name:

```typescript
interface Person {
  name: string;
  age: number;
}

interface FlexInterface {
  [index: string]: Person;
}

// now you can use it like
const Group: FlexInterface = {
  alice: {
    name: 'Alice Byers',
    age: 24
  },
  brian: {
    name: 'Brian Sanders',
    age: 16
  }
};

// still this will fail!

const Group2: FlexInterface = {
  alice: {
    name: 'Alice Byers',
    age: 24
  },
  brian: {
    name: 'Brian Sanders',
    age: 16
  },
 // Type 'string' is not assignable to type 'Person'
  matt: 'Mathew'
};

```

Taking advantage of this technique you can create flexible types without using type `any` !

## Create a type that has a partial match of another type 
This effectively means that we can match any number of properties of a given type:

```typescript

interface Person {
  name: string;
  age: number;
}

type PartialPerson = Partial<Person>;

function updatePerson(personToUpdate: Person, attributes: PartialPerson) {
  return { ... personToUpdate, ...attributes };
}

let person: Person = {
  name: 'John Doe',
  age: 8
};


// this works as expected
const attrs1: PartialPerson = {
  age: 38
};

// this will fail
const attrs2: PartialPerson = {
  hobbies: ['chess', 'swimming', 'coding']
};

person = updatePerson(person, attrs1);

```

**I you have some tips and tricks of your own feel free to share them in the comments below!**


Happy coding :)  


### Credits

Photo by [Yogendra Singh](https://www.pexels.com/@yogendras31?utm_content=attributionCopyText&utm_medium=referral&utm_source=pexels)  from [Pexels](https://www.pexels.com/photo/man-raising-both-his-arms-1701208/?utm_content=attributionCopyText&utm_medium=referral&utm_source=pexels)
How to install Vim on XSERVER
Tags: xserver, vim
Published: 2020-01-29 08:44:26

---
title: How to install Vim on XSERVER
published: true
description: How to install Vim on XSERVER
tags: xserver,vim
---

[XSERVER](https://www.xserver.ne.jp/) is one of the most popular hosting service in Japan.

It is possible to connect to the server via ssh, but Vim is not installed.

I often work with Vim on the server, so I installed Vim using the following steps:

## Step1: Install ncurses

```
mkdir ~/opt && cd $_
wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.1.tar.gz
tar zxfv ncurses-6.1.tar.gz
cd ncurses-6.1
./configure --prefix=$HOME/local
make
make install
```

## Step2: Install Vim

```
cd ~/opt
git clone https://github.com/vim/vim.git
cd vim
./configure --with-features=huge --enable-fail-if-missing --prefix=$HOME/local --with-local-dir=$HOME/local
make
make install
```

## Step3: Setting environment

```
vi ~/.bashrc

# Add alias to .bashrc
export PATH=$PATH:$HOME/local/bin
alias vi='vim'
```

Reload .bashrc

```
source ~/.bashrc
```

Now you can use the `vim` command.

Have a great day👍
Learning In Public
Tags: career, learninpublic
Published: 2020-01-29 09:03:13

---
title: Learning In Public
published: true
date: 2020-01-29 08:37:36 UTC
tags: career, learninpublic
canonical_url: https://giftegwuenu.com/learning-in-public
---

In this video, I share my thoughts on the topic **Learning In Public** and why I have decided to embark on that journey with areas I'm looking forward to improving in my career. 


{% youtube 8VGoj8mrMnY %}

## Resources

 - https://www.swyx.io/writing/learn-in-public/
 - https://www.swyx.io/writing/learn-in-public-hack/
 - https://kentcdodds.com/blog/intentional-career-building
How Recursion works behind the scene in PHP
Tags: php, webdev, recursion
Published: 2020-01-29 08:16:22

Recursion is a programming technique where a function calls itself. Recursion is also a technique of “Making a loop in a functional way”. 
Recursive functions have two parts. “Base case” and “The Recursive function”.

> Recursion in computer science is a method of solving a problem where the solution depends on solutions to smaller instances of the same problem.
>
> Wikipedia

Skeleton of a Recursive function:
```php
function skeleton() {
 	// Base case
  
  	// Recursive function
}
```
Before we move forward, we need to know about **Factorial**.
It’s a mathematical term. The factorial of a positive integer *n*, denoted by *n!* and is the product of all positive integers less than or equal to *n*.
`n! = n * (n – 1) * (n – 2) * (n – 3) * ... .. * 3 * 2 * 1`

Example: `5! = 5 * 4 * 3 * 2 * 1 = 120`
Here,
`5! = n!`, `n = 5`, `(n – 1) = 4`, `(n – 2) = 3`, ... ..


Here are a couple of things about factorial —
1. Can’t be a negative number
2. Factorial of 0 is equal to 1

> ### Full article with Diagram [Click Here](https://blog.abmsourav.com/recursion-in-php/)

Now let’s create a Recursive Function of Factorial —
``` php
function fact($n) {
    // Base case
    if ( $n === 0 ) {
     	return 1;
    }
  
    // recursive function
    return $n * fact( $n - 1 );
}

echo fact(4); // 4 * 3 * 2 * 1 = 24
```

Now, you must be thinking, where is the loop? How it’s iterating and getting data?

When I’ve called `fact(4)` it went into the function and got `fact(3)` and then it went into `fact(3)` and got `fact(2)`... .. and so on. Finally, it went to `fact(0)` and got 1 from the base case.
Then it started returning the value to `fact(1)`, `fact(2)`... .. and so on, that’s why finally `fact(4)` got 6 from `fact(3)`.

{% link https://dev.to/abmsourav/php-class-autoloader-5co4 %}
Introducing Programmable X
Tags: announcement, api, programmable, communications
Published: 2020-04-09 22:21:32

---
title: Introducing Programmable X
published: true
date: 2020-01-29 08:15:42 UTC
tags: announcement, API, programmable, communications
canonical_url: 
---

## API For CSP Wholesale Digital Transformation

Digitizing telecom wholesale requires the right tech tools and knowledge.

A combination of legacy voice (SIP, SS7) and messaging protocols (SMPP) combined with accurate real-time billing (AAA) and business/market know how to complete the solution and enable CSPs to fully automate the wholesale process.

Additionally it to be layered by intuitive APIs for developers to quickly learn and deploy using modern tools.

Programmable X, you can add it into existing workflows to fully automate the process and pioneer wholesale digital transformation.

[Visit ProgrammableX API docs](https://lnkd.in/gcRaDqg) by TelecomsXChange (TCXC) to start your telecom #wholesale digital transformation

### What is Programmable X ?

Programmable X refers to communications service providers (CSPs) utilizing application programming interfaces (APIs) to automate the core actions for telecom wholesale buying and selling, such as interconnection, carrier relations, market opportunity research, ticket escalation, communications, traffic routing control, ratings and reviews, financial settlements for Voice , SMS and Virtual Numbers.

For more information, contact info@telecomsxchange.com

The post [Introducing Programmable X](https://telecomsxchange.com/blog/introducing-programmable-x/) appeared first on [TelecomsXChange Blog](https://telecomsxchange.com/blog).
Power of Webforms in drupal 8 incredible explanation!
Published: 2020-01-29 08:12:37

https://blog.amplexor.com/popular-features-drupal-8-web-forms
Flexibility & freedom, Out-of-the-box functionality and numerous other benefits of using webform for your Drupal Site, that are comprise of enterprise forms. 
#Drupal #Webform 
Web Development, Best Approach
Filter Images in Flutter
Tags: productivity, dart, flutter
Published: 2020-01-29 07:46:22

I've been finding some really interesting "hacks" that have helped me a lot to come up with easy solutions during my internship as a Flutter Dev. 

One such solution was using `ColorFiltered` Widget in Flutter to Filter my images. Initially, our designer could provide any necessary images or assets required to build UI. But the problem came when there were multiple "versions" of the same image. By versions, I mean the same image in different colors and transparency. In fact, if I calculate, there were approximately 15 images that had around 3 versions each that had just color changes. 

That's around 45 images. As a developer, keeping all the images that were only different in color wouldn't make much sense. This would increase the App Size and my work as I would have to manage all the images with their proper locations and whatnot. Apart from that, I would have to load a different image every time, which again doesn't make sense as it would probably add unnecessary load to the App. 

Luckily, Flutter has the widget called `ColorFiltered` that can handle all of that for me. Here's what I did. 

I had this original image:

<img src="https://dev-to-uploads.s3.amazonaws.com/i/es6olx9enzdsmacarj5s.png" width=100px height=100px>

And this was one of the versions of the same image: (Ignore the background)
<img src="https://dev-to-uploads.s3.amazonaws.com/i/0y8065odea8uskqpj532.png" width=100px height=100px>


Similarly, as stated before, there were 15 different images and 3 such "versions" of these images. Here's an example for the above 2 images I used in Flutter.

```
ColorFiltered(
child: Image.asset("assets/images/originalImage.png", scale: 5,),
colorFilter: ColorFilter.mode(Colors.white, BlendMode.srcIn),)
),
```

The `ColorFiltered` widget has the `colorFilter` property that we can use to add filters to a Widget. I added a white color and used `BlendMode` class that can be used to blend pixels. `srcIn` is just a property that overlaps both the color and on the original image. There are a lot of properties for the `BlendMode` class that are provided by the folks at Flutter and you can check them out [here](https://api.flutter.dev/flutter/dart-ui/BlendMode-class.html).

This gave me exactly the image I wanted: <img src="https://dev-to-uploads.s3.amazonaws.com/i/0y8065odea8uskqpj532.png" width=100px height=100px>


With just 2 lines of code, I was able to reduce around 45 images 15, and what's better? I didn't even have to trouble the designer for the images and did it myself without much hassle and the help of Flutter, of course!
Add Firebase Authentication to React App
Published: 2020-01-29 07:01:08

<h3>Introduction</h3>
<p>In this article, we will be adding a Firebase to a React App, I will get straight to the point assume you are not a beginner </p>
I<h3>Pre-requisites</h3>
<li>Recent versions of Node.js and npm installed on your system</li>
<li>knowledge of JavaScript/ES6</li>
 <li> Intermediate Knowledge of React</li>

<h3>Firebase </h3>
Start creating a <a href="https://console.firebase.google.com/">Firebase project</a> and go to the Authentication page.
Click on the “Sign-in method” tab and make sure you have email/password enabled as a sign-in provider.


<code>
   $ npm install -g rekit
</code>



 <li> Create an app</li>
<code>
   $ rekit create my-app
   $ cd my-app
   $ npm install

</code>
 <li> Run It!</li>
<code>

   $ npm start

</code>
</ol>

<h3><strong>Deploying The GraphQL Server</strong></h3>
In case you have not already installed the Rekit Boilerplate
<ol>
<li>Install Rekit</li>

<code>
   $ npm install -g rekit
</code>



 <li> Create an app</li>
<code>
   $ rekit create my-app
   $ cd my-app
   $ npm install

</code>
 <li> Run It!</li>
<code>

   $ npm start

</code>
</ol>
Build a web app with GraphQL and React
Published: 2020-01-29 06:38:52

<h3>Introduction</h3>
<p>In this article, we will be build a react app that will be consuming data from GraphQL as opposed to the older RESTful API</p>
We will be doing it with a cool react boilerplate, <a href="https://rekit.js.org/docs/get-started.html" target="_blank">Rekit</a>.

<h3>Why GraphQL?</h3>
GraphQL is a query language for APIs that offers the advantages of being self-documenting where you choose to request only what you need as opposed to Restful API which can great very robust. GraphQL  makes it easier to evolve APIs over time, and enables powerful developer tools.

<h3>Pre-requisites</h3>
<li>Recent versions of Node.js and npm installed on your system</li>
<li>knowledge of JavaScript/ES6</li>
 <li> Intermediate Knowledge of React</li>



<h3><strong>Creating The React Client</strong></h3>
I will also be making sure of a popular graphql boilerplate, ensure you git installed
<ol>
<li>git clone https://github.com/graphql-boilerplates/react-fullstack-graphql</li>

<code>
   $ npm install -g rekit
</code>



 <li> Create an app</li>
<code>
   $ rekit create my-app
   $ cd my-app
   $ npm install

</code>
 <li> Run It!</li>
<code>

   $ npm start

</code>
</ol>

<h3><strong>Deploying The GraphQL Server</strong></h3>
In case you have not already installed the Rekit Boilerplate
<ol>
<li>Install Rekit</li>

<code>
   $ npm install -g rekit
</code>



 <li> Create an app</li>
<code>
   $ rekit create my-app
   $ cd my-app
   $ npm install

</code>
 <li> Run It!</li>
<code>

   $ npm start

</code>
</ol>
Auto-alias Your Repos (with autocomplete)
Tags: bash, linux, productivity
Published: 2020-01-29 06:28:14

Found this note about [Auto-alias Your Repos](https://dev.to/nickelkr/auto-alias-your-repos-5epo), while this is very fast but I've another handy code to do the same. Check it out.

All my projects is under `dev` directory in the `$HOME` path, I've this code in my `~/.bash_profile`:

```bash
#~/.bash_profile

goto() {
   cd "$HOME/dev/$1" 
}
_goto() {
  COMPREPLY=()
  local word="${COMP_WORDS[COMP_CWORD]}"
  local comps=$(dir $HOME/dev)
  COMPREPLY=( $(compgen -W "${comps}" -- ${word}) )
}
complete -f -F _goto goto
```

Now I can jump in any project folder under the `dev` with autocomple:

```bash
~ >  goto b<TAB>
bench_redis_fdb  bigboy           botmaster
bfm              bitpayer
```

Use it!