Skip to content

Instantly share code, notes, and snippets.

View buralex's full-sized avatar

Oleksandr Burlachenko buralex

View GitHub Profile
@buralex
buralex / postgres-cheatsheet.md
Created June 18, 2019 10:27 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@buralex
buralex / tokens.md
Created September 26, 2018 15:59 — forked from zmts/tokens.md
Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Preconditions:

В данной заметке рассматривается работа JWT с симметичным алгоритмом шифрования (HS256/HS384/HS512)

Основы:

Аутентификация(authentication, от греч. αὐθεντικός [authentikos] – реальный, подлинный; от αὐθέντης [authentes] – автор) - это процесс проверки учётных данных пользователя (логин/пароль). Проверка подлинности пользователя путём сравнения введённого им логина/пароля с логином/паролем, сохранённым в базе данных пользователей.

Авторизация(authorization — разрешение, уполномочивание) - это проверка прав пользователя на доступ к определенным ресурсам.

@buralex
buralex / difference.js
Created August 16, 2018 06:38 — forked from Yimiprod/difference.js
Deep diff between two object, using lodash
/**
* Deep diff between two object, using lodash
* @param {Object} object Object compared
* @param {Object} base Object to compare with
* @return {Object} Return a new object who represent the diff
*/
function difference(object, base) {
function changes(object, base) {
return _.transform(object, function(result, value, key) {
if (!_.isEqual(value, base[key])) {
@buralex
buralex / fix-ssl-cert-snakeoil.key-ubuntu-postgresql.sh
Created August 13, 2018 20:31 — forked from GabLeRoux/fix-ssl-cert-snakeoil.key-ubuntu-postgresql.sh
Fix postgresql error FATAL: could not access private key file "/etc/ssl/private/ssl-cert-snakeoil.key": Permission denied
# > It happened to me and it turned out that I removed erroneously the postgres user from "ssl-cert" group, set it back with
gpasswd -a postgres ssl-cert
# Fixed ownership and mode
sudo chown root:ssl-cert /etc/ssl/private/ssl-cert-snakeoil.key
sudo chmod 740 /etc/ssl/private/ssl-cert-snakeoil.key
# now postgresql starts! (and install command doesn't fail anymore)
sudo /etc/init.d/postgresql start
@buralex
buralex / log-tab-focus.js
Created August 6, 2018 06:26 — forked from ryanve/log-tab-focus.js
Log :focus element each time tab key is pressed
document.addEventListener('keyup', function(e) {
9 != e.keyCode || e.metaKey || e.ctrlKey || console.log(document.activeElement)
}, false)
@buralex
buralex / gist:f94efe3331c23ac7c1f6814ff6551dae
Created August 2, 2018 20:06 — forked from tamoyal/gist:10441108
Create super user and database user in Mongo 2.6
# Create your superuser
$ mongo
> use admin
> db.createUser({user:"someadmin",pwd:"secret", roles:[{role:"root",db:"admin"}]})
> exit
# Alias for convenience (optional and at your own risk)
$ echo 'alias mongo="mongo --port 27017 -u someadmin -p secret --authenticationDatabase admin"' >> ~/.bash_profile
$ source ~/.bash_profile
@buralex
buralex / mongodb
Last active February 22, 2018 10:40
https://stackoverflow.com/questions/14226410/node-js-cannot-find-module-mongodb
npm install mongodb -g
cd /path/to/my/app/folder
npm link mongodb
With that in place, I could do this in my application file: require('mongodb').
/**/
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-mongodb-on-ubuntu-16-04
@buralex
buralex / limitLoop.js
Created February 4, 2018 13:57 — forked from addyosmani/limitLoop.js
Limit the frame-rate being targeted with requestAnimationFrame
/*
limitLoop.js - limit the frame-rate when using requestAnimation frame
Released under an MIT license.
When to use it?
----------------
A consistent frame-rate can be better than a janky experience only
occasionally hitting 60fps. Use this trick to target a specific frame-
rate (e.g 30fps, 48fps) until browsers better tackle this problem
@buralex
buralex / citystategeo.js
Last active January 2, 2018 08:37 — forked from danasilver/citystategeo.js
Get only city and state from Google Maps API Reverse Geocoder
for (var ac = 0; ac < results[0].address_components.length; ac++) {
var component = results[0].address_components[ac];
switch(component.types[0]) {
case 'locality':
storableLocation.city = component.long_name;
break;
case 'administrative_area_level_1':
storableLocation.state = component.short_name;
break;
@buralex
buralex / LICENSE
Created November 15, 2017 11:47 — forked from ourmaninamsterdam/LICENSE
Arrayzing - The JavaScript array cheatsheet
The MIT License (MIT)
Copyright (c) 2015 Justin Perry
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions: