teleren/devto huggingface dataset:
How to convert string to binary in python
Tags: python, binary, string, binarytostring
Published: 2021-05-07 16:09:14

**Strings** are an array of Unicode code characters.

**Binary** is a base-2 number system consisting of 0's and 1's. The computer understands binary. The computer sees the string in binary format i.e **'H'=1001000**.
 
The string as seen by the computer is a binary number which is an **ASCCI value( Decimal number)** of the string converted to binary.

#### String to binary
To convert a string to binary we first append( join ) the string's individual **ASCII values** to a list `l`  by using the function `ord(_string)`. 

The function `ord(_string)` gives the **ASCII value** of the string. i.e *ord(H) = 72* , *ord(e) = 101*.

Then from the list of **ASCII values** we convert them to binary by using the function `bin(_integer)`.

The function `bin(_integer)` converts decimal number to a binary number.
i.e `bin(72) = 1001000`

Then append(add) these binary values to a list `m`. Then the list `m` now consists of the binary numbers from the strings given and can be returned or printed.

```import math

def toBinary(a):
  l,m=[],[]
  for i in a:
    l.append(ord(i))
  for i in l:
    m.append(int(bin(i)[2:]))
  return m

print("''Hello world'' in binary is ") 
print(toBinary("Hello world"))
Compress String with Run Length Encoding in Java
Tags: java, encoding
Published: 2021-05-07 16:03:19

https://grokonez.com/java/compress-string-run-length-encoding-java

Compress String with Run Length Encoding in Java


In this Java example, we're gonna know how to compress String in Java with Run Length Encoding (RLE) method.

Related Posts:
- <a href="https://grokonez.com/java/java-core/java-regular-expression-overview-syntax">Java Regular Expression Overview – Syntax</a>
- <a href="https://grokonez.com/java/java-core/java-regular-expression-to-extract-data-from-string">Java Regular Expression to extract data from a Text</a>
- <a href="https://grokonez.com/java/java-core/java-regular-expression-to-mask-information-from-a-text">Java Regular Expression to mask information from a Text</a>

<!--more-->
<h2>Run Length Encoding</h2>
- RLE is a very simple form of data compression.
- It produces sequences in which the same data values occurs in data elements are stored as a single data value and a counter. For example, AAABB => 3A2B.
- RLE is suitable to use for:
+ palette-based bitmap images such as computer icons or
+ black points collection on a solid white background for example:

<img src="https://grokonez.com/wp-content/uploads/2018/03/run-length-encoding-java.png" alt="run-length-encoding-java" width="379" height="372" class="alignnone size-full wp-image-11287" />
<h2>Implementation</h2>
Encoding is very simple. For decoding, we use <a href="https://grokonez.com/java/java-core/java-regular-expression-overview-syntax">Regular Expression - Regex</a>.

More at:
https://grokonez.com/java/compress-string-run-length-encoding-java

Compress String with Run Length Encoding in Java
Kotlin – How to read/write CSV file with OpenCSV
Tags: kotlin, csv, opencsv
Published: 2021-05-07 15:58:45

https://grokonez.com/kotlin/kotlin-how-to-read-write-csv-file-with-opencsv-example

Kotlin – How to read/write CSV file with OpenCSV

In this tutorial, we're gonna look at Kotlin examples that read and write CSV file using OpenCSV.

<!--more-->
<h2>I. Dependency</h2>
<pre><code class="language-html">&lt;dependency&gt;
	&lt;groupId&gt;org.jetbrains.kotlin&lt;/groupId&gt;
	&lt;artifactId&gt;kotlin-stdlib&lt;/artifactId&gt;
	&lt;version&gt;1.2.21&lt;/version&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
	&lt;groupId&gt;com.opencsv&lt;/groupId&gt;
	&lt;artifactId&gt;opencsv&lt;/artifactId&gt;
	&lt;version&gt;4.0&lt;/version&gt;
&lt;/dependency&gt;</code></pre>
<h2>II. Write Data to CSV File</h2>
<h3>1. From String Array</h3>
<pre><code class="language-java">
var fileWriter = FileWriter("customer.csv")

csvWriter = CSVWriter(fileWriter,
		CSVWriter.DEFAULT_SEPARATOR,
		CSVWriter.NO_QUOTE_CHARACTER,
		CSVWriter.DEFAULT_ESCAPE_CHARACTER,
		CSVWriter.DEFAULT_LINE_END)
		
val data = arrayOf<String>("ID","NAME","ADDRESS","AGE")
csvWriter.writeNext(data)
</code></pre>
<h3>2. From List of Objects</h3>

More at:

https://grokonez.com/kotlin/kotlin-how-to-read-write-csv-file-with-opencsv-example

Kotlin – How to read/write CSV file with OpenCSV
React World
Published: 2021-05-07 15:48:13

About:

React is a JavaScript “library”. It is not exactly a “framework”.Building User interfaces is the main focus of React.React following Unix Philosophy.React became more popular todays because of it created a common language between developers and browsers that allows developers to declaratively describe UIs and manage actions on their state instead of actions on their DOM elements.

React’s Popularatity Reason:

1)React basically acts like user agent who will do the communication with the DOM on their behalf.
2)React is often given the “Just JavaScript” label. This means it has a very small API to learn and after that one's JavaScript skills are what make him/her a better React developer. 
3)Learning React pays off big-time for iOS and Android mobile applications as well. React Native allows one's to use his/her React skills to build native mobile applications.

API using method:

The ReactDOM.render method and React.createElement method are the core API methods in a React application.A React web application cannot exist without using both of these methods.

ReactDOM.render:

This is basically the entry point for a React application into the browser’s DOM. It has 2 arguments:
1)The first argument is WHAT to render to the browser. This is always a “React element”.
2)The second argument is WHERE to render that React element in the browser.

React.createElement:

Representing DOM elements with object instead of string is known as React.createElement method.The React.createElement function has many arguments:
1)The first argument is the HTML “tag” for the DOM element to represent, which is div in this example.
2)The second argument is for any attributes (like id, href, title, etc.) we want the DOM element to have. The simple div we’re using has no attributes, so we used null in there.
3)The third argument is the content of the DOM element. We’ve put a “Hello React” string in there.

Nesting React elements:

DOM API and React API are two node controlling method.Major diffrences between two methods are,in the HTML version we used a string to represent the DOM tree, while in the React version we used pure JavaScript calls and represented the DOM tree with an object instead of a string.

JSX:

Fundamentally, JSX just provides syntactic sugar for the React.createElement(component, props, ...children) function.The first part of a JSX tag determines the type of the React element.

defaultProps:

defaultProps can be defined as a property on the component class itself, to set the default props for the class. This is used for undefined props, but not for null props.Example:
class CustomButton extends React.Component {
  // ...
}

CustomButton.defaultProps = {
  color: 'blue'
};
Here,if props.color is not provided it's default value will be 'blue'

State:

The state contains data specific to this component that may change over time. The state is user-defined, and it should be a plain JavaScript object.

Create React App:

Using "create react app" command we can build react app.Then running 'npm run build' will create a production build of programmer app in the build/ folder of programmer project.
5 Reasons Tailwind might not be the right choice. (WDS #1)
Tags: webdev, css, tailwindcss
Published: 2021-05-07 15:47:33

*Disclaimer this is 100% satire. For fun on a Friday (Web Dev Satire #1)*

# 1) The license is too controlling 
![Screen Shot 2021-05-07 at 11.16.35 AM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/brvprqg1kddu4vs9ub2v.png)
  The fact I have to sign a blood contract to use Tailwind is baffling. I'm hoping this is fixed in a future release. Until then, I'm trying to skate by, but Adam Wathan keeps calling me.

---

# 2) Readability 
My vision is pretty good with my glasses, but Tailwind's docs' most recent update recommends not looking at your code. Instead, you need to feel your code through your fingertips. I keep trying, but every time I look up, my code is a mess. It's not my fault. It's Tailwinds.

---

# 3) Not enough Support
The TailwindUI team is not putting out enough content. Components for React & Vue. What about components for AngularJS 1.X? Not to mention it doesn't support currently support Netscape browser, the largest browser of 1996. There are no plans to support Netscape in the future. It's disappointing.

---

# 4) Tailwind is forcing me to use it
Despite how much I **hate** Tailwind. I have to use it; there are no alternatives out there. If only there was some way I could use some other sort of styling. I'd name it CSS, Cascading Style Sheets; it would be revolutionary. Alas, there is nothing else I can use. 

---

# 5) There aren't enough articles bashing Tailwind.
Every article I see about Tailwind is by people who completely understand it and love it. Where are all the naysayers? Its clear Tailwind is brainwashing developers. They won't get me and my tinfoil hat anytime soon.

---

*In case it isn't clear by now, this is satire! Web Dev has gotten so full of uninformed opinions, I thought I'd poke some fun. To the Tailwind team, you're great. To the people who hate Tailwind, cool. Happy Friday!*
Kotlin get File Name example
Tags: kotlin, filename
Published: 2021-05-07 15:46:35

https://grokonez.com/kotlin/kotlin-get-file-name-example

Kotlin get File Name example

This Kotlin tutorial shows you ways to get File Name from full path with Kotlin Regex and extension functions.

<!--more-->
<h2>I. Technology</h2>
- Java 1.8
- Kotlin 1.1.2
<h2>II. Practice</h2>
<h3>1. Using Regex</h3>
<pre><code class="language-java">
package com.javasampleapproach.filename

fun main(args: Array<String>) {

	val fullPath = "JavaSampleApproach/Kotlin/Practice/getFileNameExample.kt"

	val regex = """(.+)/(.+)\.(.+)""".toRegex()
	val matchResult = regex.matchEntire(fullPath)

	if (matchResult != null) {
		val (directory, fileName, extension) = matchResult.destructured
		println("dir: $directory | fileName: $fileName | extension: $extension")
	}
}
</code></pre>
Result:
<pre><code class="language-java">
dir: JavaSampleApproach/Kotlin/Practice | fileName: getFileNameExample | extension: kt
</code></pre>
<h3>2. Using Kotlin String extension function</h3>

More at:
https://grokonez.com/kotlin/kotlin-get-file-name-example

Kotlin get File Name example
What is the comparison operators in PHP.
Tags: php
Published: 2021-05-07 15:44:53

Comparison operators will compare multiple values among themselves on the name. For example, is a variable in `$a` the same as `$b`? Or bigger? We will make comparisons with these operators.

Let's show the comparison operators on a table:

| Operator |          Name          | Usage     |
|:--------:|:----------------------:|-----------|
|    ==    |          Equal         |  $a == $b |
|    ===   |       Equivalent       | $a === $b |
|    !=    |        Not equal       |  $a != $b |
|    !==   |     Not equivalent     | $a !== $b |
|     <    |         Smaller        |  $a < $b  |
|     >    |         Bigger         |  $a > $b  |
|    <=    |     Small and equal    |  $a <= $b |
|    >=    | Greater than and equal |  $a >= $b |

In the comparison operator, the double equal sign, there is a small detail to consider. A double equal sign is used to compare two values, and a single equal sign is used to assign a value. So make sure you don't make odd equals when you want to use the equals double equals operator.

Follow my blog for more [baransel.dev](https://baransel.dev/).
Kotlin – How to read File with Kotlin language
Tags: kotlin, readfile
Published: 2021-05-07 15:41:52

https://grokonez.com/kotlin/kotlin-read-file-kotlin-language

Kotlin – How to read File with Kotlin language

This tutorial shows you how to read File in Kotlin using <code>InputStream</code> or <code>BufferedReader</code>.

<!--more-->
<h2>I. Technology</h2>
- Java 1.8
- Kotlin 1.1.2
<h2>II. Overview</h2>
<h3>1. Goal</h3>
Read file: <em>all lines</em>/<em>by line</em> using <code>InputStream</code> or <code>BufferedReader</code> or <code>File</code> directly.
<h3>2. Steps to do</h3>
- Create:
+ <code>InputStream</code> from <code>File</code>, then get <code>BufferedReader</code> using <code>bufferedReader()</code> method
+ <code>BufferedReader</code> from <code>File</code>.
- Use:
+ <code>Closeable.use()</code> method with <code>Reader.readText()</code> method inside block. <code>Closeable.use()</code> will automatically close the input at the end of the lambda's execution:
<pre><code class="language-java">
String = (Reader implements Closeable).use(Reader.readText())
</code></pre>
+ <code>Reader.useLines()</code> method with Kotlin <code>Sequence</code> (a sequence of all the lines) inside block. <code>Reader.useLines()</code> will automatically close the reader once the processing is complete:
<pre><code class="language-java">
Reader.useLines(block: Sequence)
</code></pre>
+ <code>File.useLines()</code> method with Kotlin <code>Sequence</code> (a sequence of all the lines) inside block. It will close the reader once the processing is complete:
<pre><code class="language-java">
File.useLines(block: Sequence)
</code></pre>
+ <code>File.readLines()</code> method to return a <code>List&#60;String&#62;</code>:
<pre><code class="language-java">
File.readLines()
</code></pre>
<h2>III. Practice</h2>
<h3>0. kotlin.txt</h3>

More at:

https://grokonez.com/kotlin/kotlin-read-file-kotlin-language

Kotlin – How to read File with Kotlin language
I Didn't Put My Earnings Back Into My Startup. Here's Why
Published: 2021-05-07 15:31:23

When you are bootstrapping a startup, and you first start making money, it's straightforward advice to put “the money back into the startup.” It shows commitment to grow, they say.

I found it to be precisely the opposite. For me, I decided to take the first thousand dollars and paid myself.

The reason was this:

When I started, my big goal was to get to a modest couple of thousand dollars of recurring revenue per month. Probably enough to match my salary and quit my day job. That goal, amongst creating a great product that people used, charged me up, and kept me going. When I achieved it, there was a great sense of relief. And the monthly recurring revenue kept growing past my goal, and the spirit of assistance turned into confidence.

I didn’t like that.

I needed that goal back again. I need the feeling of the climb from zero to 2–3k back again.

So I made it that. I took the money away from the company and paid myself. So I better build the recurring revenue back up again.

I know this is pretty silly, even stupid but anything to keep the interest going in the beginning stages.

Startups fail not because of a lack of money, but because the founders quit. They lose interest, drive, challenge, and accept defeat. It has happened to me many times before. Not that I would have stopped this time around, but it’s fun to have a laser beam to chase.

Keeping the heart in the business is more important than saving money.

I am the founder of Proxies API and if I can do it, you can too
Ruby Call Path Analysis using TracePoint
Tags: ruby
Published: 2021-05-07 15:28:37

During a recent diagnostic analysis exercise I needed to identify if there was additional "work" being done based on a single option being changed. As Ruby offers numerous productivity tools for developers it should come as no surprise that a mechanism to easily produce a full call stack for one to many operations exists.

The code below is using the [MongoDB Ruby Driver](https://docs.mongodb.com/ruby-driver/master/) and [Mongoid ODM](https://docs.mongodb.com/mongoid/current/) to [`$sample`](https://docs.mongodb.com/manual/reference/operator/aggregation/sample/) a single document with a [Read Preference](https://docs.mongodb.com/manual/core/read-preference) passed in from the command line. The collection likely won't exist however the goal of this analysis was simply to see what differences changes the read preference would expose.

For the purposes of my analysis I wanted to produce a [diff](https://en.wikipedia.org/wiki/Diff) of two call stacks to try and see "where" there may be a difference in the amount of "work" being performed. To do this the first step was to introduce instrumentation via a [TracePoint](https://ruby-doc.org/core-2.7.0/TracePoint.html).

```ruby
# test.rb
# ruby test.rb [primary|secondary]
require 'bundler/inline'
gemfile do
  source 'https://rubygems.org'

  gem 'mongoid', '7.0.4'
  gem 'mongo', '2.11.1'
end

Mongoid.configure do |config|
  config.clients.default = { uri: "mongodb+srv://..." }
end

class Sample
  include Mongoid::Document
end

def with_tracepoint
  trace = []
  tp = TracePoint.new(:call) do |x|
    trace << "#{x.defined_class}##{x.method_id.to_s} @ #{x.path}"
  end
  tp.enable
  yield
  return trace
ensure
  tp.disable unless tp.nil?
end

# first argument to symbol
read_pref = ARGV[0].nil? ? :primary : ARGV[0].to_sym
# run first command to establish a connection
Sample.collection.aggregate([{ :'$sample' => { size: 1 } }], read: { mode: read_pref }).first
trace = with_tracepoint do
  Sample.collection.aggregate([{ :'$sample' => { size: 1 } }], read: { mode: read_pref }).first
end

puts trace
```

The above will trace all Ruby method calls executed within the block and push them in to an array. By running the above script twice with different options and feeding the results into a `diff` tool (such as [`icdiff`](https://www.jefftk.com/icdiff)) a visual representation of how the call stacks differ can be generated.

```bash
icdiff -N <(ruby test.rb primary) <(ruby test.rb secondary) | less
```

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zyxqka258k4cjnoefhua.png)

(Open screenshot in a new tab to get a better look)

The `with_tracepoint` helper method in the script above is only filtering on `:call`s, however can easily be modified to filter based on your particular needs (see [TracePoint Events](https://ruby-doc.org/core-2.7.0/TracePoint.html#class-TracePoint-label-Events) for the full list).

Let me know if this approach helped you troubleshoot a particular issue or identify an interesting defect.

Happy Coding!
PHP Error Log Exporter for Prometheus with Grafana dashboard
Tags: prometheus, grafana, php
Published: 2021-06-09 10:21:37

---
title: PHP Error Log Exporter for Prometheus with Grafana dashboard
published: true
date: 2021-05-07 15:22:21 UTC
tags: prometheus,grafana,PHP
canonical_url: https://daniele.tech/2021/05/php-error-log-exporter-for-prometheus-with-grafana-dashboard/
---

Grafana with Prometheus is a good way to profile your customers wbsite when you do support for them. Let's see some real examples!

The post [PHP Error Log Exporter for Prometheus with Grafana dashboard](https://daniele.tech/2021/05/php-error-log-exporter-for-prometheus-with-grafana-dashboard/) appeared first on [Daniele Mte90 Scasciafratte](https://daniele.tech/eng).
Kotlin – How to read/write Excel file with Apache POI
Tags: kotlin, apachepoi, excel, file
Published: 2021-05-07 15:17:59

https://grokonez.com/kotlin/kotlin-read-write-excel-file-apache-poi-example

Kotlin – How to read/write Excel file with Apache POI

In this tutorial, we're gonna look at Kotlin examples that read and write Excel file using Apache POI.

<!--more-->
<h2>I. Dependency</h2>
<pre><code class="language-html">&lt;dependency&gt;
	&lt;groupId&gt;org.jetbrains.kotlin&lt;/groupId&gt;
	&lt;artifactId&gt;kotlin-stdlib&lt;/artifactId&gt;
	&lt;version&gt;1.2.21&lt;/version&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
	&lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
	&lt;artifactId&gt;poi-ooxml&lt;/artifactId&gt;
	&lt;version&gt;3.17&lt;/version&gt;
&lt;/dependency&gt;</code></pre>
<h2>II. Write Data to Excel File</h2>
- Simple POJO <strong>Customer</strong> (id, name, address, age):
<pre><code class="language-java">
package com.javasampleapproach.kotlin.apachecsv

class Customer {
	var id: String? = null
	var name: String? = null
	var address: String? = null
	var age: Int = 0

	constructor() {}
	constructor(id: String?, name: String?, address: String?, age: Int) {
		this.id = id
		this.name = name
		this.address = address
		this.age = age
	}

	override fun toString(): String {
		return "Customer [id=" + id + ", name=" + name + ", address=" + address + ", age=" + age + "]"
	}
}</code></pre>
- Write to Excel file:

More at:
https://grokonez.com/kotlin/kotlin-read-write-excel-file-apache-poi-example

Kotlin – How to read/write Excel file with Apache POI
The excitement of making things real
Tags: motivation, watercooler, devjournal
Published: 2021-05-07 15:17:38

A software engineer career started for me in 2001 when I joined a tiny start-up company as a junior developer. Since then I was working in different companies and different roles. There is one thing that is still *every time* magical and makes me feel like a kid.

<!--more-->

It didn't change over all these years and it's a feeling of excitement of making things real. Those things that you sketch on a whiteboard, discuss with colleagues or friends, implement and re-implement in the code, and then finally see them happening.

Let me share a story that happened recently.

This time I was working together with [@driv3r](https://github.com/driv3r) on a project that connects multiple apps (including a third-party one). After a couple of weeks of planning, collecting requirements, communicating with other teams involved, changing existing code, and creating a new app, everything was ready for the first test run. Of course, all components of the project were tested individually, but it isn't the same as to turn on the whole thing and see if it works as expected.

The third-party app was supposed to make the initial request to one of our API endpoints and that should be triggering a few interactions between other apps, and at some point, the third party should be getting a request back from our system.

Everything is deployed and waiting for that initial request. Click a button in the third-party app. A couple of messages between our internal apps. And 2-3 seconds later the third party receives a call back from our system. EVERYTHING WORKS!

It's exciting to see how everything works exactly as planned! It doesn't matter if you are 99% sure that everything should just work anyway (because you've spent time checking every component and connection). It doesn't matter if the project is big or small.

It's **always** exciting to see how the results of your work become alive!

From the outside it looks like this:

{% youtube mqp8_ROAIJY %}

---

That's the moment when you feel yourself as a kid, and it's amazing. Keep making things and be excited about them becoming real! :smile:
React Js 
Published: 2021-05-07 15:13:51

1.React Js
It is a JavaScript library. It is the most popular JavaScript Library for front-end development. React use for cross-browser like as web, android, etc.

2.Components
It is a kind of kernel in all react-based applications. The basic structure of a component is a plain JavaScript function.

3.React DOM
React works as a performer to communicate with DOM.

4.React hook
Hook is a special function.Example: useState,useEffect

5.State
A state is a JavaScript object. State modify by some special function.

6.React Fragments
Its use when multiple element rendering in a component which is a single parent. It helps not to use an extra node.

7.Props
React components passed data by props. Props declare inside component calls and use in the same syntax as HTML attributes-props='value'

8.state
Specific data contains in the state. Components change over time. It is a plain JavaScript object.

9.forceUpdate()
When the props state changes, the component will re-render.Then use forceUpdate for re-rendering.
components.forceUpdate(callback)

10.wrap-up
The component receives all the props of the container. Actually The component we want to wrap with the wrapper function. It returns wrapped components.