Skip to content

Instantly share code, notes, and snippets.

@morad7
morad7 / .env
Last active October 9, 2015 08:14
Laravel 5 fundamental course
APP_ENV=local
APP_DEBUG=true
APP_KEY=PrO1fwe4gFRlOM2jnrXtYQ6oyf6o7ld3
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
CACHE_DRIVER=file
@morad7
morad7 / database.php
Created October 9, 2015 08:10
laravel 5 fundamental course
<?php
return [
/*
|--------------------------------------------------------------------------
| PDO Fetch Style
|--------------------------------------------------------------------------
|
| By default, database results will be returned as instances of the PHP
@morad7
morad7 / auto-titles.php
Last active October 21, 2015 17:11
Auto increment nodes titles
// for auto_nodetitle module
<?php
$count = db_select('node')->fields('node')->condition('type', $node->type)->execute()->rowCount();
$id = $count+1;
$title = 'stg'.$id;
$nodes = db_select('node', 'a')->fields('a', array('title'))->condition('type',$node->type)->execute();
foreach ($nodes as $nod) {
if ($title == $nod->title) {
$id = $id + 1;
$title = 'stg'.$id;
@morad7
morad7 / attestation.php
Created October 21, 2015 08:14
Drupal : Print a view as a document
<?php
global $base_path;
if (isset($data->field_field_civilite[0]['rendered']['#markup'])) {
$civilite = $data->field_field_civilite[0]['rendered']['#markup'];
}
else {
$civilite = 'no civilite';
}
if (isset($data->field_field_prenom[0]['raw']['value'])) {
$prenom = $data->field_field_prenom[0]['raw']['value'];
@morad7
morad7 / date-diff.php
Created October 22, 2015 11:45
Drupal: calculate date differnece using views php
<?php
$date_start = new DateTime($data->field_field_date_conge[0]['raw']['value']);
$date_end = new DateTime($data->field_field_date_conge[0]['raw']['value2']);
$diff=date_diff($date_start,$date_end);
echo $diff->format("%a jours");
?>
@morad7
morad7 / commands.txt
Last active October 24, 2015 10:13
Ubuntu commands
//You can easily memorize it if you consider telling tar to e X tract a F ile
tar xf community_images.tar.gz -C /home/emmys/Pictures/Community/
//You can run the following command to reveal your server’s IP address.
ifconfig eth0 | grep inet | awk '{ print $2 }'
//To copy a file from B to A while logged into B:
scp /path/to/file username@a:/path/to/destination
//To copy a file from B to A while logged into A:
scp username@b:/path/to/file /path/to/destination
//Make sure the directory you are copying to on 192.168.0.4 is owned by the user username
chown username downloads
@morad7
morad7 / README.md
Created November 14, 2015 21:48 — forked from hofmannsven/README.md
My simply MySQL Command Line Cheatsheet
@morad7
morad7 / site-moved-permanently.php
Last active December 3, 2015 09:56
Site moved permanently
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://example.com/newpage.html");
exit();
?>
@morad7
morad7 / custom-view-mode.module
Created December 5, 2015 09:11
Drupal custom view mode
/**
* Implements hook_entity_info_alter().
*/
function MYMODULE_entity_info_alter(&$entity_info) {
$entity_info['node']['view modes']['another_teaser'] = array(
'label' => t('Another teaser'),
'custom settings' => TRUE,
);
}
@morad7
morad7 / drupal-jquery.js
Created December 5, 2015 09:43
Drupal jquery
(function ($) {
Drupal.behaviors.yourBehaviorName = {
attach: function (context, settings) {
//..
}
};
})(jQuery);