Skip to content

Instantly share code, notes, and snippets.

View alexsegura's full-sized avatar
🔥
On fire

Alexandre Segura alexsegura

🔥
On fire
View GitHub Profile
@alexsegura
alexsegura / csv.php
Created June 26, 2012 13:06
Simple HTML form to create CSV files with PHP
<?php
if (isset($_POST['rows'])) {
$h = tmpfile();
foreach ($_POST['rows'] as $row) {
fputcsv($h, array_values($row));
}
rewind($h);
$csv = '';
@alexsegura
alexsegura / gist:7357978
Last active December 27, 2015 16:49
Simple function to add an entire folder to a ZipArchive. Uses getSubPathName to avoid recreating whole disk structure. Uses iterators, no recursion.
<?php
function addFolderToZip(\ZipArchive $zip, $dir) {
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::SELF_FIRST);
$zip->addEmptyDir(basename($dir));
@alexsegura
alexsegura / symfony_forms.php
Last active August 29, 2015 13:56
Creating Symfony Forms with Validation programmatically
<?php
$builder = Validation::createValidatorBuilder();
$builder->addYamlMapping('/path/to/validation.yml');
$validator = $builder->getValidator();
$extensions = array(
new ValidatorExtension($validator)
);
@alexsegura
alexsegura / gist:9650651
Last active July 9, 2022 10:41
Prestashop 1.6 folder permissions
chmod a+w -R config/
chmod a+w -R cache/
chmod a+w -R log/
chmod a+w -R img/
chmod a+w -R mails/
chmod a+w -R modules/
chmod a+w -R themes/default-bootstrap/lang/
chmod a+w -R themes/default-bootstrap/pdf/lang/
chmod a+w -R themes/default-bootstrap/cache/
chmod a+w -R translations/
@alexsegura
alexsegura / gist:9895452
Created March 31, 2014 15:52
Get MySQL error code with Doctrine DBAL
<?php
$sql = '...';
$stmt = $conn->prepare($sql);
try {
$stmt->execute();
} catch (\Doctrine\DBAL\DBALException $e) {
$previous = $e->getPrevious();
@alexsegura
alexsegura / Gruntfile.js
Last active August 29, 2015 14:05
Reloading a Cordova project with Grunt
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
src: {
files: ['www/**/*.html', 'www/**/*.js', 'www/**/*.css'],
tasks: ['shell']
}
},
@alexsegura
alexsegura / xdebug.ini
Created September 10, 2014 08:51
XDebug configuration
[xdebug]
zend_extension=xdebug.so
xdebug.overload_var_dump = 0
xdebug.default_enable = 1
xdebug.idekey = "sublime.xdebug"
xdebug.remote_autostart = 0
xdebug.remote_enable = 1
xdebug.remote_log="/var/log/xdebug/xdebug.log"
xdebug.remote_host=192.168.0.1
@alexsegura
alexsegura / Item.php
Last active January 27, 2019 14:24
Archivable pattern in Doctrine
<?php
use Doctrine\ORM\Mapping as ORM,
Doctrine\ORM\Event\LifecycleEventArgs;
/**
* @ORM\Table(name="item")
* @ORM\HasLifecycleCallbacks
*/
class Item
@alexsegura
alexsegura / paymill.php
Created March 31, 2015 14:19
Paymill API pagination
<?php
$api = new Paymill\Request('private_key');
function get_transactions($api, $count, $offset) {
$request = new Paymill\Models\Request\Transaction();
// Other options here
$request->setFilter([
'offset' => $offset,
'count' => $count
@alexsegura
alexsegura / install_certbot.sh
Created December 1, 2016 22:58
Install CertBot on Debian Jessie
echo 'deb http://ftp.debian.org/debian jessie-backports main' >> /etc/apt/sources.list
apt-get update
apt-get install certbot -t jessie-backports