Skip to content

Instantly share code, notes, and snippets.

View muratgozel's full-sized avatar

Murat Gözel muratgozel

View GitHub Profile
@muratgozel
muratgozel / convertMinutesToHours.js
Last active November 22, 2017 13:09
Convert minutes to hours Number -> HH:HH
function convertMinsToHours(input) {
if (typeof input != 'number') {
return ''
}
const m = input < 0 ? -1 : 1
const k = Math.floor(input*m % 60)
const b = Math.floor(input*m / 60)
return (m==-1 ? '-' : '+') +
@muratgozel
muratgozel / composer-setup.sh
Last active February 28, 2018 23:39
Apache, PHP 5.6, Mysql Stack Setup on Ubuntu 16
#!/bin/sh
EXPECTED_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig)
sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
then
>&2 echo 'ERROR: Invalid installer signature'
sudo rm composer-setup.php
#!/bin/sh
# Don't forget to run "sudo chmod a+x filename" to give this script neccessary permissions in order to work properly.
osascript <<EOD
tell application "Google Chrome"
set windowList to every window
repeat with aWindow in windowList
set tabList to every tab of aWindow
repeat with atab in tabList
@muratgozel
muratgozel / composer-setup.sh
Created April 10, 2018 20:55
Composer setup shell script.
#!/bin/sh
EXPECTED_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig)
sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
then
>&2 echo 'ERROR: Invalid installer signature'
sudo rm composer-setup.php
@muratgozel
muratgozel / outbound-traffic-over-floating-ip.sh
Created September 6, 2018 18:50
Which IP address is nginx or apache using while making outbound request?
# 1. Option: From the Terminal
# Get internal ip addresses
hostname -I
# Get the ip address which is starting with 10.XXX.XXX.XXX from the output.
# And place it in the command below.
wget --bind-address=10.XXX.XXX.XXX https://example.com
@muratgozel
muratgozel / install_pillow.sh
Created November 28, 2018 15:39
install pillow (python imaging library) on ubuntu 18.04 (bionic)
#!/bin/bash
apt update
apt install python3-pip -y
apt install libjpeg8-dev zlib1g-dev libtiff-dev libfreetype6 libfreetype6-dev libwebp-dev libopenjp2-7-dev libopenjp2-7-dev -y
pip3 install pillow --global-option="build_ext" --global-option="--enable-zlib" --global-option="--enable-jpeg" --global-option="--enable-tiff" --global-option="--enable-freetype" --global-option="--enable-webp" --global-option="--enable-webpmux" --global-option="--enable-jpeg2000"
@muratgozel
muratgozel / resize-and-crop-with-pillow.py
Created December 1, 2018 13:55
Resizes and crops the given image using Python Pillow. Support multi frame images such as GIF and WebP.
from math import floor, fabs
from PIL import Image, ImageSequence
def transform_image(original_img, crop_w, crop_h):
"""
Resizes and crops the image to the specified crop_w and crop_h if necessary.
Works with multi frame gif and webp images also.
args:
original_img is the image instance created by pillow ( Image.open(filepath) )
@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
@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.
mongodb://$user:$password@localhost:27027/?authMechanism=DEFAULT&authSource=$dbname
mongodb://$user:$password@$host1:27017,$host2:27017/?replicaSet=rs0&authMechanism=DEFAULT&authSource=$dbname