Skip to content

Instantly share code, notes, and snippets.

View muratgozel's full-sized avatar

Murat Gözel muratgozel

View GitHub Profile
@muratgozel
muratgozel / constants.js
Last active December 15, 2021 10:34
Sheet size and cost computation of the machine.
function constants() {
const data = {
T: { // levha kalınlıkları
single: 3,
double: 5
},
tCostFactor: { // levha maliyetleri
single: 5.5,
double: 8.5
},
@muratgozel
muratgozel / findDockerServiceIdByName.js
Created October 27, 2021 14:15
Find docker service id by service name in docker compose.
import {execSync} from 'child_process'
const service = 'some_service'
const containerId = execSync(`docker ps -f name=${service} --quiet`).toString().trim()
@muratgozel
muratgozel / configure_directory_permissions.sh
Last active November 2, 2020 09:37
Configure existing and future file and folder user and group permissions recursively in linux.
#!/bin/bash
SAMPLE_DIR=/mnt/some-volume
# change ownership of the directory and all of its contents
chown -R cmsman:cmsteam $SAMPLE_DIR
# change permissions of the directory and all of its contents
chmod -R u=rwX,g=rwX,o-rwx $SAMPLE_DIR
# set uid and gid
chmod -R u+s $SAMPLE_DIR
@muratgozel
muratgozel / gen_rsa_key_pair.sh
Created October 26, 2020 15:57
Generate RSA private and public key pair with OpenSSL.
openssl genrsa -out cms_auth_key.pem 4096
openssl rsa -in cms_auth_key.pem -outform PEM -pubout -out cms_auth_key_public.pem
@muratgozel
muratgozel / cross-browser-performance-library.js
Created February 9, 2020 10:39
Tiny, cross browser frontend performance checking library.
/*
*
* Purformance
*
* Simply use mark and measure methods similar to native performance api.
*
* Native performance methods are not supported by browsers
* and there is no better way to measure performance than Date.getTime()
* in those cases.
*
function configureTimeAgo(element) {
const elementID = element.getAttribute('id')
let updater = setInterval(function() {
const elementStillExistInDOM = document.getElementById(elementID)
if (!elementStillExistInDOM) {
clearInterval(updater)
return;
}
const seconds = (Date.now() - parseFloat(element.dataset.timestamp)) / 1000
#!/bin/bash
# set env vars from .env file
set -a
. $1
set +a
# set backup filename
datetime=$(date +%Y-%m-%d-%H-%M-%S)
filename="${datetime}.gz"
mongodb://$user:$password@localhost:27027/?authMechanism=DEFAULT&authSource=$dbname
mongodb://$user:$password@$host1:27017,$host2:27017/?replicaSet=rs0&authMechanism=DEFAULT&authSource=$dbname
@muratgozel
muratgozel / doesnt_exist.sh
Last active February 6, 2019 12:46
Some useful bash functions to check if something doesn't exist in Linux OS.
# check if user doesn't exist
function user_doesnt_exist {
if id -u "$1" >/dev/null 2>&1; then
return 1
else
return 0
fi
}
# usage. do something if the user abc doesn't exist.
@muratgozel
muratgozel / gen-static-pages.js
Last active March 12, 2024 03:25
Static page generation with puppeteer headless chrome for javascript web apps.
const os = require('os')
const crypto = require('crypto')
const path = require('path')
const fs = require('fs')
const util = require('util')
const puppeteer = require('puppeteer')
const libxml = require('libxmljs')
const dayjs = require('dayjs')
// generates static html files for server side rendering