Skip to content

Instantly share code, notes, and snippets.

View BiosBoy's full-sized avatar
⛰️
The bigger you know - the less you scared of.

Sviat Kuzhelev BiosBoy

⛰️
The bigger you know - the less you scared of.
View GitHub Profile
class Singleton {
constructor() {
if (Singleton.instance) {
return Singleton.instance;
}
this.data = [];
Singleton.instance = this;
}
getData() {
# Code Examples from "Top 5 Underestimated Native Browser Features You Should Be Using"
## 1. Bluetooth: Connecting to Devices Wirelessly 📡
### Example: Connecting to a Bluetooth Device
```typescript
async function connectToBluetooth() {
try {
function Person(name) {
this.name = name;
}
Person.prototype.greet = function() {
console.log(`Hello, my name is ${this.name}`);
};
const alice = new Person('Alice');
const userRole = 'admin';
if (userRole === 'admin' || userRole === 'editor' || userRole === 'moderator') {
console.log('Access granted');
} else {
console.log('Access denied');
}
const userRole = 'admin';
# Webpack Bundle Analyzer Examples
## Install the Package
```bash
npm install --save-dev webpack-bundle-analyzer
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
@BiosBoy
BiosBoy / graphQl_restful
Created July 28, 2024 09:01
I Love RESTful, But It's Time for GraphQL: Everything You Should Know Before Switching in 2024
npm install apollo-server-express graphql
const express = require('express');
const { ApolloServer, gql } = require('apollo-server-express');
// Define your type definitions (schema)
const typeDefs = gql`
type Query {
hello: String
}
const arr1 = [1, 2, 3, 4];
const result1 = arr1.flatMap(x => [x, x * 2]);
console.log(result1); // [1, 2, 2, 4, 3, 6, 4, 8]
const arr2 = ['a', 'b', 'c', 'd'];
console.log(arr2.at(-1)); // 'd'
console.log(arr2.at(-2)); // 'c'
const arr3 = [1, 2, 3, 4, 5];
const result2 = arr3.findLast(x => x % 2 === 0);
const originalArray = [1, 2, 3, 4, 5];
const slicedArray = originalArray.slice(2, 4);
console.log(slicedArray); // [3, 4]
console.log(originalArray); // [1, 2, 3, 4, 5]
const originalArray = [1, 2, 3, 4, 5];
const splicedArray = originalArray.splice(2, 2);
interface User {
id: number;
name: string;
email: string;
}
function updateUser(userId: number, updates: Partial<User>) {
// Imagine this function updates a user in the database
console.log(userId, updates);
}
// Old way
if (user && user.address && user.address.city) {
console.log(user.address.city);
}
// Modern way with Optional Chaining
console.log(user?.address?.city);
// Nullish Coalescing
const userName = user.name ?? 'Guest';