Skip to content

Instantly share code, notes, and snippets.

@aonurdemir
aonurdemir / php
Last active December 11, 2017 07:26
PHP related commands
List all php modules
$ yum search php-
Details of a module
$ yum info <module name>
Install the module
$ sudo yum install <module name>
@aonurdemir
aonurdemir / download file php
Created December 11, 2017 07:39
download file php
$fp = fopen("file.csv", 'rb');
$stream = new \Slim\Http\Stream($fp); // create a stream instance for the response body
return $res->withHeader('Content-Type', 'application/force-download')
->withHeader('Content-Type', 'application/octet-stream')
->withHeader('Content-Type', 'application/download')
->withHeader('Content-Description', 'File Transfer')
->withHeader('Content-Transfer-Encoding', 'binary')
->withHeader('Content-Disposition', 'attachment; filename="file.csv"')
@aonurdemir
aonurdemir / find pid by port
Created December 13, 2017 07:53
find pid by port
sudo lsof -n -i :<PORT_NUMBER> | grep LISTEN
@aonurdemir
aonurdemir / geolocation
Last active December 28, 2017 07:57
Finding locations with MySQL
To find locations in your markers table that are within a certain radius distance of a given latitude/longitude, you can use a SELECT statement based on the Haversine formula. The Haversine formula is used generally for computing great-circle distances between two pairs of coordinates on a sphere. An in-depth mathemetical explanation is given by Wikipedia and a good discussion of the formula as it relates to programming is on the Movable Type Scripts website.
Here's the SQL statement that finds the closest 20 locations within a radius of 25 miles to the -33, 151 coordinate. It calculates the distance based on the latitude/longitude of that row and the target latitude/longitude, and then asks for only rows where the distance value is less than 25, orders the whole query by distance, and limits it to 20 results. To search by kilometers instead of miles, replace 3959 with 6371.
SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * si
@aonurdemir
aonurdemir / functions.php
Created January 4, 2018 07:53
Slim functions
Redirect
return $res->withRedirect("/login");
Get GET parameters
$jobId = $req->getQueryParams()['jobId']; //checks _GET [IS PSR-7 compliant]
Get POST parameters
$filename = $req->getParsedBody()['filename'];
Sanitize query param
$jobId = filter_var($jobId, FILTER_SANITIZE_NUMBER_INT);

Multiple MySQL Versions with Homebrew

For homebrew version 0.9.5.

brew -v # => Homebrew 0.9.5

Install the current version of mysql.

# Install current mysql version

brew install mysql

@aonurdemir
aonurdemir / commands.md
Created August 10, 2018 11:40
mysql5.7 php apache stack installation in macosx high sierra
@aonurdemir
aonurdemir / gist:b16e3f4461d0c020c60563d88c5f734c
Created August 30, 2018 09:28
Design and Code Review Checklist
Review Unit Tests
Is the code in the right place?
Does the name space make sense? http://blogs.msdn.com/brada/articles/361363.aspx
Is the class / procedure / variable scope correct.
Are the Classes, methods, and variables named correctly? http://blogs.msdn.com/brada/articles/361363.aspx
Are the methods, and variables typed correctly?
Look at the code.
Review for OCP (open closed principle - Open for extension closed for modification)
Review for DRY Principle (Don't Repeat Yourself - abstract common things and put in single place).
Review for SRP (Single Responsibility Principle - every object has a single responsibility. All the object's services should be focused on that responsibility).
@aonurdemir
aonurdemir / Dockerfile
Last active October 25, 2018 07:44
Docker ubuntu php
FROM php:7.2-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-install -j$(nproc) iconv \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install -j$(nproc) pdo pdo_mysql
&& docker-php-ext-install -j$(nproc) bcmath
@aonurdemir
aonurdemir / info.txt
Last active July 6, 2020 22:14
Docker image manipulations
http://ropenscilabs.github.io/r-docker-tutorial/04-Dockerhub.html
precondition: docker should be installed and you should be logged in in your system.
precondition2: use .dockerignore file near the Dockerfile as:
*
!Dockerfile
in the folder where Docker file resides, run:
docker build .