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
@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
}
"scripts": {
"start": "node nightly --experimental-strip-types index.ts"
}
const map = new Map();
map.set(1, 'Number one');
map.set('1', 'String one');
map.set(true, 'Boolean true');
console.log(map.get(1)); // Output: Number one
const map = new Map();
map.set('a', 1);
map.set('b', 2);
<script async src="analytics.js"></script>
<script defer src="main.js"></script>
<!-- Correct usage -->
<script async src="https://example.com/ads.js"></script>
<script defer src="app.js"></script>
<script type="module" src="main.js"></script>
const record = #{ name: "Alice", age: 30 };
const tuple = #[1, 2, 3];
console.log(record.name); // Alice
console.log(tuple[0]); // 1
const data = { type: 'user', info: { name: 'Alice', age: 30 } };
const result = match (data) {
class Singleton {
constructor() {
if (Singleton.instance) {
return Singleton.instance;
}
this.data = [];
Singleton.instance = this;
}
getData() {
<div className="flex flex-col items-center p-6 bg-white shadow-md rounded-lg">
<h2 className="text-2xl font-bold mb-2">Card Title</h2>
<p className="text-gray-700">This is a card description.</p>
</div>
import styles from './Card.module.scss';
<div className={styles.card}>
<h2 className={styles.title}>Card Title</h2>
enum Direction {
North,
East,
South,
West
}
let myDirection: Direction = Direction.North;
console.log(myDirection); // Output: 0
// 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';
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);
}