teleren/devto huggingface dataset:
Using MongoDB as Datasource in GoLang
Tags: go, mongodb
Published: 2020-09-23 04:30:30

---
title: Using MongoDB as Datasource in GoLang
published: true
date: 2020-09-21 00:00:00 UTC
tags: Go,MongoDB
canonical_url: https://www.loginradius.com/engineering/blog/mongodb-as-datasource-in-golang/
---

In this tutorial, we will use the official MongoDB Go Driver to manage our MongoDB database. In the due process, we will write a program to learn how to install the MongoDB Go Driver and perform CRUD operations with it.

   
[Read On](https://www.loginradius.com/engineering/blog/mongodb-as-datasource-in-golang/)
How to create a buffer space and write to it in Node.js?
Tags: node
Published: 2020-09-21 00:00:00

---
  title: How to create a buffer space and write to it in Node.js?
  published: true
  tags: Nodejs
  date: Mon Sep 21 2020 05:30:00 GMT+0530 (India Standard Time)
  canonical_url: https://melvingeorge.me/blog/create-buffers-and-write-to-it-nodejs
  cover_image: https://melvingeorge.me/_next/static/images/main-12f172ff62dd56fe118cccac57a70c51.jpg
  ---
  [Originally posted here!](https://melvingeorge.me/blog/create-buffers-and-write-to-it-nodejs)
  
## Create buffer space

To create buffer space we can use the `alloc()` method in the global `Buffer` class in Node.js.

- The method takes the number of bytes (`integer`) to allocate as the first argument.
- The method returns a buffer object.

Let's allocate a buffer space of 10 bytes.

```javascript
// allocate 10 bytes of buffer space
const buff = Buffer.alloc(10);

// display buff contents
console.log(buff); // <Buffer 00 00 00 00 00 00 00 00 00 00>
```

To initialize the bytes with other than 0, you can pass that integer or string as the second argument like this,

```javascript
// allocate 10 bytes of buffer space
// allocate with integer 1
const buff = Buffer.alloc(10, 1);

// display buff contents
console.log(buff); // <Buffer 01 01 01 01 01 01 01 01 01 01>
```

## Write to Buffer

To write to a buffer space we can use the `write()` method in the `Buffer` object.

- The method accepts a string as the first argument to write.

```javascript
// allocate 10 bytes of buffer space
const buff = Buffer.alloc(10);

// write to buffer
const bytesWrote = buff.write("John Doe");

console.log(bytesWrote); // 8
console.log(buff); // Raw Buffer: <Buffer 4a 6f 68 6e 20 44 6f 65 00 00>
console.log(buff.toString()); // String: John Doe
```

### We can use the `toString()` method in the `buff` object to convert a raw buffer to string.

We can also define the starting point where it needs to write to the buffer.

For example, if we want to write to buffer after 2 bytes we can pass that as the second argument to the `write()` method.

```javascript
// allocate 10 bytes of buffer space
const buff = Buffer.alloc(10);

// write to buffer
// after 2 bytes
const bytesWrote = buff.write("John Doe", 2);

console.log(bytesWrote); // 8
console.log(buff); // Raw Buffer: <Buffer 00 00 4a 6f 68 6e 20 44 6f 65>
console.log(buff.toString()); // String: John Doe
```

If you look closely into the contents inside the `buff` variable you can see that the first 2 bytes are `00 00` which means we started writing into the buffer after 2 bytes.

See this example live in [repl.it](https://repl.it/@melvin2016/Create-Buffers-and-Write-to-it).

### Feel free to share if you found this useful 😃.

---
How to make sidebar menu work better?
Tags: beginners, wordpress
Published: 2020-09-20 23:50:28

I work with a website that reviews adult toys. On every review page we have a kind of link to parts of the whole article, and want to make it highlighted when you are in an exact part of the text. Sometimes in one part there might be two or more reviewed objects. When you read about the second on, your location is not highlighted. How can I make it highlighted?
For some reasons, I cannot add here a careen with that sidebar menu. You can check it by visiting my site.
https://joynights.org
The Art of Development
Published: 2020-09-20 23:26:46

If you are a developer, you are an artist. I don't care how STEM you think you are, you are an artist. You are creating a vision. Even if you are creating non-graphical interfaces, you are still creating something beautiful.

So now you're an artist! Congrats! What does it actually mean to be an Artistic Software Developer? I define it as a person who cares about technology and writing software. An Artistic Software Developer is someone who cares about the quality of code, the flexibility, the feel, to name a few. They have a passion for creating sustainable software. They care about code.

I know I am not a traditional artist. I've never been good at art. Sure I can edit a video and make it fancy, but I know that I am no traditional artist. No one is going to come up to me and ask for a painting. If someone would do that, they would get a terrible stick figure. But if someone were to ask me to write a simple calculator, I would develop it in a way that is: understandable, clean, protective, simple, and scalable. Just like an author creates beautiful sentences, we too can create beautiful code.

The day I started to see code as an art form was the day I became an Artistic Software Developer. The book, Clean Code, lays out a pretty good definition of good code. The book not old describes what good code looks like, it also explains why good code is good. It focuses on the fundamentals and the focus on readability and quality. 

Be an artist. Care about code. Consider others and how they might view your code. To be a good Artistic Software Developer, you must have the ability to create software that is not only simple but also explains itself. Code can be art. Code is art. Become an artist. Care about your code!
The Grey
Published: 2020-09-20 23:01:59

Have you thought about your future? Are you ready to get old? I know I'm not ready to get old! I do want to clarify what I mean by "get old". We all age, every second of every day. That is the human condition. I am not referring to that type of "old". I'm talking about aging out of your career. The day I age out of my career is very far away, but knowing that it will come is why I'm writing this.

Getting old...I'm a developer. I can't remember when I was not writing code. I love having the ability to write a sentence and watch the computer follow my orders. Am I getting old? Yes, I am but that does not mean I am aging out of my career. Instead, I am seeing my career in a new light. I don't have to be the best and pursue delusions of grandeur. I want to be a good developer and a good family member.

Have you ever put your career before your family? It sucks when it happens, but you justify it. I know I've justified having to work late and miss my son's Taekwondo lessons. Was it worth it? I don't think so. Family first. Family is my future!

I don't plan on getting "old", I plan on growing old. "Old", in my career mindset, means falling out of pace with the world. I'm not going to grow like that. How? By trying to be the best developer I can be all while keeping an eye on the future.

I will get old. I will get grey. I will get shorter (though 5'5 is pretty short). I won't stop learning though. I will never stop, no matter what my age is. Carpe Diem!!!
Using polymorphic relationships in Rails forms with GlobalID
Tags: rails, polymorphic, forms
Published: 2020-09-20 22:47:38

```
#form
f.input, :groupable_gid, as: :select, collection: [groupable.name, groupable.to_gid]
```
```
#polymorphic model
def groupable_gid
  groupable&.to_global_id
end
def groupable_gid=(gid)
  self.groupable = GlobalID::Locator.locate gid
end
```
self-referential data-reflex-root
Tags: stimulus, stimulusreflex, viewcomponents
Published: 2020-09-20 22:45:22

It can sometimes be tricky to re-render an element, partial or view component in a selector morph from a reflex, especially if it needs new.

An alternative approach to selector morphs is wrapping your element(s) in a div with data-reflex-root. The value of the data attr will be used as the selector(s) for the morph. 
A neat trick is that you can do this on itself
```
<div id="unique-morph-target" data-controller='resource-toggle-component' data-reflex-root='#unique-morph-target'>
```
N.b. only the children of this element will be morphed, and not the element itself!
One major difference is that this approach still hits the controllers original action, which may or may not be desirable.
There’s nothing special needed in the reflex
ref: https://docs.stimulusreflex.com/morph-modes#scoping-page-morphs
data-reflex-root
Tags: stimulusreflex, stimulus, morphdom
Published: 2020-09-20 22:42:24

If you’re finding janky animations or renders with elements when using reflexes with [self-referential](https://dev.to/scottbarrow/self-referential-data-reflex-root-4o13) `data-reflex-root`, wrap the children of your root element in a div/span
This helps morphdom…morph
Janky:
```
<div id='some-id' data-reflex-root='#some-id'>
  some text
  <input data-reflex= 'click->SomeReflex#some_action'>..</div>
</div>
```
Not janky
```
<div id='some-id' data-reflex-root='#some-id'>
  <div>
    some text
    <input data-reflex= 'click->SomeReflex#some_action'>..</div>
  </div>
</div>
```
YMMV
Leetcode - Validate Binary Search Tree (with JavaScript)
Published: 2020-09-20 22:37:46

Today I am going to show how to solve the Validate Binary Search Tree.

Here is the problem:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/y5en1zjvr3wnp3n8xcbo.png)

Before explaining the solution to this problem, I am going to shortly go over what a Binary Search Tree (BST) is.

Generally a tree is a data structure composed of nodes. Each tree has a root node which is the highest node and has zero or more child nodes. As stated in the problem, a Binary Search Tree is a type of tree in which each node has up to two children and adheres to the following properties: 

- The left subtree of a node contains only nodes with keys less than the node's key.
- The right subtree of a node contains only nodes with keys greater than the node's key.
- Both the left and right subtrees must also be binary search trees.

Based on all of this, we can say that every node in BST has a minimum value and a maximum value. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/0q0n86fqw61kkub7r686.png)

Therefore, I am going to traverse the entire given tree by starting from the root node. Then, I move down from the root to validate all the subtrees by checking if all of the subtrees’ nodes are wrapped between their minimum value and maximum value. I will do this until I reach null values i.e. leaf nodes that don't have any child nodes.

For this, I created a helper method (validateBst)  which takes in additional arguments, a minValue and a maxValue, and I pass down values as we traverse the tree. When I call the helper method on the left subtree of a node, I change the maximum value to be the value of our current node. When I call the function on our left subtree, I change the maximum value to be the current value of our node.

```javascript
var isValidBST = function(root) {
    return validateBst(root, -Infinity, Infinity)
};

function validateBst(root, minValue, maxValue) {
    if(root == null) return true;
     if(root.val >= maxValue || root.val <= minValue) return false;
    return validateBst(root.right, root.val, maxValue) &&
            validateBst(root.left, minValue, root.val)
}
```
Web Vulnerabilities: Romantic Conversations of a Vulnerable Application Part 1
Tags: webdev, computerscience, security
Published: 2020-09-20 22:35:15

This article is a collection of conversations between two lovers – Mr. Hacksaw and Miss App which unfortunately can be used to explain the concept of web vulnerabilities. 

So, the background of the story.

Mr. Hacksaw is a handsome man. A player who has mastered the art of seduction and finds joy in breaking into women’s hearts and leaving them devastated. 

On the other hand, Miss App is a young lady, short in length 😊 who takes her job seriously. Miss App is **robust** in bodily features with a **portable** structure. Her job is to render high software support services and her customers are always happy because she is always available and never under-**performing**. Miss App is said to be a highly **functional** individual and can be trusted even when **non-functional**. 

Because of this, Miss App had a lot of clients doing business with her which included Mr. Hacksaw. Over time, Mr. Hacksaw got to bond deeply with Miss App and she threw caution to the winds, becoming vulnerable gradually. The evolution of these vulnerabilities can be found in some conversations they had as seen below. 

##Active Session Hijacking- Day 3

**Miss App**: So much traffic today, business is moving fast. (*sees Mr. Hacksaw*) Oh! Mr. Hacksaw, you are here again. Do you want anything?


**Mr. Hacksaw**: Nothing really. I just want to borrow some of your time.


**Miss App**: Oh! Many clients need my services now, Hacksaw. But I can stop communicating with this particular client for a minute to hear what you have to say. You have the floor, Hacksaw.


**Mr. Hacksaw**: (*Hacksaw steals client’s session and uses it to steal sensitive client information as App’s attention is divided*) Would you be available for a date tomorrow?


**Miss App**:  Hmm... Yes. But you know I am always working and anything can come up at any time. I hope you don’t mind if I come with the client files for the date.


**Mr. Hacksaw**: Sure. No problems.


##Cross-Site Request Forgery- Day 4 

**Miss App**: Oh! I like this site you picked for the date. It’s a break from my **domain**. Gosh! I have worked too much this week.


**Mr. Hacksaw**: I know right. So, tell me, how do you **structure** yourself to handle the client’s enormous problems? Also, in any case, a client needs to change his or her personal details, what is the process?


(*Miss App spills her internal structure while Mr. Hacksaw excuses himself for a while and comes back to slip wrong information with the exact structure explained into the client’s file as App's attention was fixed in Hacksaw's handsome face*)


**Miss App**: It was a beautiful time with you, Hacksaw. I really enjoyed myself. Sorry, I had to bring these files along. I would be taking them now back to my **domain** for immediate processing. I would miss you, baby.


**Mr. Hacksaw**: Same here, cupcake. Bye.





The next series reveals more conversations between Miss App and Mr. Hacksaw.
I need your help putting together a curriculum.
Tags: webdev, help, beginners, javascript
Published: 2020-09-20 22:34:15

Good day to everyone that sees this.

My name is Favour. I am 21 years old. Currently in my 3rd year of university studying Computer Science. This corona thing and my lecturers being on strike have come together to make sure I am at home with nothing to do. After exactly 7 months of being idle and bored, I have set myself the goal of becoming a job ready Frontend developer in the next three months, starting on the 27th of this month, September. The issue is:

1. I don't know any programming languages, I have a very high level knowledge of things being a CS student. I just enough to pass my exams nothing more.
2. I don't have money to join a bootcamp or pay for a bunch of classes, i.e I am broke, dead broke. 

 What I am asking for is help, to put together a curriculum an in-depth curriculum. I have time to kill and nothing else to do, I am highly motivated to work my bones off.

I am asking for recommendations and resources you used to learn to get your first job. 

Before you go, you can't get job ready in 3 months, calm down, I have seen people do it. Plus I am aiming for the moon while shooting for stars.

If you have any help please dm me on Twitter. Thanks for your help. See I am thanking you in advance so you are guilt tripped into helping me. Thank you anyways.
Creating java code and simplifying execution with JBang
Tags: java, linux
Published: 2020-09-20 22:11:49

---
title: Creating java code and simplifying execution with JBang
published: true
description: We will look at JBang which is a tool that could simplify your workflow with java applications. For instance you could run java programs directly from maven or github, you can create new programs in java with JBang.
tags: java, linux
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/b1soi329vxugdc41lzqg.jpg
---

{% youtube A9YeRPSCdVU %}

We will look at JBang which is a tool that could simplify your workflow with java applications. For instance you could run java programs directly from maven or github, you can create new programs in java with JBang.
CodeReady Containers: Unable to load kvm module
Tags: openshift, crc, codeready, quicktip
Published: 2020-09-20 21:56:58



I found myself setting up a new machine recently and was enjoying the usual fun of configuring all of my tooling again. One of those tools is `CodeReady Containers`, which allows me to run a small OpenShift 4 environment locally. I've never had much issue with this previously (aside from some of the [resource requirements](https://github.com/code-ready/crc/issues/557) that it has of course), but on this machine that wasn't going to be an issue.

That being said, after pulling down the binary and my pull secret, I was a bit surprised after running the intial `crc setup` command:

 ```
Failed to load kvm amd module: exit status 1: modprobe: ERROR: could not insert 'kvm_amd': Operation not supported
```

Now before digging into what this actually means, let me be quite clear. This wasn't an actual issue with `crc` itself. It was more of an issue with the prerequisites that `crc` requires. I only came across one pull request that mentions something similar and didn't find anything in the way of documentation (*Note*: I also only did a quick pass on this), so I thought this quick write up would be helpful for others that find themselves in the same boat.

# So what is the problem?

Again, the error message that we received here was this:

```
Failed to load kvm amd module: exit status 1: modprobe: ERROR: could not insert 'kvm_amd': Operation not supported
```

I'm running on an AMD machine, so that makes sense. If you find yourself on an Intel machine, it would look something more like this:

 ```
Failed to load kvm intel module: exit status 1: modprobe: ERROR: could not insert 'kvm_intel': Operation not supported
```

What this is telling us is that it's having an issue enabling the specific kvm module that it's trying to use. And what it all boils down to (at least in my case) was that I have a machine where I haven't enabled virtualization on yet. CRC of course sets up a single virtual machine that runs an OpenShift release, so of course if there's no virtualization enabled on the machine, I'm not going to get OpenShift here. 

The fix is going to look _slightly_ different in each case as your BIOS is going to look a bit different depending on your own machine, but overall what you're going to need to look for is found in your BIOS settings. So reboot your machine and press whatever keys necessary to get you to your BIOS screen. The setting you'll be looking for (likely to be settled in somewhere under an `Advanced` or `CPU` tab) is one that allows you to enable virtualization. In my case, the acronym was SVM -- but your mileage and use of acronyms may vary across any number of BIOS.
My #100DOC - Day 25
Tags: 100daysofcode, challenge, log
Published: 2020-09-20 21:50:57

### Day 25: September 20, 2020

#### **Today's Progress**: 
1. **[Continued with Tim Buchalka's Java Programming Masterclass course](https://github.com/pablohs1986/javaProgrammingMasterclass_Buchalka)** (1h):<br>I continued to review the fundamentals of Java beginning the exercise Numbers To Words from the Buchalka course.
    
#### **What I learned**: 
* Review of how to count digits of an int and reverse it in Java.

#### **Total time**:
1h.
My #100DOC - Day 24
Tags: 100daysofcode, challenge, log
Published: 2020-09-20 21:50:10

### Day 24: September 19, 2020

#### **Today's Progress**: 
1. **[Continued with Confección y Publicación de Páginas Web Course](https://github.com/pablohs1986/confecci-nYpublicaci-nDeP-ginasWeb_SEPE)** (3h):<br>I finished Units 2 and 3, reviewing how to insert images and multimedia content into HTML, as well as basic guidelines on usability and accessibility.
    
#### **What I learned**: 
* Review of the handling of images and multimedia content in HTML.
* Basic concepts of usability and accessibility.

#### **Total time**:
3h.
When did you transision to MacOS and how did you find it?
Tags: watercooler, discuss
Published: 2020-09-20 21:31:03

The reason I ask is fairly simple. It's a switch which seems to make sense the more I think about it.

I currently have an average personal laptop which I abuse when coding. It only has 8GB RAM, and I use most of it often. Had the whole thing freeze a few times this week.

I use Ubuntu day-to-day, but the available devices with it installed are too small for me (all 13") and are limited to 16GB RAM. 

I'm considering a MacBook Pro (16"), a It's not Windows. It's got a great spec, and should last a while. Problem is, I've never been an Apple guy.
Bash/HTML/JS is not a valid Prism.js language for eleventy-plugin-syntaxhighlight
Tags: staticsitegenerator, 11ty, eleventy, prismj
Published: 2020-09-28 02:34:57

---
title: Bash/HTML/JS is not a valid Prism.js language for eleventy-plugin-syntaxhighlight
published: true
date: 2020-09-20 21:14:49 UTC
tags: staticsitegenerator,11ty,eleventy,PrismJ
canonical_url: https://releasecandidate.dev/bash-html-js-is-not-a-valid-prismjs-language-for-eleventy-plugin-syntaxhighlight
---

This is one of the small articles I wish I had found while researching a problem I encountered. So I hope it solves your issue without much fuss.

If you are into the [static generator](https://peterthaleikis.com/posts/introduction-to-static-site-generators/) [11ty](https://www.11ty.dev/) like me you might stumble upon one of these messages:

- "Bash" is not a valid Prism.js language for eleventy-plugin-syntaxhighlight

- "HTML" is not a valid Prism.js language for eleventy-plugin-syntaxhighlight

- "JS" is not a valid Prism.js language for eleventy-plugin-syntaxhighlight

- "Pug" is not a valid Prism.js language for eleventy-plugin-syntaxhighlight

Prism.js is the [syntax highlighting library](https://www.11ty.dev/docs/plugins/syntaxhighlight/) used in eleventy.

Good news is: I've got an easy solution for you available. Change the spelling to lowercase and you should be good to go.