Skip to content

Instantly share code, notes, and snippets.

View pounard's full-sized avatar
💭
What's happening?

Pierre pounard

💭
What's happening?
View GitHub Profile
@pounard
pounard / drupal-fix-table.php
Created March 15, 2016 09:57
Properly fix table schema adding constraint (MySQL and PostgreSQL working version)
/**
* This function is reentrant.
*/
function mymodule_install_schema_fix() {
$constraints = [
'lo_register_phone' => [
'fk_lo_register_phone_user' => "ALTER TABLE {lo_register_phone} ADD CONSTRAINT {fk_lo_register_phone_user} FOREIGN KEY (uid) REFERENCES {users} (uid) ON DELETE CASCADE",
],
];
@pounard
pounard / ie8placeholders.js
Created October 30, 2015 09:31
Not a polyfill, but does the trick for graceful degradation without complex and buggy JavaScript code.
/*jslint browser: true, plusplus: true, todo: true, white: true */
/*globals Drupal, jQuery */
// Simple placeholder fix for IE8, not a polyfill:
// If a field has no label displayed:
// - If the label is hidden (sr-only or element-invisible) then just show it.
// - If there is no label but a placeholder, build a label using the
// placeholder value.
(function(jQuery) {
"use strict";
@pounard
pounard / install_node.sh
Last active November 30, 2015 11:20
Install node js for your user, isolated, static, and working. This also installs gulp and I'm happy with it.
#!/bin/sh
# Thank you so much, mab!
cd $HOME
wget https://nodejs.org/dist/v4.1.1/node-v4.1.1-linux-x64.tar.gz
tar xzf node-v4.1.1-linux-x64.tar.gz
rm -rf node-v4.1.1-linux-x64.tar.gz
mv node-v4.1.1-linux-x64 node
export PATH="$PATH:$HOME/node/bin"
npm install gulp
export PATH="$PATH:$HOME/node_modules/.bin"
@pounard
pounard / fucking-drupal-version.php
Created May 29, 2015 14:36
Restores all modules version to their latest number (useful if you did a wrong UPDATE in {system} table).
require_once DRUPAL_ROOT . '/includes/update.inc';
$modules = db_query("SELECT name, 1 FROM {system} WHERE type = 'module'")->fetchAllKeyed();
foreach (array_keys($modules) as $key) {
module_load_install($key);
$updates = [];
// From module.inc/update.inc.
$regexp = '/^' . $key . '_update_(?P<version>\d+)$/';
$functions = get_defined_functions();
foreach (preg_grep('/_\d+$/', $functions['user']) as $function) {
$matches = [];
@pounard
pounard / prevent-double-click.js
Created May 7, 2015 09:46
Tiny JS code (jQuery, sorry guys) - that prevents double click on target forms.
// Prevent double click in some forms.
(function(jQuery) {
"use strict";
Drupal.behaviors.fixDoubleClick = {
attach: function (context) {
var k, selectors = [
"#comment-form"
// Add here forms with problems.
];
for (k in selectors) {
$conf['mail_system'] = ['default-system' => 'NetSmtp_MailSystemProxy'];
$conf['netsmtp_proxy'] = ['default' => 'MimeMailSystem'];
$conf['netsmtp_catch'] = [
'[email protected]',
'[email protected]',
// ...
];
$conf['netsmtp_debug_trace'] = true;
$conf['netsmtp_debug_mime'] = true;
$conf['netsmtp'] = [
$mockList = [
[
'name' => "Sa maman",
'firstname' => 'Josianne',
'lastname' => 'Balasko',
],
[
'name' => "Des ours",
'firstname' => 'Jean',
'lastname' => 'Rochefort',
@pounard
pounard / advanced-forum-is-stupid.php
Last active August 29, 2015 14:15
Those lines may save your life whenever you use the advanced_forum module.
/**
* Implements hook_process().
*/
function MYTHEMEORMODULE_process(&$variables, $hook) {
// Seems legit.
// @see laborange2_theme_registry_alter().
if (false === strpos($hook, 'advanced_forum')) {
// This one is a stupid variable mis-use and typo from advanced_forum.
if (!empty($variables['theme_hook_suggestion']) && false !== strpos($variables['theme_hook_suggestion'], 'advanced_forum')) {
// Do not override the 'theme_hook_suggestion' other than advanced
@pounard
pounard / gist:6f620cc38063d1a652d1
Created February 3, 2015 11:12
mimemail-7.x-1.0-beta1 -mailsystem
diff -urN mimemail.orig//mimemail.info mimemail//mimemail.info
--- mimemail.orig//mimemail.info 2015-01-12 12:06:10.000000000 +0100
+++ mimemail//mimemail.info 2015-01-12 12:08:23.000000000 +0100
@@ -1,6 +1,5 @@
name = Mime Mail
description = Send MIME-encoded emails with embedded images and attachments.
-dependencies[] = mailsystem
package = Mail
core = 7.x
@pounard
pounard / gist:7b23c4150704f2657b22
Last active August 29, 2015 14:14
leek-runtime-en.js
/**
* abs(Number number) : Number result
* Returns the absolute value of given number.
* A number.
* Given number's absolute value.
*
* @level 1
* @cores 1
*