teleren/devto huggingface dataset:
Laravel on Ubuntu 20 in 9 commands
Tags: laravel, digitalocean
Published: 2020-05-27 06:12:22

---
title: Laravel on Ubuntu 20 in 9 commands
published: true
description: 
tags: laravel,digitalocean
---

```
# Update 
apt update

# Install PHP and all the extensions
sudo apt-get install php7.4-{bcmath,bz2,intl,gd,mbstring,mysql,zip,dom} php -y

# Install composer
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Go to web root
cd /var/www/html

# Copy Laravel your laravel project here (we'll create an new example)
composer create-project laravel/laravel

# Edit the apache config
vi /etc/apache2/sites-enabled/000-default.conf

# Change doc root to laravel
- DocumentRoot /var/www/html # From this
+ DocumentRoot /var/www/html/laravel/public # To This

# Reload apache
service apache2 reload

# Set the proper file permissions
chown -R www-data:www-data /var/www/html/
```
How to detect abnormal memory usage and memory spikes in Android Apps
Tags: android, bugs, apps, memory
Published: 2020-05-27 05:45:07

Abnormal memory usage and spikes will pull down the app performance. Given the variety of android devices out there in the market, it's challenging to test all scenarios. Hence it becomes important to capture the bugs as and when they happen in production.

This blog explains in detail about how Finotes can detect abnormal memory usage and memory spikes. Of course, it detects memory leaks too.

https://www.blog.finotes.com/post/how-to-detect-abnormal-memory-usage-and-memory-spikes-in-android-apps
Codebytes: Caching mongoose models in Redis (MongoDB).
Tags: codebytes, mongodb, mongoose, redis
Published: 2020-05-27 05:15:59

---
title: Codebytes: Caching mongoose models in Redis (MongoDB).
published: true

tags: Codebytes, MongoDB, mongoose, Redis
---

Ever considered caching your mongoose models in a super caching tool like Redis to avoid frequent MongoDB hit and refrained from doing that because you may lose the mongoose object privileges like calling model._id as model.id or model.toObject() or the superior one **model.populate()** and others.

Here comes the saviour,
https://mongoosejs.com/docs/api.html#model_Model.hydrate

> Hydrate method in mongoose API converts your raw JSON data into the mongoose model object(s).

Example: Simple model

```
// set cache

let todo = Todo.findById(id);
redis.set(key, todo); // stores as raw json

// read cache

let todoCache = redis.get(key); // returns raw json
let todo = Todo.hydrate(todoCache); // converts in to mongoose model

let createdBy = todo.populate('createdBy'); 
```

Example: Array of models

```
// set cache

let todos = Todo.findAll();
redis.set('todos', todos); // stores as array of son

// read cache

let cachedTodos = redis.get('todos'); // returns array of json
let todos = cachedTodos.map(todo => Todo.hydrate(todo)); // converts in to mongoose model

let incompleteTodos = todos.filter(todo => !todo.isDone);
```
Jsoning - A simple key-value JSON-based persistent lightweight database.✨
Tags: node, npm
Published: 2020-05-27 05:08:59



<img src="https://raw.githubusercontent.com/khalby786/jsoning/master/media/jsoning.svg" alt="jsoning" width="250px">

✨ A simple key-value JSON-based lightweight database. ✨

<br />


Jsoning is a simplified wrapper for Node.js that lets you write and read data to and from JSON files. It's designed to be beginner-friendly and easy to use, with a simple API that makes it easy to get started with. It's perfect for small projects, prototyping, and learning how to work with databases.


## Features

- Use existing JSON files to read and write key-value pairs
- EventEmitters to listen to changes in the database
- Atomic file writing to prevent data corruption
- Easier to use than a toaster
- TypeScript support for all the fixed-type addicts out there

## Install

**Node.js v16.x or greater is required for this package to work.**

```bash
npm i jsoning

# pnpm if you're feeling fast
pnpm i jsoning

# yarn if you're feeling fancy
yarn add jsoning
```

View the full documentation [here](https://jsoning.js.org/).

## Basic Usage 

```ts
import { Jsoning, MathOps } from 'jsoning';
const db = new Jsoning('database.json');

// Set some values with a key
await db.set('birthday', '07-aug');
await db.set('age', '13');

// Push stuff to an array for a particular key
await db.push('transformers', 'optimus prime');
await db.push('transformers', 'bumblebee');
await db.push('transformers', 'iron hide');

// Get the value of a key
console.log(await db.get('transformers')); // [ 'optimus prime', 'bumblebee', 'iron hide' ]

// Get all the values
console.log(await db.all()); // { Record<string, JSONValue> of the whole database contents }

// does such a value exist?
console.log(await db.has('value2')); // false

// My age keeps changing, so I'm deleting it
console.log(await db.delete('age')); // true

// I got $100 for my birthday
await db.set('money', 100);

// and someone gave me $200 more
await db.math('money', MathOps.Add, 200);

// Just wanna make sure how much money I got
console.log(await db.get<number>('money')); // 300

// RIP iron hide, he died
await db.remove('transformers', 'iron hide');

// I'm getting bored, so I'm clearing the whole database
await db.clear();
```
Struct ง่ายนิดเดียว
Published: 2020-05-27 04:52:48

วันก่อน มีโอกาสได้ Pair programing กับ pongneng พี่อธิบายถึงเรื่องของ Struct ให้ฟัง ซึ่งเข้าใจง่ายมาก เลยอยากจะขอจดเก็บเอาไว้หน่อย

### **Struct คืออะไร**

struct มันคือ type ที่เก็บรวบรวม field ต่างๆ เพื่อที่จะจัดกลุ่ม data เข้าไว้ด้วยกัน อธิบายง่ายๆ มันเหมือนเป็นกล่องใบหนึ่ง ที่ให้เรามัดของที่เกี่ยวข้องกัน ยัดใส่ลงไป

![Struct](https://dev-to-uploads.s3.amazonaws.com/i/r6ssbwcp4xzd1icqijws.jpg)

เริ่มต้นเรื่อง โดยปูพื้นฐานเรื่องของตัวแปร(Variable) กันก่อนเลย โดยพี่เล่าว่า  ปกติเราประกาศ ตัวแปรใน ภาษา go มี 2 แบบ ดังด้านล่างนี้

```go
// ประกาศตัวแปรแบบเต็ม
var bookTitle string
var price float32
var stock int
var available bool

bookTitle = "Clean Code"
price = 22.53
stock = 33
avaliable = true
```

```go
// แบบ short หรือสายย่อ
bookTitle := "Clean Code"
price := 22.53
stock := 33
avaliable := true
```

จากนั้น เราอยาก composite data เพื่อ group มันเข้าด้วยกัน วิธีการนี้ ในทางภาษา Go เราจะใช้การ Declare Struct เพื่อที่จะให้สามารถ group fields เข้าไว้ด้วยกันได้ โดยประกาศให้มันเป็น type sturct แบบนี้

```go
type Book struct {
	bookTitle string
	price float32
	stock int
	available bool
}

```

ต่อมาเราอยาก สร้าง function ที่ชื่อว่า `isAvailable` ที่จะคอยเช็คว่า หนังสือนั้นใช้งานได้หรือเปล่า สิ่งที่เราจะทำ คือ การ pass object ของ Book มา เพื่อที่จะดูว่าค่า available ว่ามันเป็น true หรือ false

```go
func isAvailable(b *Book) bool {
	return b.available
}
```

แต่...ช้าก่อน  ถ้าเราสังเกตดีๆ เราไม่ควรที่จะต้องส่ง object ของ Book มา แต่ isAvailable ควรจะรู้จักกับ Book ได้เองเลย หรือถ้าเข้าใจง่ายๆ คือ ฟังก์ชัน `isAvailable` มันเป็นส่วนหนึ่งของ Book เสมอ 

เราเลยต้องทำให้ `isAvailable` มันสามารถเรียกผ่าน object ของ Book ได้เอง โดยวิธีการทำง่ายมาก คือ เราจะย้าย `(b *Book)` มาวางไว้หน้าชื่อฟังก์ชันเพื่อระบุว่า มันเป็น method ของ Book 

```go
func (b *Book)isAvailable() bool {
	return b.available
}
```

เพียงเท่านี้ เราเองก็สามารถที่จะเรียกใช้งาน `isAvailable` ผ่าน book ได้แล้ว

```go
func main() {
	b := Book{}
	b.bookTitle = "Clean Code"
	b.price = 22.53
	b.stock = 33
	b.available = true
        
// เราสามารถเรียก isAvailable ผ่าน object Book ได้แล้ว
// จากเดิมแทนที่เราเองต้องเรียก isAvailable(b) --> b.isAvailable()
	b.isAvailable()
}
```

---

### **สรุป**

Struct เป็น type ที่ Go สร้างขึ้นมา เพื่อที่จะนำเอาข้อมูลที่อยู่ในโดเมนเดียวกันมามัดใส่เป็นก้อน
ส่วนการระบุ method ของ type โดยประกาศชื่อ type ด้านหน้าของ method นั่นเอง

```go
package main

import "fmt"

type Book struct {
	bookTitle string
	price     float32
	stock     int
	available bool
}

func (b *Book) isAvailable() bool {
	return b.available
}

func main() {
	b := Book{}
	b.bookTitle = "Clean Code"
	b.price = 22.53
	b.stock = 33
	b.available = true

	fmt.Println(b.isAvailable())
}

```
What is the Starting row number and Column Number I should be giving to map the error in star book
Tags: Mainframe, cics, star, testing
Published: 2020-05-27 03:56:14

After doing MSSU(STYB-KEY) FR12, I am getting an error in the region job file.I have created xdc of CFSUPD as it is an update file.But when I open the file in STAR TOOL,To map the error using a copy book I don't know how to proceed with it. Can you please help me out with this. What is the Starting row number and Column Number I should be giving
BIAS (Bluetooth Impersonation AttackS)
Tags: Bluetooth, codenewbie, virus, hacktoberfest
Published: 2020-05-27 03:50:21

New BIAS attack works against Bluetooth devices and firmware from Apple, Broadcom, Cypress, Intel, Samsung, and others.
Academics have disclosed today a new vulnerability in the Bluetooth wireless protocol, broadly used to interconnect modern devices, such as smartphones, tablets, laptops, and smart IoT devices.

The vulnerability, codenamed BIAS (Bluetooth Impersonation AttackS), impacts the classic version of the Bluetooth protocol, also known as Basic Rate / Enhanced Data Rate, Bluetooth BR/EDR, or just Bluetooth Classic.

# The BIAS attack

The BIAS security flaw resides in how devices handle the link key, also known as a long-term key.
This key is generated when two Bluetooth devices pair (bond) for the first time. They agree on a long-term key, which they use to derive session keys for future connections without having to force device owners to go through the long-winded pairing process every time the Bluetooth devices need to communicate.

Researchers said they found a bug in this post-bonding authentication process. The flaw can allow an attacker to spoof the identity o a previously paired/bonded device and successfully authenticate and connect to another device without knowing the long-term pairing key that was previously established between the two.

Once a BIAS attack is successful, the attacker can then access or take control of another Bluetooth Classic device.
The research team said they tested the attack against a wide range of devices, including smartphones (iPhone, Samsung, Google, Nokia, LG, Motorola), tablets (iPad), laptops (MacBook, HP Lenovo), headphones (Philips, Sennheiser), and system-on-chip boards (Raspberry Pi, Cypress).
"At the time of writing, we were able to test [Bluetooth] chips from Cypress, Qualcomm, Apple, Intel, Samsung and CSR. All devices that we tested were vulnerable to the BIAS attack," researchers said.

"Because this attack affects basically all devices that 'speak Bluetooth,' we performed a responsible disclosure with the Bluetooth Special Interest Group (Bluetooth SIG) - the standards organisation that oversees the development of Bluetooth standards - in December 2019 to ensure that workarounds could be put in place," the team added.

#BIAS + KNOB
The academic team behind the BIAS attack includes Daniele Antonioli from the Swiss Federal Institute of Technology in Lausanne (EPFL), Kasper Rasmussen from the CISPA Helmholtz Center for Information Security in Germany, and Nils Ole Tippenhauer from the University of Oxford, thh UK.
The research team said that if an attacker combines BIAS and KNOB, they can break the authentication even on Bluetooth Classic devices running in a secure authentication mode.

As such, Bluetooth-capable devices must receive patches against both the BIAS (CVE-2020-10135) and KNOB (CVE-2019-9506) attacks to be fully secure.


Additional details about the BIAS attack are available on the vulnerability's official website, in a research paper titled "BIAS: Bluetooth Impersonation AttackS" [PDF], or the video presentation below.
Contiguous Array - LeetCode
Tags: hashtable
Published: 2020-05-27 03:30:57

---
title: Contiguous Array - LeetCode
published: true
description: Medium Problem
tags: hash-table
---

Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1.

**Example 1:**

**Input**: [0,1]

**Output**: 2

**Explanation**: [0, 1] is the longest contiguous subarray with equal number of 0 and 1.

![Contiguous Array](https://i.imgur.com/vDbtzWm.png)

**Algorithm**:

1. Initialize two variables `curSum` and `max`
2. Loop through the array and increment `curSum` by 1 if _nums[i]_ is 1 else decrement 1
3. Now you can encounter two cases
	1. Sub array formed from index 0

		In this case just take the current index and add 1

		In above examples it would be 1+1 = 2 for 1st example and 3+1 = 4 for 2nd example

	2. Sub Array formed after index 0

		In this scenario you have to find the previous index of cursum and subtract it

		In above image it would be 5-1 = 4

Here's the Code:

```js
/**
 * @param {number[]} nums
 * @return {number}
 */
var findMaxLength = function(nums) {
	let curSum = 0, max =0;
	let map = new Map();

	for(let i = 0; i < nums.length; i++) {
		if(nums[i] == 0) {
			curSum--;
		} else {
			curSum++;
		}

		if(curSum == 0) {
			max = i + 1
		}

		if(map.has(curSum)) {
			max = Math.max(max, i - map.get(curSum))
		} else {
			map.set(curSum, i)
		}
	}

	return max;
};
```

You can optimize the if condition where curSum == 0 by adding a value into map {0: -1}

Now, in the condition map.has(curSum), it will be something like 1 - (-1) = 2
Announcing web.dev LIVE: A three day digital event
Tags: webdev, news, frontend
Published: 2020-05-27 03:18:35

Two weeks ago we, at Google, would have hosted our annual developer conference, Google I/O. Out of concern for the health and safety of all participants, and in compliance with local "shelter in place" orders, we decided to not host I/O in any capacity.

To bring together the web community in this unprecedented time, Google's Web Platform team is putting together a 3-day digital event. Watch our 10-20 minute sessions for 3 hours every day, where we'll host talks about modern web development and answer your questions!

From the comfort of your own home join other web developers to, _"celebrate our community's actions, learn modern web techniques and connect with each other."_

#### Watch live on:
- June 30th, 9am - 12pm PDT (For developers in the Americas)
- July 1st, 12pm - 3pm GMT (For developers in Europe & Africa)
- July 2nd, 1pm - 4pm IST (For developers in Asia & Australia)

Be sure to sign up and get more information at [web.dev/live](https://web.dev/live/)!
Integrating a Ghost blog with an elixir reverse proxy in Phoenix
Published: 2020-05-27 03:12:53

---
title: Integrating a Ghost blog with an elixir reverse proxy in Phoenix
published: true
description: I wanted to start a blog in my Phoenix application, but couldn't find a polished solution in Elixir, so I explored my options.
tags: 
---
After thinking about it for a while, I decided to take the jump and actually start a blog. The blog will be about tech and SEO.

I have published my very first blog post, which is [my journey of integrating the blog itself into my Phoenix based application](https://seoapps.dev/blog/integrating-a-ghost-blog-with-elixir-phoenix).

I thought it would be fun to write the very first post about how I set up the blog, on the blog :)

It is a 7 minutes read.

A real reverse proxy such as nginx would probably be preferable, but I wanted to see how it would work just in Elixir.
PrimeNG setup
Tags: primeng, angular, design, webdev
Published: 2020-05-27 03:04:50

PrimeNG is a UI library for Angular. It has a list of components that we can use in our Angular applications. 

A lot of devies get this error when they try to add PrimeNG:

```
p-card is not a known Angular component
```
Note here, that p-card is just an example, and the error could be for any PrimeNG component one might be using. To solve that, make sure you have followed ALL the following steps:

- Installing the packages.
```
npm install primeng --save
npm install primeicons --save
```
Make sure the following dependencies are added in the package.json file:
```

"dependencies": {
  //...
  "primeng": "^8.0.0",
  "primeicons": "^2.0.0"
},
```
- Import the necessary modules in the app.module.ts file.
```
import {CardModule} from 'primeng/card';   
import {MenuItem} from 'primeng/api'; 
```
In the imports below, add the corresponding module.
```
imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule,
```

- If you still get the same error, add this to the angular.json file, in the styles:
```
"styles": [
  "node_modules/primeicons/primeicons.css",
  "node_modules/primeng/resources/themes/nova-light/theme.css",
  "node_modules/primeng/resources/primeng.min.css",
  //...
],
```

This should do the job! 

Cheers! Happy coding!
Create bootstrap like columns using css grid
Tags: css
Published: 2020-05-27 17:27:29

---
title: Create bootstrap like columns using css grid
published: true
date: 2020-05-27 00:00:00 UTC
tags: css
canonical_url: https://www.jskap.com/blog/create-bootstrap-like-columns-using-css-grid/
---

## Create responsive columns[<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#Create-responsive-columns)

Create a container and three children. These three children each will occupy 33% available width. We are going to use css grid to create this columns like structure. We are adding background and height to make better visual comparison.

```
 <div class="container">
      <div class="item">1</div>
      <div class="item">2</div>
      <div class="item">3</div>
    </div>

<style>
.item {
    height: 100px;
    background: yellow;
}
</style>
```

So it will look like this. [![html](https://www.jskap.com/static/f7b276b20678876bf39e134b005dcbed/7d013/html.jpg)](/static/f7b276b20678876bf39e134b005dcbed/7d013/html.jpg)

Let's add `display:grid` property to the container. We will use `grid-template-columns` property to specify children responsive widths.

```
.container {
    display: grid;
    grid-template-columns: auto auto auto;
}
```

Now three-item children each should take 33% width available on the screen. Make sure to match the number of children and their width in `grid-template-columns`. The width taken by children is responsive. So it will be relative to their parent width. It will take the respective % width available to their parent element.

Now it will look like this -

[![columns](https://www.jskap.com/static/7fd03cbeb7d98cce78e67666ec0a59dc/7b510/columns.jpg)](/static/7fd03cbeb7d98cce78e67666ec0a59dc/7b510/columns.jpg)

Using `grid-template-columns` you can specify number of columns and their widths for a grid container element. What if you want to add some gap between those columns without specifying external margin ? We can use `grid-gap` for that. Let's add 20px gap between these columns.

```
.container {
    display: grid;
    grid-template-columns: auto auto auto;
    grid-gap: 20px;
}
```

Now it will look like this -

[![gap](https://www.jskap.com/static/b0bd2ccebcb012d91700411fabc1c7fa/b768e/gap.jpg)](/static/b0bd2ccebcb012d91700411fabc1c7fa/b768e/gap.jpg)

CSS grid is a powerful feature to create complex responsive layouts. We don't need special library to create responsive layouts if we take advantage of features like CSS grid and flexbox.

  

👋 Hi! I’m Kapil. I am always chatty about building things, sharing my learnings, freelancing. Come say hi to me at [https://twitter.com/kapilgorve](https://twitter.com/kapilgorve)
Linking Documents in a Semantic Graph (Part 2)
Tags: datascience, datavisualization, graph, database
Published: 2020-05-31 20:21:51

---
title: Linking Documents in a Semantic Graph (Part 2)
published: true
date: 2020-05-27 02:39:51 UTC
tags: data-science,data-visualization,graph,database
canonical_url: 
---

[![](https://cdn-images-1.medium.com/max/1582/1*4H4HTOPerWaBy-gTpXCNSA.png)](https://towardsdatascience.com/linking-documents-in-a-semantic-graph-732ab511a01e?source=rss-fc0227505fc6------2)

How to design your own graph using TigerGraph Cloud

[Continue reading on Towards Data Science »](https://towardsdatascience.com/linking-documents-in-a-semantic-graph-732ab511a01e?source=rss-fc0227505fc6------2)
Measuring Web Requests with Httping
Tags: webdev, showdev
Published: 2020-05-27 02:07:24

---
title: Measuring Web Requests with Httping
published: true
description: Measuring Web Requests with Httping
tags: webdev, showdev
---

I recently encountered a bug where an http request was taking up to 3 seconds. Once I developed a potential solution, I needed to test the request to see if it was faster with the new code changes. In order to test, I developed a baseline by curling the request without any code changes. Next, I updated the code with the hopeful solution and curled the request again to observe the change. 

Below is an example. Note, the `-v` (short for `-verbose`) shows extra information, like the runtime, which shows the length of the request in seconds.

`curl -v http://api.citybik.es/v2/networks`

I found myself curling repeatedly to check the length of the request. I even recorded the times and averaged them. This was cumbersome. Fortunately, I discovered a useful program called [httping](https://www.vanheusden.com/httping/) that allows you to test the latency of a request by pinging it on a loop. When you exit the loop, an average runtime is provided for you.

`httping http://api.citybik.es/v2/networks`

![httping-demo](https://i.imgur.com/LRPs8dC.gif)

It's worth checking out the man pages because there are a number other useful httping features. For example, the demo below enables color highlighting and highlights all requests above the provided threshold.

`httping http://api.citybik.es/v2/networks -Y --threshold-red 325`

![httping-color-demo](https://i.imgur.com/J3rtU7T.gif)
Java 15 in 2020: Reasons to *not* use Java?
Tags: healthydebate, java, javascript, go
Published: 2020-05-27 01:52:28

In 2020, Java 15 will be released with major features (some coming out of preview mode), both at language, API, and runtime levels.

https://openjdk.java.net/projects/jdk/15/

Considering the changes that have already made through since Java 8 and the upcoming changes in Java 15, what are in your opinion the use cases that no longer make sense to use Java, and why?