Skip to content

Instantly share code, notes, and snippets.

View AlexArus's full-sized avatar

Alexander Selivanov AlexArus

View GitHub Profile
type TypesOfObjectProperties<T> = {
[K in keyof T]: T[K]
}[keyof T];
export type Optional<T = unknown> = null | T;
export const hasValue = <T,>(value: Optional<T>): value is T => value !== null;
@AlexArus
AlexArus / timeHelpers.ts
Created December 11, 2019 16:08
JavaScript time/date helpers
export const localTimeZoneName = Intl.DateTimeFormat().resolvedOptions().timeZone;
export const localTimeZoneOffsetInSeconds = -new Date().getTimezoneOffset() * 60;
@AlexArus
AlexArus / stopwatch-logger.ts
Created September 25, 2019 13:42
Stopwatch logger
type loggerLevel = 'info' | 'error' | 'warn' | 'debug';
const log = (message: string, level: loggerLevel = 'info') => {
console.log(`${new Date().toLocaleString()} [${level}] ${message}`)
}
/**
* Create Logger with stopwatch
* @param label - stopwatch logger label
* @returns - logger wrapper with stopwatch feature
@AlexArus
AlexArus / .bashrc
Created September 22, 2019 14:19
Bash PS1 with colors and git info
if [ "$color_prompt" = yes ]; then
# get current branch in git repo
function parse_git_branch() {
BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
if [ ! "${BRANCH}" == "" ]
then
STAT=`parse_git_dirty`
echo "${BRANCH}${STAT}"
else
@AlexArus
AlexArus / index.js
Created September 5, 2019 20:30
Use React to render static site
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
import ReactDOMServer from 'react-dom/server'
class Navigation extends Component {
render() {
return (
<ul>
<li>Main</li>
<li>About</li>
@AlexArus
AlexArus / bindings.json
Last active April 27, 2023 14:00
Useful keybindings for Visual Studio Code (keybindings.json) and micro (bindings.json from ~/.config/micro/bindings.json)
/**
* Useful keybindings for micro
* version: 19.12.11
* author: Alex Arus
*
* to install put it to ~/.config/micro/bindings.json
* +------------------------------------------------------------+
* | Y | U | I | O | P |
* | add cursor above| home | up | end | page up |
* |-----------------|---------|---------|---------|------------|
@AlexArus
AlexArus / logger.ts
Last active October 24, 2019 14:45
Winston logger console formatter
import { createLogger, format, transports } from 'winston';
import { loggerConfig } from '../config';
import chalk from 'chalk';
export const logger = createLogger(loggerConfig);
export const msToPrettyTime = (totalMilliseconds: number) => {
const msInSecond = 1000;
const secondInMinute = 60;
const minuteInHour = 60;