All Posts in The Programming Mechanism

June 26, 2012 - Comments Off on Drush de Jour: Painless database backups for your Drupal site

Drush de Jour: Painless database backups for your Drupal site

Proceed directly to drush.
Do not pass Go.
Do not enter your site name.

When you first set up your Drupal site- install drush, the command line shell for Drupal. With drush, you can backup your db, create users, reset passwords, re-index search, start/stop migration, check logs, etc. etc. etc.

From the root of your Drupal install: (e.g., /var/www/<sitename>).

% drush archive-backup --destination=sitebackup.sql

That's it. Your entire drupal database is written to a file.

% drush sql-dump > sitebackup.sql

This method uses drush's Mysql command line interface to do a mysqldump of the site database

And if you want to be stubborn and not install drush:

mysqldump -u -p <sitedatabase> > sitebackup.sql

Links

The Drush de Jour brings you the latest and possibly greatest bits of drush wisdom we use for developing and maintaining our Drupal sites.

Published by: chazcheadle in The Programming Mechanism
Tags: , ,

June 21, 2012 - Comments Off on Drupal Rule(s)!

Drupal Rule(s)!

 Fitness Tips To Help You See Impressive Results

MARCH 23, 2020

Being fit has many physical and mental benefits for your health. However, many people may not understand what it fully requires to fully reach their goals. Follow these 5 fitness tips to help you see impressive results. Check these profit singularity reviews.

1. Stay Consistent

Consistency will lead you on the road to success the quickest. It doesn’t matter what your goals are. If you have consistency and develop a routine that you know that you can rely on, it will lead to you reaching your goals quicker.

For example, if you want to lose weight, you should be consistent in your cardio exercise regimen. This consistency cannot just stop at your physical exercise, though. This consistency has to extend into another important part of your routine, which is your diet.

2. Watch Your Diet

Maintain a good diet to reach your fitness goals.

Many people only focus on the gym and exercise component of attaining fitness goals. As mentioned before, your diet is one of the most important parts of your fitness regimen, but having a great diet, regardless of your fitness goals, will impact whether or not you are successful in your goals as much or more than actual exercise. This is because your body will reflect what you eat and your diet can either progress your goals further or set you back.

It may be helpful for you to keep a log of what you eat and determine which foods you need to eliminate and which foods you need to add. In addition, you also want to be mindful of when you are eating, because it can also affect your performance in the gym.

For those who are bodybuilding or looking to build muscle, it’s recommended to incorporate some kind of carbohydrates before a workout session, and then have a protein-heavy meal once you are finished to speed up the recovery process. Protein shakes are a popular commodity in this regard. However, different protein powders can have different vitamins, minerals, and ingredients that can be more effective for men or women.

Ladies can check out a variety of protein powders to see what’s available for their needs. There tend to be more protein powders available for men that already have the extra minerals and vitamins included to help them get gains. So when guys are searching for the best protein powder, it’s better to decide if they’re trying to get lean or gain weight.

3. Have Realistic Expectations

Having the right mindset is imperative to achieve the fitness goals of any kind, and it starts by having realistic expectations. If you don’t like what you see in the mirror, then you have to work hard to see a change. However, if you are looking to shed some pounds and reduce your waistline, you can’t expect it to be done within a week.

Realistic expectations directly correlate with being consistent. Gaining weight means you will need to take the time to increase the amount of food in your diet and the number of weight-bearing activities that you engage in.

Losing weight will take a gradual amount of time with you engaging in vigorous cardio and making healthy choices. Your body cannot adapt to the changes that you plan to make overnight.

Published by: chazcheadle in The Programming Mechanism
Tags: , , ,

June 20, 2012 - Comments Off on Google Tech Talk: Continuous Integration

Google Tech Talk: Continuous Integration

Fitness Tips To Help You See Impressive Results

MARCH 23, 2020

Being fit has many physical and mental benefits for your health. However, many people may not understand what it fully requires to fully reach their goals. Follow these 5 fitness tips to help you see impressive results. Check these Testoprime reviews.

1. Stay Consistent

Consistency will lead you on the road to success the quickest. It doesn’t matter what your goals are. If you have consistency and develop a routine that you know that you can rely on, it will lead to you reaching your goals quicker.

For example, if you want to lose weight, you should be consistent in your cardio exercise regimen. This consistency cannot just stop at your physical exercise, though. This consistency has to extend into another important part of your routine, which is your diet.

2. Watch Your Diet

Maintain a good diet to reach your fitness goals.

Many people only focus on the gym and exercise component of attaining fitness goals. As mentioned before, your diet is one of the most important parts of your fitness regimen, but having a great diet, regardless of your fitness goals, will impact whether or not you are successful in your goals as much or more than actual exercise. This is because your body will reflect what you eat and your diet can either progress your goals further or set you back.

It may be helpful for you to keep a log of what you eat and determine which foods you need to eliminate and which foods you need to add. In addition, you also want to be mindful of when you are eating, because it can also affect your performance in the gym.

For those who are bodybuilding or looking to build muscle, it’s recommended to incorporate some kind of carbohydrates before a workout session, and then have a protein-heavy meal once you are finished to speed up the recovery process. Protein shakes are a popular commodity in this regard. However, different protein powders can have different vitamins, minerals, and ingredients that can be more effective for men or women.

Ladies can check out a variety of protein powders to see what’s available for their needs. There tend to be more protein powders available for men that already have the extra minerals and vitamins included to help them get gains. So when guys are searching for the best protein powder, it’s better to decide if they’re trying to get lean or gain weight. Visit https://washingtoncitypaper.com/article/565430/prodentim-reviews-new-report-on-this-chewable-candy-for-healthy-gums/.

3. Have Realistic Expectations

Having the right mindset is imperative to achieve the fitness goals of any kind, and it starts by having realistic expectations. If you don’t like what you see in the mirror, then you have to work hard to see a change. However, if you are looking to shed some pounds and reduce your waistline, you can’t expect it to be done within a week.

Realistic expectations directly correlate with being consistent. Gaining weight means you will need to take the time to increase the amount of food in your diet and the number of weight-bearing activities that you engage in.

Losing weight will take a gradual amount of time with you engaging in vigorous cardio and making healthy choices. Your body cannot adapt to the changes that you plan to make overnight.

June 14, 2012 - Comments Off on How to programmatically pass an argument to a view in a Quicktab

How to programmatically pass an argument to a view in a Quicktab

We are building a site in which we are using taxonomy term page templates to display some content. One of the requirements is to include a section at the bottom of the page with tabbed content which is related to the current term.
The page path will look like this: site.com/topics/topic-name. Where topic-name is a taxonomy term name. For this project, we're using the excellent Quicktabs module.

First we create the view which provides the Quicktabs content. The view will display content based on the taxonomy term being viewed, so we add a contextual filter ('arguments' in D6) based on the Term ID. Normally, the contextual filter will get its parameters from the URL, but we're using pathauto to make the URL look nice and so the taxonomy term name as represented in the path will not translate to an argument that the view can use.

Add contextual filter

Add contextual filter

At this point, the view won't work correctly, since it is expecting a term Id and the path arguments will be text. But that is ok, we're not done yet.

What we need is a way to pass the taxonomy term id to the view, but we must do so through the Quicktabs object.
Quicktabs is very cool, but as you can see in this screenshot, there is no way to pass the term id to the view with this form when the term is not in the URL.

Quicktabs settings

Quicktabs settings

As with the view we created earlier, we'll set this up and move on to the next step which will tie all of these parts together.

We created a taxonomy term template to theme the display of our terms, and that gives us access to the term id, $tid, and that is precisely what we need to feed to our view! In our term template file we print out the terms fields like we want and then at the bottom, we add a few lines of code that will send the term id to the view through the Quicktabs object and then render it.

Here's the code:

//Load the Quicktab instance and assign it to a variable we can manipulate
$qtabs = quicktabs_load('topic_tabs');
foreach($qtabs->tabs AS $item => $id) {
// Here we pass the $tid to the 'args' element of the each tab
$qtabs->tabs[$item]['args'] = $tid;
}
// Create a render array of the newly modified Quicktabs instance.
$quicktabs = quicktabs_build_quicktabs('topic_tabs', $overrides = array(), $other = array());
print render($quicktabs);

And here is the resulting themed and tid aware Quicktab:

Quicktabs with filtered view content

Quicktabs with filtered view content

Now, when we visit any term page, we will see the content and at the bottom will be the Quicktabs with the relevant content.
This can be extend in several ways. You can alter the tab titles, default active tab, the tab order, etc. all on the fly based on any number of variables.

References:

Published by: chazcheadle in The Programming Mechanism
Tags: , ,

May 11, 2012 - Comments Off on Building new sites… with some old data

Building new sites… with some old data

The files are IN the computer!

When building a new site for a client, migrating data from an old site or system can be a daunting task. There are several excellent modules such as feeds_import which can help move data that is already online in one form or another via rss/xml and so on. Sometimes there is content which needs to get onto the site that lives off-line or for other reasons isn't compatible with an existing import module- for that you can write some code to help out.

For one project we had to import a list of users which came from a CSV export from a spreadsheet. We really just needed users in the system to be able to assign them as authors of content. The following code is what we used to read in the CSV file and create the users. Any CCK field can be populated with this, here we are adding First, Middle and Last name fields before submitting.
This script relies on Drush and the Forms API to bootstrap drupal and feed it the form submission.

As with all things Drupal, there are more ways to accomplish a task than there are tasks to accomplish.

/**
* Import users via a CSV
*
*/
// Initialize a counter to track the number of users processed
$i = 0;
// Check for the .csv file in the particular directory. We create a <site>_util directory
// to put these sorts of scripts.
if (($handle = fopen("./sites/all/modules/custom/site_util/new-users.csv", "r")) !== FALSE) {
// While there are rows of data in the file, keep looping through.
while (($data = fgetcsv($handle, 0, "," )) !== FALSE) {
// Read in and sanitize data from the CSV file.
// Here we assign each column to a variable.
$fname = utf8_encode(trim($data[0]));
$mname = utf8_encode(trim($data[1]));
$lname = utf8_encode(trim($data[2]));
$email = trim($data[3]);
// Create random 8 character password.
$pass = user_password();

// Initialize the $form_state array which will be passed to drupal_form_submit.
$form_state = array();

// Tell drupal_form_submit what operation this form is performing
$form_state['values']['op'] = t('Create new account');

// Drupal 7 requires this second password field to create users.
$form_state['values']['pass']['pass1'] = $pass;
$form_state['values']['pass']['pass2'] = $pass;

// Populate the name and email elements of $form_state.
$form_state['values']['field_profile_fname']['und'][0]['value'] = $fname;
$form_state['values']['field_profile_mname']['und'][0]['value'] = $mname;
$form_state['values']['field_profile_lname']['und'][0]['value'] = $lname;
$form_state['values']['mail'] = $email;

// Build a human readable Username. We are using email as the primary login.
// Since the users do not always have a middle name we will use a
// a ternary operation to prevent adding a second space between the
// first and last name.
$form_state['values']['name'] = $fname . ' ' . ($mname ? $mname . ' ' : '') . $lname;

// Since we're running on the command line, we'll add some status information.
print('Adding: ' . $form_state['values']['name']. "n");

// Finally, we submit the built $form_state array to Drupal's user_register_form.
drupal_form_submit('user_register_form', $form_state);

// Increment the counter.
$i++;
}
}
print("Processed: " . $i . " users.");

Save this code to a file and then run execute it with drush:
% drush scr script.php

Thats it. It should import your users and report at the end.
You'll need to make sure the data going in is sensible, valid emails, names etc.

Published by: chazcheadle in The Programming Mechanism
Tags: , , , ,

January 4, 2012 - Comments Off on Starting Mobile Web Development

Starting Mobile Web Development

We recently underwent the process of making our site mobile and tablet friendly. The next phase in growing our business and making it much more accessible is definitely to branch out and use services of qualified companies like Vecro Tech for our application making it easily accessible on android, windows, and ios operating systems. The results look fantastic but our implementation has, in places, been a bit cumbersome since the original site was not laid out with such an adaptation in mind. Now that we're more or less done I felt it would be pertinent to create a list or useful resources found and lessons learned along the way. Since this entire branch of web development is still so young and liquid I don't know how long the following will be useful but I hope it helps those as lost as I was when we began this trek.

Adapt or Leave?

One of the biggest questions when faced with the prospect of creating a mobile site is "Should my site adapt or redirect?" Unfortunately I don't believe there is one right answer to such a question since, like so much in life, it depends!

Some key factors that might affect our decision include the functionality we want, type of content we mean to serve and look/feel of our design. Is it important that our mobile version have stunningly different design and/or app-like animation effects? Then we probably need to hire a landing page expert. Are we mainly trying to provide a mobile version of a news, blog or other site where content is the focus? Then a media query adaptation would be beneficial as we make it easier for users to share content between devices (and keep all that traffic in one place to boot). However both options can be adapted either way if we put in enough work.

Let's not forget the last option: making a web app. Using services like PhoneGap we can take a our HTML and make it into a bonafide app on the user's device...well it's really just a virtualized webpage with greater device integration (accelerometer, media, camera, etc.)  and a dedicated icon on the device but sometimes that can be a great branding edge. And there's the added bonus that users can then use our "site" even when not connected to the internet though the line between website and app begins to blur at this point. A direct migration of your website to an app will probably never clear the iTunes store's strict approval process so we need to add something unique which may  be more trouble than its worth.

Let Me Pose You a Query Sir

Media Queries: confusing, under-documented, cutting-edge, useful as all hell and bloody confusing! It took me awhile to get my head around these little statements of goodness. Once I did I came to understand their power and structure. We have two main options when dealing with media queries; we can use them to specify certain CSS links or alternatively we can write them into an existing CSS file. Personally I used a mix. It made sense to use the internal CSS version when altering this blog's WordPress theme while on the other hand the link option made sense for most other pages. In general I'd  recommend the linking option since it keeps each CSS shorter, allows for easier document navigation and generally keeps our process cleaner.

It's easiest to think of media queries as giant "If" statements that inject our extra CSS when our given properties are met. As such, we must remember to override existing styles in order to apply our new device-friendly ones. It can be tedious searching through our original CSS file to see which specific properties need to be overwritten. I found it easiest to simply copy the entire original CSS, do all changes as required and then go through and delete any definitions or properties that remained constant (I sniff an extremely useful code highlighting/SVN tool that could do this comparison automatically along the liens of CSSlint).

Another nice benefit of media queries is the ease of testing and updating them. During the development process, make sure to specify "max/min-width/height" AND "max/min-device-width/height." This will ensure that our queries appear not only devices with the specified resolution but also any similar window viewport allowing us to use Firebug/Chrome Inspector as we normally do for a familiar debug cycle as well as useful previewing tools like Protofluid. Just remember that once the site is live, we should only target devices if we don't want adaptive versions appearing on desktop browser windows of the required size as was our case since the mobile versions or so device specific.

Quite Novel

Don't forget this is a completely new ballgame. Using media queries, especially with mobile devices, we can add all sorts of fun and/or hidden functionality into a site. How about a site that literally changes personality the smaller the window? Maybe you have a logo or character that actually reacts to the changing amount of space they're given as elements shift about them? And don't be afraid to think even more radically. The very function of a page could alter depending on a devices orientation. We could have our copy appear in portrait and then an image gallery appear in landscape (as is the case for our iPad site). Such novel use of media queries can completely redefine how people interact with a site and help redraw the front lines of the ongoing war between app and webpage.

No touchy

Of course not all the changes that come out of these new device are solely good. In fact the biggest one requires a fundamental change in how we think about design and interaction: touch. No cursor means no hover. Truly though, hover is simply an artifact of the invention of the mouse, itself not very old and clearly diminishing in importance. There's now a new frontier of interaction and design patterns to be explored.

Here though, the waters are still quite murky. Some plugins, like this jQTouch one, allow a webpage to respond to touch-specific events that most browsers and libraries don't yet natively handle. Of course this comes with the down side that we also lose our native touch-to-scroll ability (though theoretically we could reconstitute this functionality by hand or via work-arounds). For sites designed specifically for small screen devices this opens up many new possibilities that before only existed natively in apps and not on the browser.

Real Estate

One clear limitation we have on mobile devices is the lack of real estate. Design is all about creating something to fit within certain restrictions which are quite tight in this case. However good design often comes out of such challenges so the news isn't all bad. Sadly problems arise since lack of space also reduces our margin of error. When designing a website for the browser, we can safely assume that most screens will fit a design of a specific minimum height and width with room to spare or allow the user to easily scroll about the page to see everything. You can read the Space Selectors blog for more information (https://spaceselectors.com/blog/).

Alas the fragmented nature of the mobile market, even if we disregard tablets, poses greater challenges since different devices not only have a wide range of sizes and screen ratios but also numerous different abilities and native elements. As such we must be dead certain that our site is adaptive to many heights, widths and especially devices. Yet by in large the best mobile sites are designed to fill the screen perfectly so making adaptive designs can be difficult to impossible. Perhaps this is where "good enough" is fine since the prospect of specifying designs for each resolution is daunting to say the least. Furthermore, we can try and maximize our real estate by hiding browser elements when possible. For instance many mobile sites "hide" the address bar on mobile Safari by programmatically scrolling the page down by the bar's height giving us more space above the fold.

If It Ain't Fixed

We've grown used to a lot of functionality on the web but many of these norms may not have been carried over to the mobile world, at least not yet. Some APIs may not yet have native support for our platform of choice but we can, on occasion, find workarounds like this one for the Google plusone button. However, sooner or later we have to simply cut functionality from our mobile site and sometimes this may be for the best considering the restrictions and problems discussed so far. So if you're wasting time trying to get a certain resource to function on your mobile site when you could be perfecting the design itself or, better yet, device testing, consider simply hiding that element or simplifying the functionality. After all, even if you get it to work it's only a matter of time until official support rolls out and your work's left out in the cold.

References
  • Smashing Magazine Intro Tutorial
  • Less useful Adobe Tutorial but with great list of possible properties
  • ProtoFluid is a great way to test out your Media Queries. It essentially creates a iFrame of a given URL with dimensions specified by the chosen device. I found it to be a bit unstable and often designs look different on the actual device. There is also the lack of scroll/touch, the persistence of hover states and other Desktop-Device hybrid funniness but its great for checking your initial layout. BE SURE TO TEST ON DEVICES AS WELL!!! (Note: since Protofluid works via Desktop browser, make sure all your queries specify "width" and "device-width" as outlined above)
  • Hide address bar in iOS mobile Safari
  • Google+ plusone mobile button fix

Published by: benchirlin in The Programming Mechanism
Tags: , , , ,

May 20, 2010 - Comments Off on Developing web apps for the Chrome web store

Developing web apps for the Chrome web store

Erik Kay

Yesterday's keynote recap

* HTML5
* Web apps
* Chrome web store

Two perspectives on web apps

* Users: How can I get better web apps?
* Developers: How do I make money doing this?

From a user perspective, web apps can be difficult to find. Awareness.

No authoritative place for web apps. Web apps may contain a lot of contain, but generally doesn't contain content that can be crawled and indexed in the standard way.

The cheaper the purchase is, the more the trust and convenience issues get in the way.

Web apps are special to users, but the browser treats it like any other page.

Web apps don't have a shortcut to launch them, don't have deep OS integration. Etc.

Security model of browser is good, because able to trust most links. Part of model enforces limited capabilities. There are times we'd like the web app to do more, but no way to indicate this trust.

Web store link will be integrated tightly with the Chrome. Link always there.

Apps launched from the apps tab will display differently. Address bar hidden (to make the app central). The actual app tab will be smaller, but the favicon will be larger. Trying to treat the app as a first-class citizen.

How to monetize web apps

If costs are high and traffic is low, you don't get to set the price, it sets itself.

Need to integrate with payment processors.
In order to attract the most users, must target the least capable browser.

Web store wants to handle licensing and payment for you. Web is not a captive audience--not like the other phone app stores.

Pushing us to just use Chrome (???) and the Chrome web store. A lot of users on Chrome. Explicitly said, "We don't need to target the lowest browser anymore." Interesting (especially since the web app is available on the web) and a lot of these features aren't even supported in Firefox. Reminds me a lot of what Gears promised two years ago (and never delivered). And then it was gone.

Any app can go in the web store (HTML, Flash).

Can add a JSON manifest and icons for packaging to the store.
Can add permissions at install time to remove some of the browser's security model!
Can add permissions property to JSON manifest (array of required permissions).

If user trusts and installs the app, then will not be constantly prompted by the browser.

Installation similar to an extension.

Google Maps added geolocation support for select browers. (hadn't noticed this before)

Action items

* FAQ: http://chrome.google.com/webstore
* Docs: http://code.google.com/chrome/apps
* Build a really cool web app
* Join the discussions

Developer preview this summer and then open to public in the fall.

Published by: jeffreybarke in The Programming Mechanism
Tags: ,

May 20, 2010 - Comments Off on Live blogging Google I/O: Google Analytics APIs: End to end

Live blogging Google I/O: Google Analytics APIs: End to end

Nick Mihailovski

First time GA has done anything at Google I/O.

Four components
* Processing
* Management
* Data collection
* Data exporting

Core processing

Dimensions: Strings (80 dimensions)
Metrics: Numeric values (95 metrics)

1. Logs (collection)
2. Goals, filters, profile settings (management)
3. Data structure (processing)
4. Functions (processing)
5. Tables (processing)
6. Query engine (export)

Core visitor interaction model

Visitor/session/hit levels

1x1 tracking pixel with a number of parameters appended. Three of these parameters relate to visitor, session, hits.

Their back end parses their logs and sorts and stores based on parameters.

ga:visits

int visits(Session session, int index) {
}
[Too quick to get these code snippets]

Developer platform

Data types (several)
Protocol (_utm.gif)
Client libraries:
* JavaScript (ga.js)
* Android SDK
* iPhone SDK
* Mobile websites
** PHP/JSP/ASP/Perl
* ActionScript 3
** Flash/Flex/Air
* Silverlight

Account Management

Data types:
* Accounts
* Web properties
* Profiles
* Goals
* Advanced segments

Protocol:
* Google data

Data export API

Protocol: Google Data
Client libraries:
* Java
* JavaScript
* Python
* .Net (C#)
* Ruby
* Perl
* PHP

Use the Data feed query explorer (in Google Labs)

Example integration

Using visitor behavior to optimize user experience: ranking a number

Start with a list of unordered links. Can use GA to track the number of times people click on these links.

Demo is powered by MAMP; hopefully the code will be made available. (Definitely need this code)
Two parts to the demo:
1. How to send data explicitly to GA
2. How to retrieve data from GA

Part one was implemented with PHP and JS
Part two is a scheduled .Java application

Recently introduced asynchronous tracking (to avoid blocking the browser).

Working on a better developer ecosystem:
http://google.com/analytics/apps

Working on a better turn-around time than 24-hours.

Working on complete data export, but difficult because they store it as a cube. The current export API is actually more of a query API.

Published by: jeffreybarke in The Programming Mechanism
Tags: ,