Skip to content

Instantly share code, notes, and snippets.

View muratgozel's full-sized avatar

Murat Gözel muratgozel

View GitHub Profile
@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 / 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 / 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 / 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
#!/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
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
@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 / how-to-kill-process-locks-certain-port.md
Created September 2, 2017 21:57
Find and kill that process that cause "address already in use" error on mac
lsof -i :[PORT]  
kill -9 [PID]
@muratgozel
muratgozel / Object.extract.js
Created August 8, 2017 08:36
Creates a new javascript object from bigger javascript object by taking certain properties from it.
/*
* Creates a new javascript object from bigger javascript object by taking certain properties from it.
*
* @param {object} input - Main javascript object
* @param {array} keys - Keys that will be used to create a new object.
*/
Object.prototype.extract = function extract(input, keys) {
return Object.prototype.toString.call(input) === '[object Object]'
? Object.keys(input)
@muratgozel
muratgozel / generate_key_cert_pair.sh
Last active August 4, 2017 18:28
Generates private key - public certificate pair in a single command.
# Remove -nodes if you want to protect the cert with a password.
openssl req -x509 -newkey rsa:4096 -keyout sample-key.pem -out sample-cert.pem -days 365 -subj '/CN=sample.com/O=Sample Corp./C=US' -nodes