teleren/devto huggingface dataset:
Binary Search
Tags: cpp, algorithms
Published: 2022-10-31 06:55:02

**Binary Search - Different variations**


```
// return index of first element >= target
int lower_bound(vector<int> v, int target){
    int l = 0;
    int r = v.size();
    while(l < r) {
        int m = l+(r-l)/2;
        v[m] < target ? l = m+1 : r = m;
    }
    return l;
}
```

```
// return index of first element > target
int upper_bound(vector<int> v, int target){
    int l = 0;
    int r = v.size();
    while(l < r) {
        int m = l+(r-l)/2;
        v[m] <= target ? l = m+1 : r = m;
    }
    return l;
}
```

```
// return index of element == target
int binary_search(vector<int> v, int target){
    int l = 0;
    int r = v.size();
    while(l < r) {
        int m = l+(r-l)/2;
        v[m] < target ? l = m+1 : r = m;
    }
    return l < v.size() && v[l] == target ? l : -1;
}
```

```
int main()
{
    vector<int> v = {1,1,2,4,5,5,5,6,6,8,9};
    cout<< lower_bound(v, 5);  // 4
    cout<< upper_bound(v, 5);  // 7
    return 0;
}
```
Air BnB React/JSX Styleguide: Day 2 Class vs. React.createClass vs. Stateless
Tags: react, airbnb, styleguide
Published: 2022-10-31 06:51:50

Here is day 2 for the Air Bnb Read/JSX style guide review. Yesterday we look at the basics, today we are looking at how Air BnB engineers suggest we look at Class vs. React.createClss vs. Stateless:

- If you have internal state and/or refs, prefer class extends React.Component over React.createClass. eslint: react/prefer-es6-class react/prefer-stateless-function

So we want to write our components with internal state as:

```
class Listing extends React.Component {
// ...
  render() {
    return <div>{this.state.hello}</div>
  }
}
```

And if there is no state or refs, prefer normal functions over classes:

```
function Listing({ hello }) {
  return <div>{hello}</div>;
}
```

You don't want to write it as either of the following:

```
class Listing extends React.Component {
  render() {
    return <div>{this.props.hello}</div>;
  }
}

// or

const Listing = ({ hello }) => (
  <div>{hello}</div>
);
```

That is actually very useful to know - I try not to write arrow functions myself very often anyways because I never seem to get them right. Thanks Air BnB!

I'll meditate on that one today...



![Meditating](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eq0w6undo18q2nqebghu.jpeg)

"Whooooooaaaaaaayyyyyyyyuuuuummmmmmmaaaaaayyyyyyyyyeeeeeeeuuuuuuummmmmmmmm..... Whoooooooooooaaaaaaaaayyyyyyyyyuuuuummmmmmmaaaaaaayyyyyyyeeeeeeuuuuuummmmmmmm.... ooooooohhhhhhhhhmmmmmmmmm..."

Thanks for reading!
How To Get Hourly Data In MySQL Query
Tags: laravel, php, mysql, database
Published: 2022-10-31 06:43:40

In this article, we will see how to get hourly data in MySQL Query. Many times we need to get hourly data or we are required to get data every hour in MySQL. For getting data for every hour in MySQL we use the hour() function. MySQL hour() returns the hour of a time. The return value is within the range of 0 to 23 for time-of-day values.

So, let's see SQL query to get data for every hour or MySQL query to get hour wise records in PHP and how to get hourly data in PHP from the database.


> Get Hour Wise Data Using MySQL Example:

Using SQL query to get data for every hour in MySQL.

id | order_date          | amount
---+---------------------+-------
 1 | 2022-09-29 08:15:00 | 150
 2 | 2022-09-29 08:30:00 | 200
 3 | 2022-09-29 08:55:00 | 300
 4 | 2022-09-29 09:20:00 | 400
 5 | 2022-09-29 10:45:00 | 450
 7 | 2022-09-29 11:50:00 | 200
 In your table, the record needs to be like date and hour.

```
select hour(order_date), sum(amount)
       from users
       group by hour(order_date);
``` 
 
If you want to display hour values using AM/PM notation such as 10 AM, 11 AM, 12 PM, etc, then you need to use the date_format function that allows you to change the format of a given date and time.

```
select date_format(order_date,'%H %p') as hour,
        sum(amount) as total_amount
        from users
        group by date_format(order_date,'%H %p');
```
VPS and Shared Web Hosting: What's the Difference?
Tags: security, vps, sharedwebhosting
Published: 2022-10-31 06:43:19

What's the Difference? If you're not sure which type of web hosting to choose for your website, you're not alone. Many people don't know the difference between VPS and shared web hosting and which one would be best for their needs. In this article, we'll explain the key differences [between VPS and shared web hosting](https://www.sktthemes.org/wordpress/vps-vs-shared-web-hosting/) so that you can make an informed decision about which is right for you. VPS stands for Virtual Private Server. A VPS is a type of web hosting that gives you your own private server space. This means that your website will be hosted on its own server, separate from other websites. This allows for more flexibility and control over your website than shared web hosting, but it also costs more. Shared web hosting is just what it sounds like-your website will be hosted on a server with other websites. This is the most common type of web hosting, and it's also the most affordable. However, you'll have less control over your website than with a VPS. So, which should you choose? If you're just starting out, or if you have a small website with low traffic, shared web hosting is a good option. It's affordable and easy to set up. If you have a larger website or one with high traffic, you may want to consider a VPS. A VPS will give you more control over your website and can handle more traffic than shared web hosting. Still not sure which is right for you? Contact your web hosting provider and they can help you decide which type of web hosting is best for your website. VPS stands for Virtual Private Server. A VPS is a type of web hosting that gives you more control over your website than shared web hosting, but it also costs more. If you're just starting out or have a small website with low traffic, shared web hosting is a good option.
SRE Opportunity
Published: 2022-10-31 06:20:50

**Responsibilities:**
As a SRE, you will be working as part of our global team which runs our production operations. You will:
- Do the day-to-day operations of our massively scalable and highly available backend platform.
- Manage our hybrid infrastructure.
- Automate routine operational tasks.
- Manage individual projects and milestones with abundant communication of progress.

**We are looking for someone with:**
- Experience managing geo distributed and highly available production services
- Knows linux inside out [5+ yrs of experience or has a system admin background]
- Strong monitoring, debugging, troubleshooting skills
- Effective verbal and written communication

**Technical qualifications:**
- 5+ yrs of experience with production monitoring using Prometheus/InfluxDB, ELK, Grafana and OpsGenie/PagerDuty.
- 3+ yrs of experience in Linux system administration 
- Familiarity with data center operations

**Good to have:**
- Familiarity with Incident management and SLA/SLO/SLI
- Network troubleshooting skills
- Performance tuning experience
- Python or shell scripting

Please share the details to ashwin.lobo@accionlabs.com
5 Interesting Things In JavaScript
Published: 2022-10-31 06:20:27

JavaScript is the world’s most popular programming language. JavaScript was invented by Brendan Eich in 1995 and became an ECMA standard in 1997. Javascript is most well-known as the scripting language. As of 2012, all of the rn browsers fully support JavaScript.
To be a programmer you must know about JavaScript(Js). Because it is a core part of the programming. JavaScript is more important when you design a website user interface.
But there are some interesting facts about JavaScript. Here we’ll talk about some strange things in this language’s fun facts.

**1. Programming Language Of The Web**
JavaScript (JS) is a lightweight, interpreted, object-oriented language, 
and is best known as the scripting language for Web pages. it’s also used in other environments as well.
JavaScript is a text-based programming language used both on the client-side and server-side that allows you to make web pages interactive.

**2. JavaScript engine**
JavaScript engine is a computer program that executes JavaScript (JS) code. Every browser provides a JS engine that runs the JavaScript code. This engine was a rudimentary interpreter with no optimizations. Running the JavaScript code with this engine was slow but it worked.

**3. Start with a Semicolon!**
In much other time, you have to put a semicolon(;) at the end of a statement. But you can start with a semicolon(;) if you want. But it is not recommended.

`;var a = 2`

**4. Sum of String and Numbers**
If you sum a number with a string you will get this:
`'500' + 1; //'5001'`

Pretty strange, right?
But if you sum a string with a number then there will be no doubt:
`500 + '1'; //501`

**5. Immediately-Invoked Function Expression**
Look at the examples below. The first one works but the second one gives Uncaught SyntaxError: Unexpected token ).
`// Works fine
var foo = function () { 
    //some stuff
}();`

`// Syntax error
function foo() {
    //some stuff 
}();`


These are some Interesting things in JavaScript. Hope you will get something new from this article.
Spiral Matrix
Tags: dsa, python
Published: 2022-10-31 06:14:58

## Instructions

Given an m x n matrix, return all elements of the matrix in spiral order.

```python
Input: matrix = [
[1,2,3],
[4,5,6],
[7,8,9]]
Output: [1,2,3,6,9,8,7,4,5]
```
[Attempt](https://leetcode.com/problems/spiral-matrix/) the question.


##Approach
- The output follows a clockwise motion; we move to the left, then downwards, upwards and finally to the right.

We initialize four pointer; left,right,top and bottom.
Then move from left to right and update the top pointer to the next row because we are done with the given row.

Then move from current top to bottom to cover elements on the rightmost column and update the right pointer.

Move from right to left in the bottom most row and update the bottom pointer.

Move from bottom to top and update the left pointer.
This process continues until the left and right pointer meet or the top and bottom pointer meet.

## Implementation

```python
def spiralOrder(matrix):
    left, right = 0, len(matrix[0])
    top, bottom = 0, len(matrix)

    spiral = []

    while (top < bottom and left < right):
        # left to right
        for i in range(left, right):  
            spiral.append(matrix[top][i])  
        top += 1
        # right to bottom
        for i in range(top, bottom):  # does not repeat value because we have updated top
            spiral.append(matrix[i][right-1])
        right -= 1
        if not (top < bottom and left < right):
            break
        # right to left
        for i in range(right-1, left-1, -1):
            spiral.append(matrix[bottom-1][i])
        bottom -= 1
        # top to bottom
        for i in range(bottom-1, top-1, -1): 
            spiral.append(matrix[i][left])
        left +=1

    return spiral
```
  
            
Happy learning !!

### References
[Spiral Matrix](https://www.youtube.com/watch?v=BJnMZNwUk1M)
Kubernetes 101 - Node component
Tags: kubernetes, beginners
Published: 2022-10-31 06:06:15

We'll check out the node component in more detail for this article.

The node component is a component that runs on every node, and it's responsible for maintaining running pods and providing the Kubernetes runtime environment.

It closely connects with the Kubernetes API and receives and sends data from its node.

Each node runs two main components a kubelet and a container runtime. Let's take a look at what each one does.

### kubelet

The kubelet is responsible for establishing and acting on the communication between the Control Plane and the node.

### Container runtime

The container runtime is in charge of pulling the relevant image from the image registry, unpacking them, and running them on the node.
It can run multiple container runtimes, including Docker, CRI, CRI-O, and Containerd.

### kube-proxy

Besides the two main components, we also get the kube-proxy which runs on each node. It's responsible for maintaining network rules on each node. It makes sure the communication between nodes and pods is as expected.

### Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on [Facebook](https://www.facebook.com/DailyDevTipsBlog) or [Twitter](https://twitter.com/DailyDevTips1)
Moving to Backend (Starting with Ruby!)
Tags: webdev, programming, ruby
Published: 2022-10-31 06:05:57

## Introduction
Good evening everyone here in the DEV community, I'm back again but this time I'm switching from frontend development to backend! Surprisingly, I found that Ruby was easier to learn compared to JS/React. Maybe because it was my second language I had a bit more experience to know how to tackle learning about something new. I initially struggled in the start, but so far I've been enjoying my experience with it! Stay tuned if you're interested in more details about my journey with Ruby. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ysfnxtdwffe2p9m1mpta.jpg)

## Initial Feelings
Jumping from React to Ruby was a bit confusing at first, but I expected such since it was a swap from front-end to back-end development. Some of it was pretty familiar actually! For example, comparing a method in Ruby to a function in JS was very similar and I got the hang of it quickly! Swapping from using function to using def wasn't completely foreign to me, so that was a relief. I think that learning your first language is harder than learning the next, so if you're worried about struggling more with your second language versus your first don't worry too much! You'll get the hang of it quicker than you did the first since you have experience tackling problems now.

## Fundamentals of Ruby
Let's talk about some important fundamentals. The first one should be simple things like puts and what a method is. I briefly explained what a method was earlier, but to put it simply I would describe it as very similar to any other function in other programming languages. I would also describe puts as logging something to the console in any other language (ex: console.log() in JavaScript.) Below this paragraph will be an example of both, so check it out if you'd like an example! Continuing with this section, other important fundamentals of Ruby would be variables such as instance variables and class variables. A class variable is a variable that belongs to a class, and an instance variable is a variable that holds a value that is local to a specific instance of an object. It might seem confusing at first, but after a bit of practice it will be easier to understand what both of those mean!

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jzyq1ijrob1skzw9h2r8.png)

## Final Thoughts
Jumping from frontend development to backend development might seem scary, but once you learn your first language you'll see that it's easier for you to tackle the challenge. Ruby is a developer-friendly backend language and I've enjoyed the time that I've spent with it so far. There were times where I felt like it was too hard for me to do, but I promise you that persistency really is the key to succeeding in what you strive to accomplish! I'm eager to keep learning more about Ruby and what it can do and I can't wait to update the DEV community again with what I've learned in a month or two. Thanks for reading my blog post and see you soon!
Keyboard shortcuts for navigating a large file in VSCode
Tags: development
Published: 2022-11-03 23:56:40

---
title: Keyboard shortcuts for navigating a large file in VSCode
published: true
date: 2022-10-31 06:00:00 UTC
tags: development
canonical_url: https://rachsmith.com/keyboard-shortcuts-large-file-vscode/
---

When writing the code gets a bit dull at my job, I try to make things more interesting by setting myself a challenge in other ways. Currently, I am training myself to use the keyboard to get around VSCode instead of a mouse. I'll list a few of my favourites (on macOS).

### Fold all: command+k command+0

This folds all the foldable sections of a file. I find it makes files easier to scan at a high level.

### Go to Symbol: shift+command+O

This allows you to search for and jump to any symbol on the page. Great for getting to the start of a method or function.

### Go to line: control+G

Enter the line number, and there you go. Great for when you're dealing with stack traces. I use it more to jump around a file quickly without needing to scroll.

### control+option (with Space Block Jumper extension): Jump to next empty line

I use the [Space Block Jumper](https://marketplace.visualstudio.com/items?itemName=jmfirth.vsc-space-block-jumper) extension to do this one. It takes you to the next blank line in the file. It allows you to move through a file faster than you would by scrolling with the up/down keys.
Useful websites that I have bookmarked (& you should too) to Learn & Practice JavaScript
Tags: javascript, webdev, beginners, programming
Published: 2022-10-31 05:51:26

Learning **JavaScript** online from _video tutorials_ is **not enough**, you should **practice** your knowledge too. Also, video tutorials don't really contain an in-depth knowledge about the concepts, they may be successful in explaining things, but to dive-deeper, there is something more you need, and this short post is written to tell you about that only!

Continue Reading...


## [JS Challenger](https://www.jschallenger.com)
![JS Challenger](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fkeuum13oolu6m8kvebx.png)
This place offers good **practice questions** for JS. However, you need to **pay** to make an account and save your progress, and for some questions too.


---

## [Learn JavaScript Gitbook](https://gitbook.gitbook.io/learn-javascript)
![Learn JavaScript Gitbook](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fp3hmo8vvcc2wov43bgp.png)
A **short** and **easy** gitbook to learn basic JavaScript

---


## [JavaScript Quiz](https://javascriptquiz.com)
![JavaScript Quiz](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4rzko2705m7dqaxai3ps.png)
A good website for testing your Javascript knowledge via quiz 

---

## [JavaScript.info](https://javascript.info)
![JavaScript.info](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/umugaqt65lc7pdyd8j0y.png)
My **favourite** place to learn JavaScript, this website has **elaborate content** about all the concepts of JS with **exercises** and is a great place to learn from beginner to advance.

---

And lastly,
## The Eloquent JavaScript
![The Eloquent JavaScript](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x0tpo89mrns2phrip15b.png)
This book is excellent for web developers to learn JS concepts deeply. However, it may not be suitable for beginners, but a must-have after you have strong basics.

Purchase from Amazon - https://amzn.to/3Fwk0pA

Read Online for free - https://eloquentjavascript.net

--- 

Thanks for reading! Hope I was able to add some value 😇

Check out the Twitter thread I originally talked about these resources - {% embed https://twitter.com/Prakhartiwari0/status/1586952879923134464?s=20&t=RiWSsLylQZguT2NEYAMgFw %}
NextSketch Compatibility on IntelliJ 2022.3 EAP Linux
Tags: news, linux, community
Published: 2022-10-31 05:47:07

Hello! 👋 

Recently, we've found that NextSketch doesn't accept licenses bought under an EAP build of IntelliJ.

We've particularly noticed it on IntelliJ Community 2022.3 EAP for Linux, but it might be the same on other OS' too.

Turns out this is actually a glitch in IntelliJ EAP so if you're not living at the cutting edge you should be fine.

Hopefully it's fixed in the next EAP!

Have fun!
Start Your Scripting Journey Today | Bash Script
Published: 2022-10-31 05:37:55

A Bash script is a plain text file that contains a series of commands. Anything we can normally run from the command line can be used to create a script.

Article Links:

1. [Start Your Scripting Journey Today | Bash Script- Part 1](https://levelup.gitconnected.com/start-your-scripting-journey-today-bash-script-part-1-46cbddf4e4e7)
2. [Start Your Scripting Journey Today | Bash Script- Part 2](https://medium.com/geekculture/start-your-scripting-journey-today-bash-script-part-2-4d93ecb59249)
python code to connect a website csmbet (linking)
Tags: python, programming, webdev
Published: 2022-10-31 05:33:59

import urllib
import urllib2

params = {'param1': 'value1'}

[csmbet](https://csmbet.info/)= urllib2.Request("[https://csmbet.info/](https://csmbet.info/)", urllib.urlencode(params))
res = urllib2.urlopen([csmbet](https://csmbet.info/))

data = res.read()
Binary Tree Inorder Traversal
Tags: algorithms, csharp, leetcode, easy
Published: 2022-10-31 05:27:14

_#94.Binary Tree Inorder Traversal_

### Problem statement
Given the `root` of a binary tree, return _the inorder traversal of its nodes' values_.

**Example 1**
```
Input: root = [1,null,2,3]
Output: [1,3,2]
```

**Example 2**
```
Input: root = []
Output: []
```

**Example 3**
```
Input: root = [1]
Output: [1]
```

### Explanation
給定一個二元樹，返回中序走訪的節點值

### Solution
解題前先來了解中序走訪，樹的走訪是訪問樹中所有節點，並將樹中的資料轉換成線性關係，例如返回一個結果陣列。那麼中序走訪的順序是先訪問左子樹，接著是樹根，最後才是右子樹，依照**左子樹→樹根→右子樹**的順序走訪二元樹直到**葉節點**也就是終端節點為止

此題意思非常清楚，單純只是寫一個中序走訪的遞迴方法，建立一個集合 `res` 用來儲存每次走訪的節點值，另外再建立一個 `Inorder` 的方法，其方法內容為中序走訪的方式，先判斷節點是否為 null，如果為 null 則代表這個節點是終點節點，所以不做任何事；若該節點為非 null，則先呼叫 `Inorder` 自己，參數帶入左節點，透過遞迴左子樹直到終端節點為止，當抵達終端節點時，`Inorder` 方法判斷該節點為 null，不做任何事結束方法，並返回到呼叫自己的方法，此時再將節點值記錄到 `res` 裡，接著再用相同作法走訪右子樹

```cs
public IList<int> InorderTraversal(TreeNode root)
{
	IList<int> res = new List<int>();
	Inorder(root, ref res);
	return res;
}

private void Inorder(TreeNode node, ref IList<int> res)
{
	if (node != null)
	{
		Inorder(node.left, ref res);
		res.Add(node.val);
		Inorder(node.right, ref res);
	}
}
```

### Reference
[LeetCode Solution](https://leetcode.com/problems/binary-tree-inorder-traversal/discuss/1312946/C-Solution)

[GitHub Repository](https://github.com/FakeStandard/LeetCode-CSharp/tree/main/Solution/0094.Binary-tree-inorder-traversal)

---

Thanks for reading the article :tulip: :sunflower: :blossom:

If you like it, please don't hesitate to click heart button :heart:
or click like on my Leetcode solution
or follow my [GitHub](https://github.com/FakeStandard) :star:
or buy me a coffee :arrow_down: I'd appreciate it.

[![Buy-me-a-coffee][1]][2]

[1]: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h077sxd0vx1hix4t7lw8.png
[2]: https://www.buymeacoffee.com/FakeStandard

---
Les modules natifs de Nodejs
Published: 2022-10-31 05:03:14

La première chose à savoir est comment le code JavaScript est exécuté. Pour cela, nous avons besoin d’un moteur JavaScript. Par exemple, chaque navigateur intègre un moteur JS : Spidermonkey pour Firefox, JavaScriptCore pour Safari et V8 pour Chrome et Chromium. Node.js est également capable d’exécuter du code JavaScript, car il inclut le moteur V8. Il dispose ensuite d’un ensemble de fonctionnalités en dehors de la portée de JavaScript. C’est pourquoi Node.js n’est pas un framework JavaScript, mais un runtime JavaScript. Il interprète JavaScript grâce à V8, puis appelle ses propres fonctionnalités. V8 est écrit en C++. Node.js, également écrit en C++, inclut la bibliothèque V8 dans son code.

Les bibliothèques Node.js prennent la forme de modules que vous intégrez à votre application Node.js grâce à require :

const foo = require('foo');

Ces modules sont généralement écrits en JavaScript et exportent un ensemble de fonctions et de classes. Il existe un autre moyen d’écrire des modules, qui est le sujet de cet article : les addons natifs, en C++.