-
Applescript to Interact with iTerm2
iTerm2 has decent support for Applescript. You can work with sessions, profiles, tabs, and more through Applescript. I only have one example, but it’s something I use in the real-world, so maybe it’ll help someone else.
The following script will open a new tab for every server in the list, and execute a command on that server. Let’s say a new version of Drush is available. I’d use this script to log into every server (we have no less than 15 servers) and check which version of Drush the server is running. I could then quickly update if needed, and I’m already logged in to do so.
-
Sorting by Specific Fields with Apache Solr
Recently I had to configure an Apache Solr search page to have the results sorted by a date field. We’re using the apachesolr module, which has a number of useful hooks, two of which we’ll use to accomplish this custom sort.
If you browse to Administration » Reports » Apache Solr search index you will see a list of the indexed fields (example shown below). Most of the documentation I’ve seen out there regarding apachesolr sorting says you can use $query->setAvailableSort() and $query->setSolrSort() within an implementation of hook_apachesolr_query_prepare() , but there is at least one caveat: the field you want to sort on must be a single-value field! Here’s a look at the field list on the site I’m working on:
-
Userscript: Hulu Right-Click for Pop Out Video
Hulu’s default rather large video player is usually too big for my needs. I prefer the “Pop Out” player. So, I often load the large video, click the cog wheel, move my mouse to the “popout” link, click it, then close the main window. It’s been a pain in the butt. So, I took some time to write a simple userscript that lets you right-click on any video thumbnail to open its video in the popout immediately. It’s working great for me but I have not tested it elsewhere, so I won’t be surprised if it doesn’t work for you… just let me know in the comments below…
http://userscripts.org/scripts/show/311800UPDATE: I rewrote this as a Chrome Extension and published it. View the blog post.
-
Copying Values Between Fields on Thousands of Entities
In a nutshell, I had a List (text) field that I needed to convert to a Text field (so that I wasn’t locked in to specific values anymore). Instead of trying to modify the field to convert it from one type to another, I decided to create a new Text field and populate it with the data from the List field (modifying it a bit first). Here’s the script I used to do this. Admittedly it could be cleaner, more efficient, etc. but it’ll show you a few things, and it got the job done for me.
If you choose to run with
drush scr update_nodes.php
you can leave out the top 3 bootstrap lines. -
Creating Field Groups in a Custom Module
If you need your module to add a fieldgroup to your Drupal 7 site, follow this quick and easy process: Also, if you’re looking to create fields, see this related post.
- Build the fieldgroup through the “manage fields” UI.
- Modify the code below to include a proper $fieldgroup_name, $entity_type and $bundle_name. I needed to add a field to the user profile, so I set the $entity_type to “user” and the $bundle_name to “user”.
1234567891011$fieldgroup_name = ''; // e.g., group_author_info$entity_type = ''; // e.g., node$bundle_name = ''; // e.g., storyinclude_once DRUPAL_ROOT . '/includes/utility.inc';$group = field_group_load_field_group($fieldgroup_name, $entity_type, $bundle_name, 'form');$group_var = '$' . $fieldgroup_name . ' = ' . substr(drupal_var_export($group), 9) . ";\r";$group_var = preg_replace("/ 'id'.*,\n/", '', $group_var); // remove the ID property$group_var = preg_replace("/ 'export_type'.*,\n/", '', $group_var); // remove the export_type property$output = $group_var . 'field_group_group_save($' . $fieldgroup_name . ');';drupal_set_message("<textarea rows=30 style=\"width: 100%;\">" . $output . '</textarea>');
-
Creating Fields in a Custom Module
I’m going to be very brief here, because Joel Stein covers this beautifully. Also, if you’re looking to create fieldgroups, see this related post.
If you need your module to add a field to your Drupal 7 site, follow this quick and easy process:- Build the field through the “manage fields” UI.
- Modify the code below to include a proper $field_name, $entity_type and $bundle_name. I needed to add a field to the user profile, so I set the $entity_type to “user” and the $bundle_name to “user”.
123456789101112$field_name = ''; // e.g., field_story_pagecount$entity_type = ''; // e.g., node$bundle_name = ''; // e.g., story$info_config = field_info_field($field_name);$info_instance = field_info_instance($entity_type, $field_name, $bundle_name);unset($info_config['id']);unset($info_instance['id'], $info_instance['field_id']);include_once DRUPAL_ROOT . '/includes/utility.inc';$output = "field_create_field(" . drupal_var_export($info_config) . ");\n";$output .= "field_create_instance(" . drupal_var_export($info_instance) . ");";drupal_set_message("<textarea rows=30 style=\"width: 100%;\">" . $output . '</textarea>');
-
WordPress Plugin: Search Regex
I wanted to quickly mention this plugin as it saved me a bit of time just now. While I worked on this new blog I set the development site up at wordpress.agileadam.com. When I switched the agileadam.com domain over to point to this new WordPress site all of my images stopped working (because the img tags pointed to wordpress.agileadam.com urls; shouldn’t they be relative anyway!? I’ll look into that later).
-
QuickLook Slow in Mavericks?
Is your QuickLook painfully slow after upgrading to Mavericks? Until there’s a solution from Apple, if you’re on a mac with a Retina display try this:
- Open the Applications directory in Finder
- Right-click the application Preview
- Select Get Info.
- Enable/check the Open in Low Resolution.
Source: http://wccftech.com/how-to-fix-quick-look-in-os-x-mavericks/
-
Add Links to Anchors Automatically
The following snippet is something I used recently to add (below the current item in a menu) links to any anchors found in the content.
1234567$("#content a[name]").each(function() {if ($("#page-anchors").length === 0) {$(".menu-block-1 li.active:last").append("<ul id='page-anchors'>");}var aname = $(this).attr("name");$("#page-anchors").append($("<li><a href='#" + aname + "'>" + aname + "</a></li>"));});Honestly I could probably create the <ul> outside of the each() loop and save having to check whether it exists with each iteration. Also, it’s probably not necessary to create the aname variable, but the overhead here is minimal.