Skip to content

Instantly share code, notes, and snippets.

@manumilou
manumilou / array-is-not-thread-safe.rb
Created March 19, 2019 22:29
Appending to arrays is not thread-safe in Ruby.
array = []
5.times.map do
Thread.new do
1000.times do
array << nil
end
end
end.each(&:join)
@manumilou
manumilou / inheritance.py
Created October 4, 2018 18:53
Example on how to merge class attribute through class hierarchy
class DefaultsMetaBase(type):
"""Automatically merges headers from all parent classes."""
def __call__(self, *args, **kwargs):
obj = type.__call__(self)
print("Metaclass %s called" % obj.__class__)
for klass in obj.__class__.__mro__:
if klass == obj.__class__ or klass == Base or not issubclass(klass, Base):
print("discarding %s" % klass)
continue
print("keeping %s" % klass)
@manumilou
manumilou / gist:ac5d71a1688d5f3ed5b1
Created June 5, 2015 19:20
Add an option to a menu item
/**
* Implements hook_form_FORM_ID_alter().
*
* @ingroup forms
* @see pp_menu_customization_form_menu_edit_item_submit()
*/
function pp_menu_customization_form_menu_edit_item_alter(&$form, $form_state, $form_id) {
// Add an option to open the link in a new window/tab
$form['target'] = array(
'#type' => 'select',
@manumilou
manumilou / develMailLog
Created February 4, 2015 16:51
Setting up Devel to log outgoing emails
# Add this code into settings.php
$conf['mail_system'] = array(
'default-system' => 'DevelMailLog',
);
- See more at: http://www.webomelette.com/drupal-modules-debug-emails#sthash.ENtXCxb8.dpuf

Keybase proof

I hereby claim:

  • I am manumilou on github.
  • I am manumilou (https://keybase.io/manumilou) on keybase.
  • I have a public key whose fingerprint is 930B B6CB 1C08 59D0 57DD F8AA C7B9 2667 DAA5 58D0

To claim this, I am signing this object:

@manumilou
manumilou / drush-sql-dump-fast
Created October 28, 2014 15:24
Fast database dump and restore
# One liner dump and compress
drush sql-dump | gzip > db_dump.XXXX.sql.gz
# One liner decompress and restore
zcat db_dump.XXXX.sql.gz | mysql -u user -p dbname
@manumilou
manumilou / profile.install
Last active August 29, 2015 14:08
Set a default theme and an admin theme during profile installation
<?php
/**
* Implements hook_install().
*/
function my_custom_profile_install() {
// Here, the admin theme is adminimal, and the default theme is called bueno
// It seems like if the themes are not enabled in the database directly, just setting the default theme does not work.
@manumilou
manumilou / main_menu.module
Created October 8, 2014 15:25
drupal\features : Delete all menu links before reverting a feature
/**
* Implements hook_pre_features_revert().
*
* If a menu link is added in a menu handled by this feature, it won't be deleted when the menu feature is reverted.
* Only the menu links exported in the feature will be reverted.
* Implementing this hook allows us to make sure that the menu is fully resetted after the revert
* by first deleting all menu links before reverting.
*/
function main_menu_pre_features_revert($component) {
if($component == 'menu_links') {
@manumilou
manumilou / \drupal\feeds: custom target in mapping for node processor
Last active August 29, 2015 14:05
Creating a custom target for mapping
Creating a new custom target allows to alter the data source before the mapping. For that, the hook hook_feeds_node_processor_targets_alter() needs to be implemented. There, you can specify a target name and description, a function callback that will process the data source, and a real target, corresponding to an actuel field of the content type.
After flushing the cache, a new option should be available in the target dropdown.
Example:
/**
* Implementation of hook_feeds_node_processor_targets_alter().
*/
function feeds_library_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name){
$targets['field_category_custom'] = array(