Skip to content

Instantly share code, notes, and snippets.

View laurentsab's full-sized avatar

Laurent Sabatier laurentsab

View GitHub Profile
@laurentsab
laurentsab / foreach.php
Last active June 9, 2017 07:41
Manipulate keys values in foreach
<?php
/**
* @param array $array
*
* @return array
*/
protected function translate($array)
{
$filtersChoicesTrans = [];
foreach ($array as $key => $value) {
@laurentsab
laurentsab / ngrok
Created August 18, 2016 14:18
ngrok How to
$ ./ngrok http -region eu -host-header=rewrite {LocalSiteName}.local:80
// On browser or mobile browser, share page like:
http://bae8d36b.eu.ngrok.io
@laurentsab
laurentsab / Docker Tips
Created April 8, 2016 07:30
Docker Tips
// allow history for root user on container
// on /root/.bashrc
// add:
HISTFILE="/root/.bash_history"
@laurentsab
laurentsab / twig_merge_attributes
Created January 20, 2016 09:02
Twig merge attributes
// parent_template.html.twig
{% include "AppBundle:fields:input_text.html.twig" with {
'form_id': form_id,
'field_name': 'Numéro',
'required': true,
'attr': {
'data-minlength': '\\d{7}',
'minlength': '7',
'maxlength': '7',
'data-error': 'e0.message_error'|trans()
@laurentsab
laurentsab / twig_loopModulo.html.twig
Created November 27, 2015 14:27
Twig Loop modulo
<div class="row">
<div class="col-md-9">
<div class="row">
{% if children is defined and children.pager.currentPageResults|length %}
{% for child in children.pager.currentPageResults %}
{% if loop.index0 % 2 == 0 and not loop.first %}
</div>
<div class="row">
{% endif %}
@laurentsab
laurentsab / gist:878005568c4501a90d55
Created October 9, 2015 09:34
update a GitHub forked repository
# http://stackoverflow.com/questions/7244321/how-to-update-a-github-forked-repository
# Add the remote, call it "upstream":
git remote add upstream https://github.com/whoever/whatever.git
# Fetch all the branches of that remote into remote-tracking branches,
# such as upstream/master:
git fetch upstream
# Make sure that you're on your master branch:
@laurentsab
laurentsab / hyperion_raspberry_commands
Created July 29, 2015 16:55
Hyperion Raspberry commands
// config file
# vi /storage/.config/hyperion.config.json
// restart service
# /bin/sh /storage/hyperion/bin/hyperiond.sh /storage/.config/hyperion.config.json
@laurentsab
laurentsab / Shell Tips
Last active February 18, 2017 04:29
Shell Tips
# Show size of each folder
$ du -sch * | sort -h
# Count number of files in a folder
$ find . -name \* | wc -l
# Search a file (or pattern) and execute a command (rm here)
$ find . -name ’*.yml’ -exec rm {} ;
# Add a line at the end of a file
@laurentsab
laurentsab / MongoDB Tips
Last active August 29, 2015 14:19
MongoDB Tips
// Update/Add a new field
Rooms.update({_id: 'XDhybphgkdC7Z4dsn'}, {$set: {user: 'Laurent'}});
// Add array
Rooms.update({_id: 'XDhybphgkdC7Z4dsn'}, {$set: {objects: ['TV', 'Radio', 'Draps'] } } );
// Push a field in an array
Rooms.update({_id: 'XDhybphgkdC7Z4dsn'}, {$push: {objects: ['Lights'] } } );
// Push an array in an array
@laurentsab
laurentsab / ez4_tips
Last active August 29, 2015 14:17
eZ Publish 4 - Tips
/* Afficher une image */
<img src="{$node.object.data_map.my_image.content[image_size].full_path}" ... />
/* Afficher le contenu d'un bloc XML */
{$node.object.data_map.my_xml.content.output.output_text}
/* Afficher un timestamp au format souhaité */
{$node.data_map.date_from.data_int|datetime(custom, '%l %d %F %Y')}
custom, '%d/%m/%y'