Skip to content

Instantly share code, notes, and snippets.

@ryzr
ryzr / reset AI
Created September 22, 2015 01:24
SET @count = 0;
UPDATE `tablename` SET `tablename`.`id` = @count:= @count + 1;
ALTER TABLE `tablename` AUTO_INCREMENT = 1;
<?php namespace Themes\Pharmacy4u\Models\Traits;
trait InsertIgnoreModelTrait
{
public static function insertIgnore($values){
$self = new static();
$query = $self->newBaseQueryBuilder();
if (empty($values)) return true;
@ryzr
ryzr / getCreatedAtAttribute.php
Last active April 3, 2020 02:11
Fix null/empty -0001-11-30 00:00:00 dates
use Carbon\Carbon;
public function getCreatedAtAttribute($value)
{
//fixes 0000-00-00 00:00:00 date to return 1970-01-01 09:30:00 instead of -0001-11-30 00:00:00
return Carbon::createFromTimeStamp($value)->toDateTimeString();
}
$file_name = 'anything';
$rel_path = 'uploads/' . str_slug($file_name) . '.csv';
$full_path = public_path($rel_path);
$f = fopen($full_path, 'w');
$firstLineKeys = false;
Model::select('data', 'data2')->chunk(500, function($entries) use ($f, $firstLineKeys) {
$array = json_decode(json_encode($entries), true);
function scaleObject(object, w_factor, h_factor)
{
var scaleX = object.scaleX;
var scaleY = object.scaleY;
var left = object.left;
var top = object.top;
var tempScaleX = scaleX * w_factor;
var tempScaleY = scaleY * h_factor;
var tempLeft = left * w_factor;
@ryzr
ryzr / gist:3434c650e517c7c0f50c
Last active January 13, 2016 00:06
Content + sidebar with equal height at least as tall as window
<style>
.wrapper {
position: relative;
}
.sidebar, .content {
min-height: 100%;
}
</style>
@ryzr
ryzr / YourServiceProvider.php
Last active July 23, 2018 04:19
Laravel Str Macros
<?php
Str::macro('sentences', function($value, $sentences = 2, $end = '...')
{
preg_match('/(.+?(?:(?<![\s.]\p{Lu})[.!?])){1,'.$sentences.'}/u', $value, $matches);
if (! isset($matches[0]) || static::length($value) === static::length($matches[0])) {
return $value;
}
@ryzr
ryzr / ApiAuthorizationController.php
Last active August 15, 2018 06:34
Custom Api Authorization
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Laravel\Passport\Bridge\AccessToken;
use Laravel\Passport\Bridge\AccessTokenRepository;
@ryzr
ryzr / QueryFilters.php
Last active February 12, 2019 02:39
Laravel Scout Filters with magic methods
<?php
namespace App;
use Laravel\Scoute\Builder;
use Illuminate\Http\Request;
abstract class QueryFilters
{
/**
@ryzr
ryzr / jsonToArray.php
Last active February 27, 2019 00:43
Convert JSON string to PHP short-array
<?php
$json = <<<EOT
{"PASTE_YOUR":"JSON_HERE"}
EOT;
echo '[' . PHP_EOL;
jsonToArray(json_decode($json, true), 1);
echo ']';