Skip to content

Instantly share code, notes, and snippets.

View polRk's full-sized avatar
💯

Vladislav Polyakov polRk

💯
View GitHub Profile
@dehamzah
dehamzah / generate.js
Last active April 14, 2024 16:47
Generate secret key in NodeJS
require('crypto').randomBytes(48, function(err, buffer) { var token = buffer.toString('hex'); console.log(token); });
@thomd
thomd / semantic-layout.html
Last active March 29, 2024 00:27
Standard HTML5 Semantic Layout
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Title</title>
<link href="stylesheets/main.css" rel="stylesheet" />
</head>
<body>
<header>
<hgroup>
@enobufs
enobufs / before_after_each_test.go
Created May 7, 2022 23:07
beforeEach and afterEach with go-test
package main
import (
"fmt"
"os"
"runtime"
"testing"
)
func TestMain(m *testing.M) {
@Potherca
Potherca / README.md
Last active March 4, 2024 23:40
The search for a Regex to match BEM CSS class-names

The search for a Regex to match BEM CSS class-names

TL;DR

Use this regular expression to match BEM class-names:

^\.[a-z]([a-z0-9-]+)?(__([a-z0-9]+-?)+)?(--([a-z0-9]+-?)+){0,2}$
@konstantin24121
konstantin24121 / verifyTelegramWebAppData.tsx
Last active February 17, 2024 10:58
Telegram Bot 6.0 Validating data received via the Web App node implementation
const TELEGRAM_BOT_TOKEN = '110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw'; // https://core.telegram.org/bots#creating-a-new-bot
export const verifyTelegramWebAppData = async (telegramInitData: string): boolean => {
// The data is a query string, which is composed of a series of field-value pairs.
const encoded = decodeURIComponent(telegramInitData);
// HMAC-SHA-256 signature of the bot's token with the constant string WebAppData used as a key.
const secret = crypto
@polRk
polRk / App.tsx
Created May 11, 2020 16:02
React Apollo + Firebase authorization
import Dashboard from 'pages/Dashboard'
import Layout from 'components/Layout'
import Login from 'pages/Login'
import React from 'react'
import { useRoutes, Navigate, useLocation } from 'react-router-dom'
import { useAuth, userContext } from 'hooks/useAuth'
function App() {
const storedToken = localStorage.getItem('token')
const location = useLocation()
@niksudan
niksudan / mc-server-setup.md
Last active December 12, 2023 20:15
How to create a new Minecraft Server with DigitalOcean

Creating a new Minecraft Server

This is a short and simple guide on how to set up a multiplayer server running the latest version of Minecraft.

This guide has been tested on Ubuntu 16.04 and 18.04.

Setup

Create a new Ubuntu droplet on DigitalOcean. Make sure it has at least 2GB of RAM, and you provide it with your SSH key.

@smnbbrv
smnbbrv / promisified-grpc-client.ts
Last active November 4, 2023 21:22
Promisify @grpc-js service client with typescript
import { Client, ServiceError, Metadata, CallOptions, ClientUnaryCall } from '@grpc/grpc-js';
import { Message } from 'google-protobuf';
type OriginalCall<T, U> = (request: T, metadata: Metadata, options: Partial<CallOptions>, callback: (error: ServiceError, res: U) => void) => ClientUnaryCall;
type PromisifiedCall<T, U> = ((request: T, metadata?: Metadata, options?: Partial<CallOptions>) => Promise<U>);
export type Promisified<C> = { $: C; } & {
[prop in Exclude<keyof C, keyof Client>]: (C[prop] extends OriginalCall<infer T, infer U> ? PromisifiedCall<T, U> : never);
}
@polRk
polRk / calendar.ts
Created June 8, 2019 17:53
Generate month days calendar on TypeScript and date-fns
import { isSameMonth, startOfMonth } from 'date-fns'
export const generateCalendar = (
firstDateOfMonth: Date
): number[][] => {
const date = startOfMonth(firstDateOfMonth)
const getDay = (date: Date) => {
let day = date.getDay()
if (day === 0) day = 7
@mrkara
mrkara / read-key-press-cpp-linux.cpp
Last active March 18, 2023 18:59
[Read Key Press from Terminal under Linux with C++] #cpp #snippet
#include<iostream>
int main() {
char c;
// Set the terminal to raw mode
while(1) {
system("stty raw");
c = getchar();
// terminate when "." is pressed
system("stty cooked");