Monday, December 21, 2015

Ruby Can Be Faster with a Bit of Rust

rusy

In spring of 2013, Sam Saffron committed fast_blank to GitHub. It was a C extension that provided a fast drop-in alternative to ActiveSupport's String#blank? method which returns whether a string is nothing but whitespace.

At Full Stack Fest 2015, Yehuda Katz presented a talk where he described his investigation into rewriting fast_blank in Rust. His initial goal was to try a naive one-liner (excluding his implementation of Buf) and see how much slower it was than the original C extension.

extern "C" fn fast_blank(buf: Buf) -> bool {
  buf.as_slice().chars().all(|c| c.is_whitespace())
}

To his surprise, it was faster.

Continue reading %Ruby Can Be Faster with a Bit of Rust%


by Robert Qualls via SitePoint

A Beginners Guide to Titan Framework: Adding Multicheck-Posts, Multicheck-Pages, and Multicheck-Categories Type Options

Convert OpenCart Modules From 1.5.x to 2.x.x

It's been a year now since the release of OpenCart 2.x.x, and now things seem to be stabilized as far the core APIs are concerned. Obviously, most of the popular extensions support the 2.x.x version and are out there along with their 1.5.x version code. You'll also find lots of extensions which allow migration from the existing 1.5.x setup to the latest version. 

Of course, there are certain limitations with these kind of extensions as they can't convert everything, specifically custom modules.

So in this article we'll go ahead and dissect the code snippets of the major components of the OpenCart module. Further, we'll see how you can convert it to be compatible with OpenCart 2.x.x. Without any further theory, I'll straight away dive into the geeky stuff!

Changes in the Controller File

In this section, we'll see the code changes required in the controller file. For the purpose of this example, I've selected the "account.php" controller file under the "catalog/controller/account" directory.

URL Redirection

Let's have a look at the 1.5.x snippet for the redirection. In the older version, the redirect method was part of the abstract Controller class, so you could call that directly using the $this object.

Now, here's what it looks like in the 2.x.x version. In the recent version, the redirect method belongs to the Response class and is thus accessed via that object.

Load the Language File

In 1.5.x, you would use the following snippet to load the corresponding module language file.

On the other hand, you need to use a slightly different version in the case of OpenCart 2.x.x, as shown in the following snippet.

Variable Assignment

We could say that it's one of the major changes in the context of the controller method, as most of the time you'll end up assigning your variables so that you can access them in the view template files.

In 1.5.x version, you would do something like this:

In 2.x.x, the same can be achieved by:

As you can see, in the recent version the $data array is prepared exclusively and it's passed as a view argument. In the earlier version, it was a properly of the abstract Controller class.

Breadcrumb

In the recent version, you don't need to provide a "separator" as an array key as opposed to the earlier version.

Here's the snippet from the 1.5.x version:

A similar result can be achieved by using the following code:

Children Template Assignment

In 1.5.x, you needed to provide an array to assign all the children templates like header, footer, column_left, etc.

In the case of the 2.x.x version, you'll use the controller method of the Loader class.

Template Assignment

In the earlier version of OpenCart, you would have used the following code to assign the template file and render it.

In the recent version, you'll need to use a slightly different and shorter way to handle it.

As you can see, in the recent version we're using the view method of the Loader class.

So, that's it as far as the controller-related changes are concerned. Using the checklist above, you should be able to convert the controller code from the older to newer version easily.

Changes in the Model File

Although model files are almost identical in both versions, there's a new feature called "Event Notifications" introduced in the recent version of OpenCart. It's a nice concept which allows you to trigger certain events and thus inform the corresponding observers if available.

Using the "Event Notifications" feature, you could allow data modification by the other modules which implement the observers for the related events before saving to the database. Let's take an example snippet from the "catalog/model/account/address.php" file.

It'll trigger an event before the address of the customer is added or updated. It'll allow other modules to alter the address data before it's saved to database. So basically, that's the only major change as far as the model is concerned. Having said that, you could also trigger the events from other components of the module.

Changes in the View File

In the final section of this tutorial, we'll discuss the changes in the view component of the module. One of the major changes is the introduction of the "Bootstrap" library, thus making the template responsive. Of course, your old templates will work in the recent version too, but won't be responsive. OpenCart 2.x.x is mobile first, so you can't ignore the responsiveness of your template.

I would like you to explore "catalog/view/theme/default/template/account/account.tpl", in which you'll see CSS class names like "col-sm-6" and "col-sm-9", which indicate the presence of the bootstrap library. So basically, as bootstrap is in the core itself, you would like to utilize most of the features provided by it.

So in the case of the view files, you need to convert the old XHTML code to the new responsive structure. Apart from that, it's the same way variables are printed and other children templates included.

So, that's it as far as today's article is concerned. I am sure that the steps which are mentioned above will help you to convert your modules from the 1.5.x to 2.x.x version.

Conclusion

Today, we discussed exactly what changes you need to make in your existing 1.5.x based OpenCart modules to convert them to be 2.x.x compatible. I hope that you've enjoyed it, and feel free to post your thoughts on the topic!

An OpenCart Theme

If you'd like to take your learning to the next level, see what it's like to see it in action, and practically apply what you've learned in this tutorial, then check out the MediaCenter Responsive OpenCart Template.


by Sajal Soni via Envato Tuts+ Code

Trefecta

Every part of the Trefecta e-bike is hand built to perfection. Build in Amsterdam strived to do the same when creating their e-commerce platform.
by via Awwwards - Sites of the day

How to Use Facebook Local Awareness Ads to Target Customers

rab-facebook-local-ads-560

Do you want to promote your local business to customers using Facebook? Have you heard of Local Awareness Ads? Local Awareness Ad campaigns are easy to set up and let you reach Facebook users based on the business location they’re closest to. In this article you’ll discover how to target customers near your business with Local [...]

This post How to Use Facebook Local Awareness Ads to Target Customers first appeared on Social Media Examiner.
Social Media Examiner - Your Guide to the Social Media Jungle


by Rocco Alberto Baldassarre via Social Media Examiner

Nominate Your Favorite Social Media Blog: 7th Annual Top 10 Social Media Blog Contest

ldj-top-10-blog-560

We’re now accepting nominations for our 7th annual Top 10 Social Media Blogs contest and we’re looking for the blogs you read and found most valuable in 2015. This is the biggest contest for social media blogs and the winners will be promoted in our 430,000-reader newsletter and announced on Social Media Examiner. How to [...]

This post Nominate Your Favorite Social Media Blog: 7th Annual Top 10 Social Media Blog Contest first appeared on Social Media Examiner.
Social Media Examiner - Your Guide to the Social Media Jungle


by Lisa D. Jenkins via Social Media Examiner

Scrollator : jQuery Scroll Bar Plugin

Scrollator is a jQuery-based replacement for the browsers scroll bar, which doesn’t use any space. Has very good performance.

The post Scrollator : jQuery Scroll Bar Plugin appeared first on jQuery Rain.


by Admin via jQuery Rain