Skip to content

Instantly share code, notes, and snippets.

View ZhandosKz's full-sized avatar
🎯
Focusing

Zhandos ZhandosKz

🎯
Focusing
View GitHub Profile
<?php
function getGeo($lat, $lng, $dist, $brng)
{
$lat = deg2rad($lat);
$lng = deg2rad($lng);
$brng = deg2rad($brng);
$distRadius = $dist / 6371;
$lat2 = asin(sin($lat) * cos($distRadius) +
cos($lat) * sin($distRadius) * cos($brng) );
<?php
public function actionReplica() {
$this->file = fopen('update.sql', 'r');
if (!$this->file) {
throw new CHttpException(404, 'no worker');
}
flock($this->file, LOCK_EX);
$output = fopen('update_2.sql', 'w');
@ZhandosKz
ZhandosKz / gist:6786141
Created October 1, 2013 22:20
carbage collector
git reflog expire --expire=now --expire-unreachable=now --all
git gc --prune=now
@ZhandosKz
ZhandosKz / gist:6745376
Last active December 24, 2015 04:39
google maps v3 geocoder
<?php
class Geocoder
{
public static $url = 'http://maps.googleapis.com/maps/api/geocode/json';
public function performRequest($search)
{
$url = sprintf("%s?address=%s&sensor=false", self::$url, urlencode($search));
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@ZhandosKz
ZhandosKz / gist:6464831
Created September 6, 2013 14:45
import sql file from comand line
mysql -uusername -p
enter password
use tablename
source path_to_sql_file
<?php
class Foo
{
public $firstValue;
public $secondValue;
public $thirdValue;
public function __construct($v1, $v2, $v3)
{
// ...
}
<?php
$arr = array(
array(
'value' => 'some#1',
'otherProperty' => '...'
),
array(
'value' => 'some#2',
'otherProperty' => '...'
),
<?php
class Foo
{
public $value;
}
$obj_1 = new Foo();
$obj_1->value = 1;
@ZhandosKz
ZhandosKz / gist:6269679
Last active December 21, 2015 07:09
TbJsonGridView example
<?php
// Controller
class TestController extends CController
{
public function actionIndex()
{
$items = array(
array('id' => 1, 'name' => 'Debora'),
array('id' => 2, 'name' => 'Joshua'),
array('id' => 3, 'name' => 'Kristina'),
$users = User::model()->findAll();
/**
* @var CAuthManager $authManager
*/
$authManager = Yii::app()->authManager;
$statuses = array(
ExtendedDbAuthManager::APPROVED => 0,
ExtendedDbAuthManager::BANNED => 0,