Monday, March 7, 2016

Re-Implementing the Range Operator in PHP

In the prequel to this article
(hint: make sure you’ve read it first), I showed one way to implement a range
operator in PHP. Initial implementations, however, are rarely the best, and so
it is the intention of this article to look at how the previous implementation
can be improved.

Thanks once again to Nikita Popov for proofreading
this article!

Previous Implementation Drawbacks

The initial implementation put all of the logic for the range operator into the
Zend VM, which forced computation to take place purely at runtime when the
ZEND_RANGE opcode was executed. This not only meant that computation could
not be shifted to compile time for operands that were literal, but also meant
that some features would simply not work.

In this implementation, we will shift the range operator logic out of the Zend
VM to enable for computation to be done at either compile time (for literal
operands) or runtime (for dynamic operands). This will not only provide a small
win for Opcache users, but will more importantly allow for constant expression
features to be used with the range operator.

For example:

// as constant definitions
const AN_ARRAY = 1 |> 100;

// as initial property definitions
class A
{
        private $a = 1 |> 2;
}

// as default values for optional parameters:
function a($a = 1 |> 2)
{
        //
}

So without further ado, let’s reimplement the range operator.

Updating the Lexer

The lexer implementation remains exactly the same. The token is firstly
registered in Zend/zend_language_scanner.l
(line ~1200):

<ST_IN_SCRIPTING>"|>" {
    RETURN_TOKEN(T_RANGE);
}

And then declared in Zend/zend_language_parser.y
(line ~220):

%token T_RANGE                    "|> (T_RANGE)"

Continue reading %Re-Implementing the Range Operator in PHP%


by Thomas Punt via SitePoint

Quick Read: Search 11,000 Free Stock Photos with Zoomy

Finding high-quality stock photos for your next project can not only be a time-consuming process but also an expensive one.

With digital restriction management, copyright, licenses, and trademarks, we live in an era where we are constantly reminded to be careful to not step on each other's toes. Avoiding such issues can avoid both major headaches and 'time-sinks' when working on a project.

That is exactly where Zoomy App promises to deliver.

Zoomy is a small, yet very useful stock photo aggregator app, drawing together thousands of Public Domain photos from multiple sources. For ease of use the photos are licensed under the Creative Commons Zero (CC0) license, meaning they in the public domain and free of any kind of restriction.

The app is available for Windows, Mac OS X and even Linux (I'm especially happy about this one) and costs of just $4 USD. That is a minimal price to pay for easy access to a vast pool of unrestricted visual goodness. You receive an application token key which you can use in your Zoomy installation.

The application also includes some extra Zoomy-exclusive photos not available via any other sites. Zoomy fetches CC0 photos from over 30 sources, including Unsplash, the Public Domain Archive and others.

Features:

Furthermore, the app also offers the ability to:

  • Filter photos by color–10 colors available from warm to cool shades
  • Search photos by layout format (Square, Landscape or Portrait) dimensions
  • Selected photo can be favorited, downloaded, organized in collections or simply copied by the URL
  • Photos can also be searched by tags

You can also visit the original source of the photo, if you ever need to do so.

The interface is simple and organized, offering a responsive experience when exploring the tons of photos Zoomy aggregates.

Having said that, your experience might be compromised to some extent if you have a slow-ish internet connection. As a lot of the stock photos on Zoomy are over 4K in resolution, that might be not surprising.

WordPress Plugin

Interestingly, Zoomy offers also a WordPress plugin which seamlessly integrates the Zoomy library into your WordPress installation.

It is not available yet on the official WordPress.org website, but you can download it from its GitHub repository, and manually add it to your self-hosted WordPress site.

Check out the ReadMe if you struggle with the plugin.

Continue reading %Quick Read: Search 11,000 Free Stock Photos with Zoomy%


by Elio Qoshi via SitePoint

Improve Your Ruby with the Adapter Design Pattern

Imagine we have some code where we want to accomplish things in a variety of ways. One way to do this is with conditional branching:

class Animal
  def speak(kind)
    puts case kind
    when :dog then "woof!"
    when :cat then "meow!"
    when :owl then "hoo!"
    end
  end
end

Animal.new.speak(:dog)

This works, but what if a developer wants to add a new way? With conditional branching, the entire method would need to be overwritten. Instead, we can separate the implementations into modules:

class Animal
  module Adapter
    module Dog
      def self.speak
        puts "woof!"
      end
    end

    module Cat
      def self.speak
        puts "meow!"
      end
    end
  end

  def speak
    self.adapter.speak
  end

  def adapter
    return @adapter if @adapter
    self.adapter = :dog
    @adapter
  end

  def adapter=(adapter)
    @adapter = Animal::Adapter.const_get(adapter.to_s.capitalize)
  end
end

animal = Animal.new
animal.speak
animal.adapter = :cat
aanimal.speak

This is a lot more code! However, if we want to add another module,

Continue reading %Improve Your Ruby with the Adapter Design Pattern%


by Robert Qualls via SitePoint

Last Chance to Pay What You Want for the White Hat Hacker Bundle

Last chance to pay what you want for the white hat hacker bundle

If you’re ready to jump into the lucrative white hat hacking industry, don’t miss this deal. It’s your last chance to pay what you want for the White Hat Hacker Bundle at SitePoint Shop.

Get seven courses worth $765 that’ll teach you how to think like a hacker to protect companies against them. You’ll learn all the skills you need to secure a job in penetration testing and ethical hacking, like cracking passwords, gaining remote control of devices, using debuggers, hack Windows systems, key logging, and more. Lifetime access to all of the material means to can polish your skills whenever you need to—like before your next job interview.

This deal is going fast, so don’t miss your last chance to grab it. Pay what you want for the White Hat Hacker Bundle at SitePoint Shop.

Continue reading %Last Chance to Pay What You Want for the White Hat Hacker Bundle%


by SitePoint Offers via SitePoint

FaceMocion – jQuery Facebook Emoticons

FaceMocion is a plugin to create Facebook emoticons with jQuery and CSS. It allows you to turn any text input emoticons on the page into cute little smiling faces.


by via jQuery-Plugins.net RSS Feed

How the "Order Totals" Extensions Work in OpenCart

How to Pin Your Facebook Carousel Ad as a Page Post

kh-facebook-carousel-post-560

Do you want more organic traffic from Facebook? Have you considered pinning your ads as Facebook page posts? In this article you’ll discover how to drive organic traffic and conversions by pinning a Facebook carousel ad to your page as a post. #1: Set Up Your Facebook Carousel Ad First, you need to create your Facebook [...]

This post How to Pin Your Facebook Carousel Ad as a Page Post first appeared on .
- Your Guide to the Social Media Jungle


by Kristi Hines via