Skip to content

Instantly share code, notes, and snippets.

View alaztetik's full-sized avatar
😁
Happy developer

Alaz Tetik alaztetik

😁
Happy developer
View GitHub Profile
@alaztetik
alaztetik / mongodb-on-linux.md
Created June 6, 2022 20:01
How to run mongod (server) and mongo/mongos shell on Linux
# start the server:
mongod --dbpath /path/to/data/to/be/stored --logpath /log/path/mongo.log

# enter the shell:
mongo
# or
mongos
@alaztetik
alaztetik / mariadb-setup-on-manjaro.md
Created May 16, 2022 19:41
This code shows how to manage a local MariaDB server on local

Setup for MariaDB / MySQL on Manjaro Linux

Follow these steps for a PHP-MariaDB project:

sudo pacman -S php mariadb mariadb-clients mariadb-libs
sudo mariadb-install-db
sudo systemctl enable mariadb.service
sudo systemctl start mariadb.service
sudo systemctl status mariadb.service
@alaztetik
alaztetik / docker-on-manjaro.sh
Last active February 24, 2022 19:17
Docker on Manjaro Linux
# make packages up to date
sudo pacman -Syu
# install Docker
sudo pacman -S docker
# start Docker service
sudo systemctl start docker.service
# stop Docker service
@alaztetik
alaztetik / create_folders.py
Created December 4, 2021 11:33
Creates folders with fixed prefix and incremental numbers at the end
import os
def create_folders(num, prefix=''):
"""Creates specified numbers of folders with a prefix in front of each"""
for num in range(1, num+1):
if not os.path.exists(f"{prefix}{str(num)}"):
os.makedirs(f"{prefix}{str(num)}")
@alaztetik
alaztetik / alias_for_jvm.sh
Created May 25, 2021 05:53
Multiple JVMs on one machine
# add following lines to the .bashrc file
alias java11='/usr/lib/jvm/java-11-openjdk/bin/java'
alias javac11='/usr/lib/jvm/java-11-openjdk/bin/javac'
alias java16='/usr/lib/jvm/jdk-16.0.1/bin/java'
alias javac16='/usr/lib/jvm/jdk-16.0.1/bin/javac'
alias jshell16='/usr/lib/jvm/jdk-16.0.1/bin/jshell'
@alaztetik
alaztetik / postgresql.sh
Created May 8, 2021 08:14
PostgreSQL install and start-up on Linux
sudo pacman -Sy postgresql
sudo -u postgres -i initdb /var/lib/postgres/data
sudo systemctl start postgresql && sudo systemctl status postgresql
sudo systemctl enable postgresql
sudo su - postgres
psql
# SQL commands
exit
@alaztetik
alaztetik / getMaxSubSumFast.js
Created January 12, 2021 20:18
Finding the contiguous/continuous subarray of an array argument with the maximal sum of items
// Fast:
function getMaxSubSum(arr) {
let maxSum = 0;
let partialSum = 0;
for (let item of arr) { // for each item of arr
partialSum += item; // add it to partialSum
maxSum = Math.max(maxSum, partialSum); // remember the maximum
if (partialSum < 0) partialSum = 0; // zero if negative
}
@alaztetik
alaztetik / sortArrayObjects.js
Created January 6, 2021 05:08
A function that will sort an array of objects according to primary and secondary properties in order
const sortArrayObjs = function(arr, prop1, prop2) {
let sort1 = [...arr].sort((a, b) => {
if (a[prop1] == b[prop1]) {
if (a[prop2] === b[prop2]) return 0;
return (a[prop2] < b[prop2]) ? -1 : 1;
} else {
return (a[prop1] < b[prop1]) ? -1 : 1;
}
});
return sort1;
@alaztetik
alaztetik / getDOMElement.js
Created December 15, 2020 07:22
Get DOM elements quickly
var el = function (element) {
if (element.charAt(0) === "#") {
// If passed an ID...
return document.querySelector(element); // ... returns single element
}
return document.querySelectorAll(element); // Otherwise, returns a nodelist
};
@alaztetik
alaztetik / exec.js
Created April 14, 2020 08:57
Executing Shell Commands with Node.js
const { exec } = require("child_process");
exec("ls -la", (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {