Skip to content

Instantly share code, notes, and snippets.

View jbutko's full-sized avatar

Jozef Butko jbutko

View GitHub Profile
@jbutko
jbutko / async-await-examples.md
Created January 23, 2019 10:23
Async/Await examples

serial processing

async function printFiles () {
  const files = await getFilePaths();

  for (const file of files) {
    const contents = await fs.readFile(file, 'utf8');
    console.log(contents);
  }
}
@jbutko
jbutko / how-to-setup-prettier.md
Last active January 10, 2019 16:18
How to setup prettier (sublime text)

Prettier setup

install prettier locally in project as well as globaly for support in your code editor

npm i -g prettier
npm i prettier --save-dev

add .prettierrc configuration file:

{
@jbutko
jbutko / mobx-replace-array-item.js
Created September 11, 2018 06:16
MobX: Replacing item in observable array
const oldQuestion = this.questionsList.find(q => q.id === newQuestionId);
extendObservable(oldQuestion, newQuestionObject);
// via From https://stackoverflow.com/questions/39543194/mobx-replacing-item-in-observable-array/39546605
@jbutko
jbutko / state-leave-listener.js
Created September 10, 2018 20:29
React Native: Leave screen callback React Navigation Tab Navigator
const didBlurSubscription = this.props.navigation.addListener(
'didBlur',
payload => {
console.debug('didBlur', payload);
}
);
// Remove the listener when you are done
didBlurSubscription.remove();
// Payload
@jbutko
jbutko / detect-scroll.js
Created September 10, 2018 06:28
React Native: Detect ScrollView has reached the end
import React from 'react';
import {ScrollView, Text} from 'react-native';
const isCloseToBottom = ({layoutMeasurement, contentOffset, contentSize}) => {
const paddingToBottom = 20;
return layoutMeasurement.height + contentOffset.y >=
contentSize.height - paddingToBottom;
};
const MyCoolScrollViewComponent = ({enableSomeButton}) => (
@jbutko
jbutko / git-useful-commands.sh
Last active January 31, 2019 09:06
Git: useful commands
# ignore files locally
git update-index --assume-unchanged file
# or
git update-index --skip-worktree file
# to revert
git update-index --no-assume-unchanged file
git update-index --no-skip-worktree package-lock.json
# properly rename caseSensitive folders
git mv casesensitive tmp
@jbutko
jbutko / nginx-renew-certs-cron.sh
Last active October 2, 2018 11:48
Nginx: renew certs cron job
# try to renew certs every sunday at 02:00 and log the result in /var/log/lets-encrypt-renew.log
0 2 * * 7 /opt/certbot/certbot-auto renew --dry-run --pre-hook "nginx service stop" --post-hook "nginx service start" >> /var/log/lets-encrypt-renew.log
# renewing manually
be sure to enable 80 port, disable all 301/302 redirects in your `.conf` files so letsencrypt can access http challenges
@jbutko
jbutko / nginx-host-static-content-folder.sh
Last active December 25, 2018 22:29
Nginx: host static content
location /static {
alias /path/to/static/files;
}
# via From https://stackoverflow.com/questions/29383159/how-do-you-serve-static-files-from-an-nginx-server-acting-as-a-reverse-proxy-for
# or
https://medium.com/@jgefroh/a-guide-to-using-nginx-for-static-websites-d96a9d034940
@jbutko
jbutko / cache-git-password.md
Created May 22, 2018 10:42
Cache SSH key password in git
@jbutko
jbutko / mongodb-cheat-sheet.MD
Last active May 7, 2018 20:42
MongoDB cheat sheet

explain find query

db.collection.find({...}).explain('executionStats')

  • or allPlansExecution

explain aggregate

db.collection.explain('executionStats').aggregate([{...}])

get indexes

db.collection.getIndexes()