Skip to content

Instantly share code, notes, and snippets.

View polRk's full-sized avatar
💯

Vladislav Polyakov polRk

💯
View GitHub Profile
@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>
@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); });
@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.

@polRk
polRk / findBestPlacement.js
Last active October 28, 2018 09:42
Find the best placement of buttons in columns. Viber richMessage (see example.ts)
const findBestPlacement = (count) => {
const result = [4, 5, 6, 7].map(rows => ({
'Rows': rows,
'Columns': ((count / rows) ^ 0) === (count / rows) ? count / rows : (count / rows >> 0) + 1,
'Excess': count % rows,
'Free': count % rows === 0 ? 0 : rows - count % rows
}));
return [...result]
.filter((item) => {
@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
@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}$
@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");
@polRk
polRk / useAuth.ts
Created May 11, 2020 15:54
React Firebase useAuth
import * as firebase from 'firebase/app'
import { useEffect, useState, createContext } from 'react'
export type AuthState = {
initializing: boolean
user: firebase.User | null
}
export const userContext = createContext<AuthState>({
initializing: true,
@polRk
polRk / useClient.ts
Last active May 11, 2020 16:47
React Apollo useClient with authorization
import {
ApolloClient,
ApolloLink,
HttpLink,
InMemoryCache,
} from '@apollo/client'
import { getMainDefinition } from '@apollo/client/utilities'
import { setContext } from '@apollo/link-context'
import { onError } from '@apollo/link-error'
import { RetryLink } from '@apollo/link-retry'
@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()