Skip to content

Instantly share code, notes, and snippets.

Avatar

Kostya Kostyushko Kostanos

View GitHub Profile
@Kostanos
Kostanos / insertOrUpdate.js
Created May 23, 2021
Knex Postgress ON CONFLICT (ON DUPLICATE KEY) insert
View insertOrUpdate.js
// Inspired by https://github.com/knex/knex/issues/701#issuecomment-314818463
// Will converts also CamelCase fields to SnakeCase
const knex = require('./pgAdaptor');
const camelToSnakeCase = str => str.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);
function insertOrUpdate(tableName, data, conflictKey) {
const updateTxt = Object.getOwnPropertyNames(data)
.filter(f => f !== conflictKey)
.map(field => `${camelToSnakeCase(field)}=:${field}`).join(', ');
@Kostanos
Kostanos / OpenWRT.OpenVPN.md
Last active Jan 21, 2021
OpenWRT PandoraBox OpenVPN
View OpenWRT.OpenVPN.md
@Kostanos
Kostanos / Dockerfile
Last active Jun 20, 2020
Creates multiple databases with postgresql docker image
View Dockerfile
FROM postgres:12-alpine
LABEL owner="Kostya Kostyushko"
# Custom initialization scripts
COPY ./create_user.sh /docker-entrypoint-initdb.d/10-create_user.sh
COPY ./create_db.sh /docker-entrypoint-initdb.d/20-create_db.sh
COPY ./dbInit.sql /dbInit.sql
COPY ./create_db_schemas.sh /docker-entrypoint-initdb.d/20-create_db_schemas.sh
@Kostanos
Kostanos / __init___test.py
Created Dec 30, 2017
python Settings class test
View __init___test.py
from . import Settings, cleanCache
import unittest
from unittest.mock import patch
import os
from pyfakefs import fake_filesystem, fake_filesystem_unittest
from dotmap import DotMap
# import pyfakefs.fake_filesystem_ as fake_glob
# Faking filesystem to test .yaml files
@Kostanos
Kostanos / Dockerfile
Last active Sep 17, 2017
debugColorsTest
View Dockerfile
FROM node:8-alpine
WORKDIR /root/app
CMD npm start
@Kostanos
Kostanos / json-to-csv.php
Created May 24, 2013
Convert JSON array file to CSV. Use the array keys as the first row. Command line using: json-to-csv.php json.filename > csv.filename
View json-to-csv.php
#!/usr/bin/php
<?php
/*
* Convert JSON file to CSV and output it.
*
* JSON should be an array of objects, dictionaries with simple data structure
* and the same keys in each object.
* The order of keys it took from the first element.
*
* Example:
View csv-to-json.php
#!/usr/bin/php
<?php
/*
* Converts CSV to JSON
* Example uses Google Spreadsheet CSV feed
* csvToArray function I think I found on php.net
*/
/*
* Using of script in command line:
* ./csv-to-json.php csv.file.name.or.url > json.file.name