Skip to content

Instantly share code, notes, and snippets.

@oleg-koval
oleg-koval / index.js
Created August 3, 2018 12:21
Reduce usage: findLongestWordLength
function findLongestWordLength(str) {
return str.split(' ').reduce((prev, curr) => {
if (prev.length > curr.length) {
return prev
}
return curr
}).length;
}
@oleg-koval
oleg-koval / revert-a-commit.md
Created July 12, 2018 11:33 — forked from gunjanpatel/revert-a-commit.md
Git HowTo: revert a commit already pushed to a remote repository

Revert the full commit

Sometimes you may want to undo a whole commit with all changes. Instead of going through all the changes manually, you can simply tell git to revert a commit, which does not even have to be the last one. Reverting a commit means to create a new commit that undoes all changes that were made in the bad commit. Just like above, the bad commit remains there, but it no longer affects the the current master and any future commits on top of it.

git revert {commit_id}'

About History Rewriting

Delete the last commit

Deleting the last commit is the easiest case. Let's say we have a remote origin with branch master that currently points to commit dd61ab32. We want to remove the top commit. Translated to git terminology, we want to force the master branch of the origin remote repository to the parent of dd61ab32:

@oleg-koval
oleg-koval / pr.md
Created June 27, 2018 13:43 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@oleg-koval
oleg-koval / f_truncate_tables.sql
Last active October 1, 2022 22:44
Script to cleanup (truncate tables) data from Postgresql
CREATE OR REPLACE FUNCTION public.truncate_tables(username character varying)
RETURNS void
LANGUAGE plpgsql
AS $function$
DECLARE
statements CURSOR FOR
SELECT tablename FROM pg_tables
WHERE tableowner = username AND schemaname = 'public';
BEGIN
FOR stmt IN statements LOOP
@oleg-koval
oleg-koval / Git push deployment in 7 easy steps.md
Created March 14, 2018 10:31 — forked from thomasfr/Git push deployment in 7 easy steps.md
7 easy steps to automated git push deployments. With small and configurable bash only post-receive hook
@oleg-koval
oleg-koval / Procfile
Created March 14, 2018 10:29
Create the job for expiring round after 24h with kue
web: node index.js
worker: node queue.js
@oleg-koval
oleg-koval / docker-cleanup.sh
Created March 9, 2018 13:54 — forked from Karreg/docker-cleanup.sh
Script to cleanup Docker leftovers, related to https://github.com/moby/moby/issues/22207
#!/bin/bash
echo "WARN: This will remove everything from docker: volumes, containers and images. Will you dare? [y/N] "
read choice
if [ \( "$choice" == "y" \) -o \( "$choice" == "Y" \) ]
then
sudo echo "> sudo rights [OK]"
sizea=`sudo du -sh /var/lib/docker/aufs`
@oleg-koval
oleg-koval / cancelable-promise.js
Created March 8, 2018 09:38 — forked from tracker1/cancelable-promise.js
JavaScript Cancelable Promise
var CancelablePromise = (function(){
var cancelledPromiseSymbol = Symbol('PROMISE_CANCELLED');
function createTypeError(message) {
var error = new TypeError(message);
var stack = error.stack.split('\n');
stack.splice(1, 1);
stack[1] = stack[1].replace(/:\d+:\d+\)$/, ')');
error.stack = stack.join('\n');
throw error;
@oleg-koval
oleg-koval / docker-cleanup-resources.md
Created March 2, 2018 08:51 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

@oleg-koval
oleg-koval / truncate_tables.sql
Created February 23, 2018 13:54
Truncating all tables in a Postgres database
CREATE OR REPLACE FUNCTION truncate_tables(username IN VARCHAR) RETURNS void AS $$
DECLARE
statements CURSOR FOR
SELECT tablename FROM pg_tables
WHERE tableowner = username AND schemaname = 'public';
BEGIN
FOR stmt IN statements LOOP
EXECUTE 'TRUNCATE TABLE ' || quote_ident(stmt.tablename) || ' CASCADE;';
END LOOP;
END;