Feed aggregator

Mario Lang: C++14 Lambdas

Planet Debian - Tue, 13/05/2014 - 02:59

The aaddition of lambdas in C++11 has greatly improved the flexibility of the language as a whole. C++14 will add a few more abilities.

C++ Truths has a very nice and brief overview of what C++14 will allow. Part 1 goes from the very basics via closures to a small demonstration of partial function application. And Part 2 continues by showing recursive lambdas, overloaded lambdas, pattern matching, in-place parameter pack expansion (neat) and finally even memoisation.

These code examples have been the most inspiring ones I have seen lately. If you have any interest in C++, go read them.

Categories: Elsewhere

2bits: Configuring Apache Solr 4.x for Drupal, with password authentication

Planet Drupal - Mon, 12/05/2014 - 21:34
Most of high traffic or complex Drupal sites use Apache Solr as the search engine. It is much faster and more scaleable than Drupal's search module. In this article, we describe one way of many for having a working Apache Solr installation for use with Drupal 7.x, on Ubunutu Server 12.04 LTS. Objectives For this article, we focus on having an installation of Apache Solr with the following objectives: Use the latest stable version of Apache Solr

read more

Categories: Elsewhere

AGLOBALWAY: Drupal CKEDITOR configuration to work with bootstrap theme

Planet Drupal - Mon, 12/05/2014 - 20:55

Drupal and Bootstrap theme are awesome, but when it comes to use ckeditor you can loose some nice framework styles and it can break your responsive website by adding a simple image or table. One of the ways of fixing it is using a simple configuration to extend and adjust ckeditor.

Adding Boostrap Components to your ckeditor styles and adding extra configuration to ckeditor.config.js

Before we start copy the sites/all/modules/ckeditor/ckeditor.styles.js and sites/all/modules/ckeditor/ckeditor.config.js file into your theme directory (themes/bootstrap/), and enable them in your ckeditor profile (in CSS tab Predefined styles chose “Define path to ckeditor.styles.js” and change Predefined styles path to “%t/ckeditor.styles.js” and in ADVANCED OPTIONS tab check Load ckeditor.config.js from the theme path to yes). You will need to also enable “styles” menu in your ckeditor toolbar and you may want to use your theme styles to preview ckeditor styles before saving your content.

  1. Open your ckeditor.styles.js, and comment or remove all useless styles. if(typeof(CKEDITOR) !== 'undefined') { CKEDITOR.addStylesSet( 'drupal', [ ]); }

    You should have something like this

  2. 2. Copy new bootstrap styles in your ckeditor.styles.js. And save the file /* Bootstrap Styles */ /* Typography */ { name : 'span.H1' , element : 'span', attributes: { 'class': 'h1' } }, { name : 'span.H2' , element : 'span', attributes: { 'class': 'h2' } }, { name : 'span.H3' , element : 'span', attributes: { 'class': 'h3' } }, { name : 'span.H4' , element : 'span', attributes: { 'class': 'h4' } }, { name : 'span.H5' , element : 'span', attributes: { 'class': 'h5' } }, { name : 'span.H6' , element : 'span', attributes: { 'class': 'h6' } }, { name : 'Paragraph Lead' , element : 'p', attributes: { 'class': 'lead' } }, { name : 'Unstyled List', element : 'ul', attributes : { 'class' : 'list-unstyled' } }, { name : 'List inline', element : 'ul', attributes : { 'class' : 'list-inline' } }, { name : 'Table', element : 'table', attributes : { 'class' : 'table' } }, { name : 'Table Striped rows', element : 'table', attributes : { 'class' : 'table table-striped' } }, { name : 'Table Bordered', element : 'table', attributes : { 'class' : 'table table-bordered' } }, { name : 'Table Hover rows', element : 'table', attributes : { 'class' : 'table table-hover' } }, { name : 'Table Condensed', element : 'table', attributes : { 'class' : 'table table-condensed' } }, { name : 'Image shap rounded', element : 'table', attributes : { 'class' : 'img-rounded' } }, { name : 'Image shap circle', element : 'table', attributes : { 'class' : 'img-circle' } }, { name : 'Image shap thumbnail', element : 'table', attributes : { 'class' : 'img-thumbnail' } }, { name : 'Image float left', element : 'table', attributes : { 'class' : 'pull-left' } }, { name : 'Image float right', element : 'table', attributes : { 'class' : 'pull-right' } },
  3. Open your ckeditor.config.js, search for “config.justifyClasses” and replace it with this line: config.justifyClasses = [ 'text-left', 'text-center', 'text-right', 'text-justify' ];

    This will change default text alignment classes to new bootstrap classes

  4. At very bottom of ckeditor.config.js, copy and paste this lines. CKEDITOR.on('dialogDefinition', function( ev ) { var dialogName = ev.data.name; var dialogDefinition = ev.data.definition; if(dialogName === 'table' || dialogName == 'tableProperties' ) { var infoTab = dialogDefinition.getContents('info'); //remove fields var cellSpacing = infoTab.remove('txtCellSpace'); var cellPadding = infoTab.remove('txtCellPad'); var border = infoTab.remove('txtBorder'); var width = infoTab.remove('txtWidth'); var height = infoTab.remove('txtHeight'); var align = infoTab.remove('cmbAlign'); } if(dialogName === 'image') { var infoTab = dialogDefinition.getContents('info'); dialogDefinition.removeContents( 'Link' ); dialogDefinition.removeContents( 'advanced' ); infoTab.remove('txtWidth'); infoTab.remove('txtHeight'); infoTab.remove('txtBorder'); infoTab.remove('txtHSpace'); infoTab.remove('txtVSpace'); infoTab.remove('ratioLock'); infoTab.remove('cmbAlign'); } });

    This will remove default inline styles like a width and height from image/table configuration popup.


Tags: drupaldrupal planet
Categories: Elsewhere

Get Pantheon Blog: Moving MySQL tables from MyISAM to InnoDB

Planet Drupal - Mon, 12/05/2014 - 19:00

One of the greatest things ever to happen to MySQL was the InnoDB engine. Before InnoDB, indexes would get corrupted, updates meant table locks, not just row locks, and we had no support for transactions. Since the advent of InnoDB however, we've come a long way. These days, most serious DBAs using MySQL build exclusively on the InnoDB engine.

Sadly though, many sites are still using the MyISAM engine. Some are hosted on shared hosting servers and some just don't have a proper DBA to look after their databases. For whatever the reason, these sites are missing out on the performance and stability gains that the rest of us take for granted. At Pantheon, we know there are a lot of these sites out there because we see them when they migrate their sites onto our platform. As part of our Launch Check, we check the engine type on every table. If we find a table using the MyISAM engine, we notify the user so they can fix it.

Fixing this problem is simple to any developer who understands a little SQL. However, for non-developers, this can be a daunting task. So I have put together a little PHP script to help you convert your MyISAM tables to InnoDB.

NOTE: This is an unofficial script. It is not supported by Pantheon. Customer Support will not help you run it, nor will they hold your hand while fixing things if this script screws up your database. Use THIS SCRIPT AT YOUR OWN RISK. I strongly suggest you make a backup of your database before running this script. 

The Easy Way

Still with me? Cool! Let's dive right in. 

There are 2 versions of this script. One is meant to be called from a web browser. It is meant for Pantheon customers. If you are a Pantheon customer, save the code in a file with the extension .php and sftp it up to your site. Place it in the code directory of your website.

Now, point a browser to your newly created script that should be in the root directory of your Dev environment.


That is all there is to it. The script will do all the work. You don't need to change anything.

Here is the browser version of the script:

The Developer Way

If you are not a Pantheon customer, or you want to run the script from the command line, use the one below. To use this one however, you need to know two things before you begin.

  1. You have to have PHP installed on the computer you want to run this on. I run this on my laptop. I have PHP installed on my laptop. I know that because I can type php -v at the command line and I get a proper response. If you do not understand any of that, this script is not for you, use the one above.
  2. If you are a Pantheon customer, you can get your database connection info from your site's dashboard. Make sure you get the information for your Dev environment. After you've run the script, and everything looks good, you can easily migrate it up the line to Test and then Live. If you are running this on your site and your site is not on Pantheon, you will have to find another way to get your MySQL connection info.

Here is the command line script:

See the line that says "* DO NOT CHANGE ANYTHING BELOW THIS LINE"? I'm serious about that. If it doesn't' work and you are not a programmer, don't mess with it. If you are a programmer, you realize exactly how dead-simple the script is.

Here are the parameters you will need to configure before running the script.

  • host = This is the name of the machine your db is running on. If you are a Pantheon customer localhost is WRONG. Get the correct host and paste it in there replacing localhost. 
  • port = This is the port that is running MySQL on your computer. Again, if you are a Pantheon customer, we give you this information. If you are not, 3306 is the standard port for MySQL. 
  • user = This is the user name you use to connect to MySQL with. 
  • password = This is your MySQL password for the user you specified in the line above.
  • database = This is the name of the database that contains the tables. If you are a pantheon customer, this is "pantheon". If you are not a Pantheon customer, you will need to get this from your host.

Now, save the file.

Then from a command window execute the program. (How you get a command window varies by OS. If you don't know, ask your computer friend, younger sibling, or niece.)

The script will tell you everything it is doing. It has safeties built in to keep it from changing anything by MyISAM tables. It will look at every table in your database and if the engine is MyISAM, it will change it to an InnoDB.

Once you have run it successfully, check everything! 

This is not a particularly dangerous script. The change is pretty simple. However, it's your data. So be careful. 

Blog Categories: Engineering
Categories: Elsewhere

drunomics: #d8rules - Supporting the Rules modules for Drupal 8

Planet Drupal - Mon, 12/05/2014 - 18:12

Today, I've the pleasure to introduce the #d8rules initative, our combined effort to get the Rules module ported to Drupal 8 in time!

Drupal 8 is coming...

Fortunately, the first beta of Drupal 8 is coming closer so it's time to make sure all the modules are ported and ready for Drupal 8. Unfortunately, the Rules module - my long term number one contributed module - is about to be left behind. I've worked a lot on Drupal 8 to get critical Entity API improvements like the new Entity Field API (called Entity Property API at the time of the introduction) as well as the new Typed data API done. Of course, the work on core is time intensive, not "done" yet and won't stop - so there is not a lot contribution time left for my contributed modules. :/

So where is Rules for Drupal 8 now?

In short, it's not there yet. While quite a bit of work under the hood and planning has been done already, the main work - porting of the module itself - is still to be done. As Drupal 8 ships with quite a bunch of important improvements, this requires the rewrite of significant parts of the module. In Drupal 7, the Rules module had to solve a lot of hard problems like handling its configuration, configuration translation, dependency tracking, integrity checks and plugins, which all have solutions in Drupal 8 core now. That's awesome, but it requires us to adapt the previous Drupal 7 solutions to work inline with Drupal 8 best practices. However, more than that - the foundational metadata Rules needs is already there as well!

The foundation is (mostly) there

In Drupal 7 the creation of the Entity API module, in particular its Entity Metadata wrappers and the backing Entity Property Information, was driven by the needs of the Rules module. While the Rules module makes it simple to work with data for site builders, the Entity module makes it simple for developers first. Subsequently, the Rules module can build upon the easy API and make it accessible via the rule model and its UI. For Drupal 8, the Entity Field API and its underlying Typed Data API are that easy API upon which the Rules module can build upon. That's great, as it means we have the foundation we can build upon in place - but again, it changed (improved) substantially and will require us to adapt a lot of what's there. However, having the Typed Data API and all the necessary metadata built-in means that the out of the box module and entity type support of Rules for Drupal 8 will be substantially better as well.

Actions and conditions in core

We've got an Actions and Conditions API in core already, so one might think another huge part has been taken care off. Unfortunately, no - those APIs have been created/ported with other use cases in mind, so they do not cater for all the more advanced features Rules users are used to. While I tried to make sure they fit Rules needs as far as possible when they were introduced/updated, they do not fit our needs yet and it might be impossible to make them fit without breaking those APIs. For Rules 8.x we plan to work on improving those APIs (from contrib) as needed first, so we can ensure they fit Rules' requirements. Once we are sure everything works out we'll know what we have to adapt and whether improvements can be contributed to core. Depending on how that works out, we'll see whether we can build up on the core Action and Conditions API or there will be Rules' variants of those APIs (again :(). For more details please see the related issues:

We have a plan

We've quite some work to do to get Rules ported to Drupal 8. klausi and me estimated the task to be additional 1050 hours work (from here). With us, working on it in our spare time besides our other contributions (Entity Field API, Rest module in core, ..) we figured the module won't be ready before sometime in 2015, not unlikely even 2016. That's obviously too late, so we'd love to invest more of our time and work on it during work hours as well, such that we can deliver a ported version in 2014. Our companys cannot afford taking that investment alone, but are up for supporting us and enable us to work on a community rate of € 45/h net cost for the project. You can find more details on the project plan and estimations on our initative site.

Rules needs your help!

If you think the Rules module is a valuable tool and helps you building sites faster, please consider supporting our iniatitive! There is a limited goodie for the 50 first supporters pledging >65$ - check it out. If you are going to Drupalcon Austin and you'd love to help, consider signing up for the #d8rules sprint! We'll get started porting either events, conditions or actions to the new API. Lastly, please help to spread the word! We've got supporter badges that you can embed on your site, and obviously our hash tag is #d8rules!

Video of #d8rules



Iniative website: http://d8rules.org
drupalfund.us campaign: https://www.drupalfund.us/project/d8rules-support-rules-module-drupal-8
Project page: http://drupal.org/project/rules

Categories: Elsewhere

Stanford Web Services Blog: Module of the Day: JS Injector

Planet Drupal - Mon, 12/05/2014 - 18:09

Today's "Module of the Day" is a handy little module called JS Injector that allows you to insert snippets of Javascript into your site.

In this post, I'll walk through how to enable and configure the module, use it to shout, "Hello, World!", and then go into some more advanced configuration.

Categories: Elsewhere

Russell Coker: BTRFS vs LVM

Planet Debian - Mon, 12/05/2014 - 09:37

For some years LVM (the Linux Logical Volume Manager) has been used in most Linux systems. LVM allows one or more storage devices (either disks, partitions, or RAID sets) to be assigned to a Volume Group (VG) some of which can then allocated to a Logical Volume (LVs) which are equivalent to any other block device, a VG can have many LVs.

One of the significant features of LVM is that you can create snapshots of a LV. One common use is to have multiple snapshots of a LV for online backups and another is to make a snapshot of a filesystem before making a backup to external storage, the snapshot is unchanging so there’s no problem of inconsistencies due to backing up a changing data set. When you create a snapshot it will have the same filesystem label and UUID so you should always mount a LVM device by it’s name (which will be /dev/$VGNAME/$LVNAME).

One of the problems with the ReiserFS filesystem was that there was no way to know whether a block of storage was a data block, a metadata block, or unused. A reiserfsck --rebuild-tree would find any blocks that appeared to be metadata and treat them as such, deleted files would reappear and file contents which matched metadata (such as a file containing an image of a ReiserFS filesystem) would be treated as metadata. One of the impacts of this was that a hostile user could create a file which would create a SUID root program if the sysadmin ran a --rebuild-tree operation.

BTRFS solves the problem of filesystem images by using a filesystem specific UUID in every metadata block. One impact of this is that if you want to duplicate a BTRFS filesystem image and use both copies on the same system you need to regenerate all the checksums of metadata blocks with the new UUID. The way BTRFS works is that filesystems are identified by UUID so having multiple block devices with the same UUID causes the kernel to get confused. Making an LVM snapshot really isn’t a good idea in this situation. It’s possible to change BTRFS kernel code to avoid some of the problems of duplicate block devices and it’s most likely that something will be done about it in future. But it still seems like a bad idea to use LVM with BTRFS.

The most common use of LVM is to divide the storage of a single disk or RAID array for the use of multiple filesystems. Each filesystem can be enlarged (through extending the LV and making the filesystem use the space) and snapshots can be taken. With BTRFS you can use subvolumes for the snapshots and the best use of BTRFS (IMHO) is to give it all the storage that’s available so there is no need to enlarge a filesystem in typical use. BTRFS supports quotas on subvolumes which aren’t really usable yet but in the future will remove the need to create multiple filesystems to control disk space use. An important but less common use of LVM is to migrate a live filesystem to a new disk or RAID array, but this can be done by BTRFS too by adding a new partition or disk to a filesystem and then removing the old one.

It doesn’t seem that LVM offers any benefits when you use BTRFS. When I first experimented with BTRFS I used LVM but I didn’t find any benefit in using LVM and it was only a matter of luck that I didn’t use a snapshot and break things.

Snapshots of BTRFS Filesystems

One reason for creating a snapshot of a filesystem (as opposed to a snapshot of a subvolume) is for making backups of virtual machines without support from inside the virtual machine (EG running an old RHEL5 virtual machine that doesn’t have the BTRFS utilities). Another is for running training on virtual servers where you want to create one copy of the filesystem for each student. To solve both these problems I am currently using files in a BTRFS subvolume. The BTRFS kernel code won’t touch those files unless I create a loop device so I can only create a loop device for one file at a time.

One tip for doing this, don’t use names such as /xenstore/vm1 for the files containing filesystem images, use names such as /xenstore/vm1-root. If you try to create a virtual machine named “vm1″ then Xen will look for a file named “vm1″ in the current directory before looking in /etc/xen and tries to use a filesystem image as a Xen configuration file. It would be nice if there was a path for Xen configuration files that either didn’t include the current directory or included it at the end of the list. Including the current directory in the path is a DOS mistake that should have gone away a long time ago.

Psychology and Block Devices

ZFS has a similar design to BTRFS in many ways and has some similar issues. But one benefit for ZFS is that it manages block devices in a “zpool”, first you create a zpool with the block devices and after that you can create ZFS filesystems or “ZVOL” block devices. I think that most sysadmins would regard a zpool as something similar to LVM (which may or may not be correct depending on how you look at it) and immediately rule out the possibility of running a zpool on LVM.

BTRFS looks like a regular Unix filesystem in many ways, you can have a single block device that you mount with the usual mount command. The fact that BTRFS can support multiple block devices in a RAID configuration isn’t so obvious and the fact that it implements equivalents to most LVM functionality probably isn’t known to most people when they start using it. The most obvious way to start using BTRFS is to use it just like an Ext3/4 filesystem on an LV, and to use LVM snapshots to backup data, this is made even more likely by the fact that there is a program to convert a ext2/3/4 filesystem to BTRFS. This seems likely to cause data loss.

Related posts:

  1. Starting with BTRFS Based on my investigation of RAID reliability [1] I have...
  2. BTRFS Status March 2014 I’m currently using BTRFS on most systems that I can...
  3. BTRFS and ZFS as Layering Violations LWN has an interesting article comparing recent developments in the...
Categories: Elsewhere

Web Omelette: Sending HTML Emails with Webform in Drupal 7

Planet Drupal - Mon, 12/05/2014 - 09:12

Have you ever wondered how you can include HTML markup in the emails you send with Webform? Out of the box, you cannot. But I am going to show you a simple way to achieve this using the Mime Mail module and some simple theming. Additionally, I will show you how to control which webforms should send HTML emails and which should not.

First though, make sure you install and enable the Mime Mail and Mail System modules (the latter is a dependency of the former). With Drush, all you have to do is use this command:

drush en mimemail -y

It will take care of all you need to do. If you commit the module to your repo, don't forget that the Mail System module also gets downloaded, so make sure you include it as well.

Next, edit your theme's template.php file and paste this block of code (explained after):

function your_theme_webform_mail_headers($variables) { $headers = array(); $headers = array( 'Content-Type' => 'text/html; charset=UTF-8; format=flowed; delsp=yes', 'X-Mailer' => 'Drupal Webform (PHP/'. phpversion() .')', ); return $headers; }

Make sure you change your_theme with the name of your theme. So what happens here? We override the theme_webform_mail_headers() declared by the Webform module. We do this in order to add a content type to the mail headers, and set it to HTML. And that's pretty much it.

If you now clear your caches and test a webform, you'll see that you can add anchor tags and other basic HTML tags.

One problem you might run into though is that all your webforms are now sending emails in HTML format - a result only partially desired. You'll notice that the default email that you send no longer provides any spacing and all the text gets put on one line - as HTML in fact.

So what you can do is make a selection of webforms for which you'll want HTML emails. A handy way of doing this is by adding a field to your webform content type that will be used to swith HTML emails on/off for a given node. So to illustrate this, let's say we added a new field to the relevant content type called HTML Emails (with the machine name: field_html_email). This field is a boolean type (a single checkbox basically) with the values of 1 for on and 0 for off.

It follows to adapt the theme override above and replace it with something like this:

function your_theme_webform_mail_headers($variables) { $headers = array( 'X-Mailer' => 'Drupal Webform (PHP/' . phpversion() . ')', ); // Get the HTML Email field $html_email_field = field_get_items('node', $variables['node'], 'field_html_email'); // Check if this webform node needs to send HTML emails if (!empty($html_email_field)) { $html = $html_email_field[0]['value'] == 1 ? TRUE : FALSE; } if ($html === TRUE) { $headers['Content-Type'] = 'text/html; charset=UTF-8; format=flowed; delsp=yes'; } return $headers; }

If you consult the documentation for this theme function, you'll know that the $variables parameter contains also the node object which uses Webform to send the email. So we basically check for the value of our field and if it is 1, we add the HTML information to the mail headers. Otherwise, we return the $headers array containing the value it does by default (essentially making no changes).

You can now clear the caches and test it out. Edit a node of the respective content type and check the box. You'll see that it now sends HTML emails. However, if you uncheck the box, it will fallback to the default format that comes with the Webform module.

Hope this helps.

In Theming | Drupal var switchTo5x = true;stLight.options({"publisher":"dr-8de6c3c4-3462-9715-caaf-ce2c161a50c"});
Categories: Elsewhere


Subscribe to jfhovinne aggregator