Skip to content

Instantly share code, notes, and snippets.

View okovpashko's full-sized avatar

Oleksandr Kovpashko okovpashko

View GitHub Profile
@okovpashko
okovpashko / index.js
Last active May 26, 2022 13:09
Detect UTF-8 BOM symbol with Node.js
const {open, read} = require('fs/promises');
const {resolve} = require('path');
async function main([filePath]) {
const resolvedPath = resolve(filePath);
let file;
try {
file = await open(resolvedPath);
} catch(e) {
// @flow
type Key = 'foo' | 'bar';
/**
* We must define an object type with an indexer that uses the same union type.
* Otherwise Flow will throw an error when we try accessing the value by a key
*/
const titles: {[Key]: string} = {
foo: 'This is a foo',
// @flow
import React, {type ComponentType, type AbstractComponent} from 'react';
////////////////////////////
// A generic list component
////////////////////////////
type ListProps<P> = {|
component: ComponentType<P>,
@okovpashko
okovpashko / test.js
Created September 8, 2015 21:22
Fill all text nodes on page with long text
var a,
w=document.createTreeWalker(document,NodeFilter.SHOW_TEXT);
while(a=w.nextNode()){
if(a.textContent.trim().length) {
a.textContent='Одиннадцатиклассница пошла посмотреть на достопримечательность, она шла долго, несколько строчек, пока не пришла';
}
}
@okovpashko
okovpashko / gist:6b12f7c0fefdf92dfd25
Created July 27, 2015 13:03
Convert utf8 DB with latin1 data to utf8
mysqldump --user=username --password=password --default-character-set=latin1 --skip-set-charset dbname > dump.sql
sed -i -E 's/latin1/utf8/g' dump.sql
mysql --user=username --password=password --execute="DROP DATABASE dbname; CREATE DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;"
mysql --user=username --password=password --default-character-set=utf8 dbname < dump.sql
@okovpashko
okovpashko / gist:db28f3eb7de713f399eb
Created April 21, 2015 19:31
Common screen widths for @media breakpoints
320px
480px
600px
768px
900px
1200px
@okovpashko
okovpashko / gist:5295e3a339d28de9a515
Last active August 29, 2015 14:14
Gaussian distribution
// Taken from here: http://habrahabr.ru/post/208684/
function Gauss() {
var ready = false;
var second = 0.0;
this.next = function(mean, dev) {
mean = mean == undefined ? 0.0 : mean; // математичне очікування
dev = dev == undefined ? 1.0 : dev; // середньоквадратичне відхилення