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()
// filtering something by its lifetime with slonik
const filterByLifetimeQuery = sql`
select id
from eventlog
where
code=${code} and
payload=${sql.json(payload)} and
created_at + interval '1 second' * ${parseInt(ctx.threshold)} > now()
`
user nginx;
worker_processes auto;
error_log syslog:server=unix:/dev/log notice;
pid /var/run/nginx.pid;
#load_module modules/ngx_http_brotli_filter_module.so;
#load_module modules/ngx_http_brotli_static_module.so;
events {
worker_connections 1024;
@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.
*
@muratgozel
muratgozel / resolving_no_space_left_error.md
Created January 29, 2020 09:27
Resolving no space left on device error.

Check which filesystem doesn't have any space left:

sudo df -h

Check which folder uses this space most:

sudo find / -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n
@muratgozel
muratgozel / nodejs-simple-file-server.js
Created November 28, 2019 12:07
Simple node.js server that serves files under a certain directory.
/*
*
* usage: node server.js folder port
* - folder is "." by default which is the current directory where node has been executed.
* - port is "8080" by default and you can specify any available port in your OS.
*
*/
const http = require('http')
const fs = require('fs')
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