Skip to content

Instantly share code, notes, and snippets.

@gsouf
gsouf / createkey.php
Last active July 10, 2017 13:24
phpcache-redis
<?php
include __DIR__ . '/vendor/autoload.php';
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$pool = new \Cache\Adapter\Redis\RedisCachePool($redis);
@gsouf
gsouf / gist:8634874aca7cf3cbd321595dc6408239
Created June 26, 2017 07:44
Aggregate apache logfile by useragent
awk -F\" '{arr[$6]++}END{for(a in arr) print arr[a], a}' access.log | sort -n
@gsouf
gsouf / mailhog.conf
Last active September 4, 2018 19:46
Mailhog upstart script to beplaced in /etc/init/mailhog.conf
description "mailhog"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec start-stop-daemon --start --make-pidfile --pidfile /var/run/mailhog.pid --exec /usr/local/bin/mailhog >> /var/log/mailhog.log 2>&1
@gsouf
gsouf / generate-codes.php
Created June 8, 2015 09:33
generate random alphanum codes
<?php
$codes = array();
function generateCode(){
global $codes;
$chars = "azertyupqsdfghjklmwxcvbn23456789";
$charsCount = strlen($chars) - 1;
<!doctype html>
<title>Site Maintenance</title>
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
a:hover { color: #333; text-decoration: none; }
</style>
@gsouf
gsouf / docker.md
Created July 11, 2014 08:15
Docker reminder

Working with docker containers

  • Daemonizing a container

$ docker run -d

  • Leaving the container

CTRL+P -> q

<?php
class EmailTestCase extends PHPUnit_Framework_TestCase {
/**
* @var \Guzzle\Http\Client
*/
private $mailcatcher;
public function setUp()
{
@gsouf
gsouf / convert-charset.sh
Created February 14, 2014 13:38
Recursively convert encoding of all files in a project
encodeTo="UTF-8"
# CHANGE THE PATTERN IF NEEDED
for filename in ` find . -type f -name "*.php"`
do
echo $filename
enc=`file -bi $filename | awk -F"charset=" '{print $2}'`
iconv -f $enc -t $encodeTo $filename -o $filename
done
@gsouf
gsouf / AuthController.php
Last active April 9, 2021 00:25
oAuth with Phalcon and PHPoAuthLib
<?php
namespace Controllers;
use OAuth\Common\Service\AbstractService;
use OAuth\Common\Storage\Session as OAuthSession;
class AuthController extends ControllerBase {
// everytime we enter the controller, then we check for login, if yes, then we dont have to access here (except logout)
@gsouf
gsouf / .htaccess
Created October 8, 2013 07:57
mod expire configuration sample
### Caching mod_headers + mod_expires
<IfModule mod_expires.c>
# Turn on Expires and set default to now
ExpiresActive On
ExpiresDefault "now"
# Set up caching on media files for 1 month
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|swf)$">