Skip to content

Instantly share code, notes, and snippets.

@kanonji
kanonji / ConstMapTrait.php
Created October 16, 2014 10:40
Const map trait
<?php
trait ConstMapTrait{
private static $const_map = [];
public static function const_map($prefix = 0){
if(! isset(self::$const_map[$prefix])){
if(0 === $prefix){
self::$const_map[$prefix] = (new \ReflectionClass(get_called_class()))->getConstants();
} else {
self::const_map();
$list = self::$const_map[0];
@sundaycrafts
sundaycrafts / preventPullToRefresh.js
Created May 23, 2015 06:16
prevent pull to refresh mobile chrome feature
/**
* inspired by jdduke (http://jsbin.com/qofuwa/2/edit)
*/
var preventPullToRefresh = (function preventPullToRefresh(lastTouchY) {
lastTouchY = lastTouchY || 0;
var maybePrevent = false;
@mcaskill
mcaskill / Function.Array-Group-By.php
Last active June 19, 2025 00:50
PHP : Groups an array by a given key
<?php
if (!function_exists('array_group_by')) {
/**
* Groups an array by a given key.
*
* Groups an array into arrays by a given key, or set of keys, shared between all array members.
*
* Based on {@author Jake Zatecky}'s {@link https://github.com/jakezatecky/array_group_by array_group_by()} function.
* This variant allows $key to be closures.
@hassansin
hassansin / eloquent-cheatsheet.php
Last active April 10, 2025 08:32
Laravel 5 Eloquent CheatSheet #laravel #eloquent
Model::
/*Select*/
select('col1','col2')
->select(array('col1','col2'))
->select(DB::raw('businesses.*, COUNT(reviews.id) as no_of_ratings, IFNULL(sum(reviews.score),0) as rating'))
->addSelect('col3','col4')
->distinct() // distinct select
/*From*/
@ivanvermeyen
ivanvermeyen / EnsureQueueListenerIsRunning.php
Last active February 13, 2024 12:40
Ensure that the Laravel queue listener is running with "php artisan queue:checkup" and restart it if necessary. You can run this automatically with a cron job: http://laravel.com/docs/scheduling
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class EnsureQueueListenerIsRunning extends Command
{
/**
* The name and signature of the console command.
@spalladino
spalladino / mysql-docker.sh
Created December 22, 2015 13:47
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@davidrushton
davidrushton / Kernel.php
Created February 17, 2016 17:29
Laravel 5 Database Queue - Shared Hosting
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
@themsaid
themsaid / HasEnums.php
Last active August 29, 2020 23:23
PHP Enumerated Type
trait HasEnums
{
/**
* The array of enumerators of a given group.
*
* @param null|string $group
* @return array
*/
static function enums($group = null)
{
@jhoff
jhoff / Enums.php
Last active July 20, 2025 00:04
Laravel Model Enumeration Trait
<?php
namespace App\Traits;
use Illuminate\Support\Str;
use App\Exceptions\InvalidEnumException;
trait Enums
{
/**
<?php
/**
* Trait EnumTrait
* @author Philipp Dahse <[email protected]>
*/
trait EnumTrait
{
/**
* @return array