Skip to content

Instantly share code, notes, and snippets.

View PoTHuYJoHN's full-sized avatar

Ivan Kolodiy PoTHuYJoHN

View GitHub Profile
@PoTHuYJoHN
PoTHuYJoHN / 1.Create config file first
Last active June 11, 2017 10:16
Generate SSL certificate on Mac OS and add to virtual host
STEP 1
cat > openssl.cnf <<-EOF
[req]
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
CN = *.ua.l
[v3_req]
keyUsage = keyEncipherment, dataEncipherment
function authInterceptor($rootScope, localStorageService, $q, $timeout, $location, APP_CONFIG) {
return {
response : function(response) {
if(response) {
var freshJwt = response.headers().authorization;
if (freshJwt) {
//refresh local token
localStorageService.set(APP_CONFIG.jwt_key, freshJwt);
@PoTHuYJoHN
PoTHuYJoHN / trial_carbon.php
Created May 31, 2017 11:32
Trial time with Carbon
<?php
class ServicePackageRepository
{
/**
* @return int
*/
public function getTrialDaysCount()
{
$cDate = Carbon::parse(self::TRIAL_DUE_FOR_STANDARD_PLAN);
@PoTHuYJoHN
PoTHuYJoHN / laravel_query_by_month.php
Last active April 29, 2017 13:07
Laravel query DB by month from related table and convert string value to date
<?php
/**
* Find Landing pages where has fields with date value by month
* Date format is mm/dd/yyyy
*/
$eventItemsIds = LandingPage::where('section', 'events_items')->whereHas('fields', function ($query) use($month,$year) {
$query->whereHas('texts', function($query) use($month,$year) {
$query->where(\DB::raw('MONTH(STR_TO_DATE(value, \'%m/%d/%Y\'))'), '=', $month)
->where(\DB::raw('YEAR(STR_TO_DATE(value, \'%m/%d/%Y\'))'), '=', $year);
});
@PoTHuYJoHN
PoTHuYJoHN / ThreadRepository.php
Last active January 15, 2016 12:54
Search threads using whereHas and orWhereHas
<?php
$q = 'someFirstNameOrLastNameOrCompany';
$limit = 20;
$threads = Thread::latest('updated_at')
->whereHas('participants', function($query) use($q) {
$query->whereHas('user', function($query) use($q) {
//search connected two tables if any of them has record appropriate to $q
$query->where(function($subQuery) use($q) {
@PoTHuYJoHN
PoTHuYJoHN / common.php
Created February 4, 2015 10:39
SEO trait
<?php
abstract class Controller_Common extends Controller
{
use Traits_ItemSeo;
public function after()
{
$view->title = $this->getMetaTitle();
$view->description = $this->getMetaDescription();
$view->socialTitle = $this->getSocialTitle() ?: $this->getMetaTitle();
@PoTHuYJoHN
PoTHuYJoHN / html.php
Created December 22, 2014 15:12
Convert double quotes to single for Facebook share
<?php
/**
* Persist quotes. For Facebook share etc.
* @param string $value
*
* @return mixed
*/
public static function convertQuotes($value)
{
return str_replace('"', '\'', htmlspecialchars_decode($value, ENT_QUOTES));
@PoTHuYJoHN
PoTHuYJoHN / image_size.js
Created October 10, 2014 07:22
Get image size via JS
myImage.addEventListener('onload', function() {
console.log('My width is: ', this.naturalWidth);
console.log('My height is: ', this.naturalHeight);
});
@PoTHuYJoHN
PoTHuYJoHN / gist:7747072
Created December 2, 2013 09:28
Генерация нового названия, если файл с таким именем уже существует
<?php
function file_newname($path, $filename){
if ($pos = strrpos($filename, '.')) {
$name = substr($filename, 0, $pos);
$ext = substr($filename, $pos);
} else {
$name = $filename;
}
$newpath = $path.'/'.$filename;
@PoTHuYJoHN
PoTHuYJoHN / map
Last active December 27, 2015 11:29
Google maps карта
<?=Html::anchor(
'http://maps.google.com/maps?q=' . urlencode(View::$global->settings['address']) . '&z=16&output=embed',
'<img src="http://maps.google.com/maps/api/staticmap?center=' . urlencode(View::$global->settings['address']) . '&zoom=15&size=390x225&sensor=false&markers=color:red%7C' . urlencode(View::$global->settings['address']) . '" alt="">',
array('class' => 'contact-map', 'onclick' => 'system.showMap(this);return false;')
)?>