Skip to content

Instantly share code, notes, and snippets.

@yadakhov
yadakhov / php
Created October 27, 2015 21:36
php-cs-fixer rules and description
$fixers = [
'psr0', // [PSR-0] Classes must be in a path that matches their namespace, be at least one namespace deep, and the class name should match the file name.
'encoding', // [PSR-1] PHP code MUST use only UTF-8 without BOM (remove BOM).
'short_tag', // [PSR-1] PHP code must use the long tags or the short-echo tags it must not use the other tag variations.
'braces', // [PSR-2] The body of each structure MUST be enclosed by braces. Braces should be properly placed. Body of braces should be properly indented.
'elseif', // [PSR-2] The keyword elseif should be used instead of else if so that all control keywords looks like single words.
@yadakhov
yadakhov / conf
Created July 30, 2015 11:05
nginx server conf for https removing www
# http://example.com => https://example.com
# http://www.example.com => https://example.com
# https://www.example.com => https://example.com
# https://example.com => https://example.com
# everything goes to https://example.com
server {
server_name example.com.com www.example.com.com;
return 301 https://example.com.com$request_uri;
}
@yadakhov
yadakhov / gist:741173ae893c1042973b
Created July 23, 2015 20:54
Laravel MyModel class
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
/**
* This class acts as our Base Model
*
* @package App\Models
$a = array('foo' => array('bar' => array('baz' => 1)));
function resolve(array $a, $path, $default = null)
{
$current = $a;
$p = strtok($path, '.');
while ($p !== false) {
if (!isset($current[$p])) {
return $default;
@yadakhov
yadakhov / SqrtNewtonMethod.java
Created August 16, 2012 13:51
Square Root using Newton's Method
/**
* Computes the square root of a nonnegative number c using
* http://en.wikipedia.org/wiki/Newton's_method
* Newton's method:
* - initialize t = c
* - replace t with the average of c/t and t
* - repeat until desired accuracy reached
*
* % java Sqrt 2
* 1.414213562373095
@yadakhov
yadakhov / gist:3258162
Created August 4, 2012 14:43
Get next working day.
<?php
/**
* Get next working day.
* Does NOT account for holidays.
* @param $timestamp
* @param int $numDays
* @return int
*/
function getNextWorkingDay($timestamp, $numDays = 1) {
// add the number of days passed but skip weekends
@yadakhov
yadakhov / daysInMonth.php
Created August 4, 2012 14:12
Number of days in a month
<?php
/**
* Returns the number of days in a month
* @param $year
* @param $month
* @return $daysInMonth
*/
function daysInMonth($year, $month) {
return date('t', strtotime($year.'-'.$month.'-01'));
}
@yadakhov
yadakhov / mysql
Created March 30, 2012 16:06
mysql create tempory table for select statement
-- TEMP TABLE FOR SELECTS
CREATE TEMPORARY TABLE temp_table AS
SELECT * FROM table1 a JOIN table2 b ON a.id = b.id;
SELECT * FROM temp_table;