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 / 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 / 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 / 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",
],
];
# mon_module/
# ma_library/src/Toto.php <- namespace de ma library, par exmple Ma\Library\Toto
# mon_module.module
# Dans mon_module.module, genre en haut:
spl_autoload_register(function ($class) {
$parts = explode('\\', $class);
if ('Ma' === $parts[0] && 'Library' === $parts[1]) {
@pounard
pounard / drupal-speed-install.php
Last active July 31, 2018 04:43
Installs a Drupal site really fast (really, really fast) - 3.8 seconds in a standard VM for standard profile
<?php
/**
* @file
* Drupal install speed.
*/
/**
* Yes, this is important.
*/
set_time_limit(0);
@pounard
pounard / drupal-panic.php
Last active April 26, 2016 09:35
This script will save your life
#!/usr/bin/php
<?php
if (!isset($argv[1])) {
$host = '127.0.0.1';
} else {
$host = $argv[1];
}
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['HTTP_HOST'] = $host;
@pounard
pounard / prompt_to_finalize.sh
Last active June 17, 2016 10:33
My PS1 (for bash) needs to be fixed a bit
#!/bin/bash
# Inspired from (very far away)
# http://code-worrier.com/blog/git-branch-in-bash-prompt/
# https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
#
# I needed something simpler, and I work on slow FS so let it be minimal.
__git_br() {
local ingit=""
@pounard
pounard / common.inc
Created July 19, 2016 13:12
drupal_http_request() ignore invalid certificates
case 'https':
// Note: Only works when PHP is compiled with OpenSSL support.
$port = isset($uri['port']) ? $uri['port'] : 443;
$socket = 'ssl://' . $uri['host'] . ':' . $port;
$options['headers']['Host'] = $uri['host'] . ($port != 443 ? ':' . $port : '');
if (empty($options['context'])) {
$options['context'] = stream_context_create();
}
stream_context_set_option($options['context'], 'ssl', 'verify_host', false);
@pounard
pounard / Parse those fucking query strings.js
Created December 29, 2016 14:46
Parse those fucking query strings
function parseLink(uri) {
if (uri === "") {
return {};
}
var pos = uri.indexOf('?');
if (-1 !== pos) {
uri = uri.substr(pos + 1);
}
@pounard
pounard / MonParamConverter.php
Last active April 14, 2017 14:20
Param converter sans annotations
<?php
namespace MonVendor\MonBundle\Controller;
use MonVendor\MonBundle\Gestion\DemandeHelper;
use MonVendor\MonBundle\Gestion\Entity\Aide;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;