Skip to content

Instantly share code, notes, and snippets.

@gnchrv
gnchrv / random.swift
Last active January 24, 2018 13:17
Swift random(_:) function
// Basically, a wrapper for the standard arc4random_uniform() function
// Helps to get rid of tedious integer type conversions
import UIKit // or any other framework based on Darwin, like Foundation or Darwin itself
func random <T:FixedWidthInteger> (_ upperBound: T) -> Int{
let upperBoundAbs = abs(Int32(upperBound)) + 1 // including this one passed to the function
let randomNumber = Int(arc4random_uniform(UInt32(upperBoundAbs)))
return (upperBound < 0) ? -1 * randomNumber : randomNumber
}
@gnchrv
gnchrv / keyboardShortcuts.json
Last active July 29, 2021 09:31
VSCode Settings
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "shift+cmd+'",
"command": "openInTerminal"
},
{
"key": "cmd+'",
"command": "workbench.action.terminal.toggleTerminal"
},
@gnchrv
gnchrv / index.js
Last active May 29, 2019 13:26
Построение графика движения рабочих по календарному плану (output-1.csv и output-2.csv — результаты для первой и второй смен, соответственно)
const jsonexport = require('jsonexport')
const CSV = require('csvtojson')
const fs = require('fs')
// Путь к файлу
const file = __dirname + '/input.csv'
// Настраиваем csv-парсер
const csv = CSV({
delimiter: ';',
@gnchrv
gnchrv / wikipedia-subdomains-list.js
Last active November 23, 2019 22:19
List all Wikipedia language-specific subdomains
// Run this bookmarlet on the page containing a list of active Wikipedias → https://en.wikipedia.org/wiki/List_of_Wikipedias
[...document.querySelectorAll('table')[1]
.querySelectorAll('tr')
].filter(tr => !tr.innerText.includes('(closed)'))
.map(tr => tr.querySelector('a.extiw'))
.filter(a => a)
.filter(a => !a.title.includes('Special') && !a.title.includes('Stat'))
.map(a => a.title.replace(/:.*/, ''))
.join()
@gnchrv
gnchrv / config.js
Last active December 19, 2019 23:12
Configuration of .env-variables in Node.js
// Reqruire and execute this module in the beginning of every entry point of the application
const dotenv = require('dotenv')
let configured = false
module.exports = () => {
// Quit if it's been already configured
if (configured) return
// Otherwise configure and leave a note
export PATH=$PATH:/usr/local/bin
alias gs="git status"
alias gc="git commit -m"
alias ga="git add"
alias gac="git add . ; git commit -m"
alias gl="git log"
alias gcam="git commit --amend --no-edit"
export PATH=$PATH:/Users/gnchrv/bin
source ~/.bashrc
@gnchrv
gnchrv / update-dependencies.sh
Created October 6, 2022 16:43
How to update project dependencies in a package.json file
npm install -g npm-check-updates
ncu -u
npm install
@gnchrv
gnchrv / readme.md
Last active September 4, 2023 13:17

Toggle Component Names Demo

Toggle Component Names

Букмарклет для подсветки компонентов на сайтах.

Находит на странице элементы, CSS-классы которых содержат строку component, подсвечивает эти блоки и отображает их названия.

Названия компонентов формируются из их CSS-классов: всё, что идёт перед строкой component, попадает в название компонента.

Первый запуск букмарклета включает подсветку компонентов, повторный — отключает.

@gnchrv
gnchrv / App.tsx
Last active September 26, 2023 08:07
import { useRef, useState, useEffect } from 'react'
import Slider from './components/slider/slider'
import * as Plot from '@observablehq/plot'
function App() {
const [points, setPoints] = useState(10)
const [max, setMax] = useState(10)
const plotContainer = useRef<HTMLDivElement>(null)
useEffect(() => {
@gnchrv
gnchrv / styles.css
Created March 5, 2024 09:57
Arc Boost for RocketChat
:root {
--f-family-system: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
--rcx-color-foreground-info: #999 !important;
}
/* Ячейка чата в сайдбаре */
.rcx-sidebar-item {
padding: .45rem 1.25rem !important;
}