Skip to content

Instantly share code, notes, and snippets.

View ternavsky's full-sized avatar

Eugene Ternavsky ternavsky

  • https://simplecodesoftware.com/
  • Russia, Novocherkassk
View GitHub Profile
@ternavsky
ternavsky / queue-ensure.php
Last active August 26, 2016 12:08 — forked from mauris/queue-ensure.php
Laravel Artisan Queue Ensurer - Set a cron job to run this file periodically to ensure that Laravel's queue is processing all the time. If the queue listener was down, it would restart it!
<?php
function runCommand ()
{
$command = 'php artisan queue:listen > /dev/null & echo $!';
$number = exec($command);
file_put_contents(__DIR__ . '/queue.pid', $number);
}
if (file_exists(__DIR__ . '/queue.pid')) {
@ternavsky
ternavsky / Inflect.php
Last active August 28, 2015 12:53 — forked from tbrianjones/Inflect.php
A PHP Class for converting English words between Singular and Plural.
<?php
// original source: http://kuwamoto.org/2007/12/17/improved-pluralizing-in-php-actionscript-and-ror/
/*
The MIT License (MIT)
Copyright (c) 2015
Permission is hereby granted, free of charge, to any person obtaining a copy
@ternavsky
ternavsky / SerializableModel.php
Last active March 8, 2020 20:12
OctoberCMS Model behavior that allows to store some model's attributes in json format in grouping fields in db.
<?php namespace Path\To\Behaviors;
use System\Classes\ModelBehavior;
/**
* Model behavior that allows to store some model's attributes
* in json format in grouping fields in db.
*
* USAGE: In your model add
*
@ternavsky
ternavsky / str_putcsv.php
Last active August 29, 2015 14:22
Converts array to csv string
public static function str_putcsv($input, $delimiter = ',', $enclosure = '"') {
// Open a memory "file" for read/write...
$fp = fopen('php://temp', 'r+');
// ... write the $input array to the "file" using fputcsv()...
foreach ($input as $fields) {
fputcsv($fp, $fields, $delimiter, $enclosure);
}
// ... rewind the "file" so we can read what we just wrote...
@ternavsky
ternavsky / csv_download.php
Last active August 29, 2015 14:22
Force download CSV file
function forceCSVFileDownload($filename, $csv) {
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Content-Type: csv/plain'); # Don't use application/force-download - it's not a real MIME type, and the Content-Disposition header is sufficient
header('Content-Length: ' . strlen($csv));
header('Connection: close');
print($csv);
}