Composer install suggestions

With Craft CMS 3 Beta, there's a fair amount of packages to install via Composer, there's also a sizeable list of suggested packages (mostly for use with sources). Usually I'd just include whichever suggestions I'd want to install by copying and pasting each package into a `composer require X`, but there's a quicker way to go from suggestion to require; the following line will add a ll suggested packages as a requirement to your Composer project.

composer suggests | xargs -i composer require {}

This may be overkill for some (most?) projects but for Craft CMS 3, I want to ensure these packages are available should a user or plugin later require it, or if a suggested package is just more efficient! Like the `ext-gmagick` package for use with P&T's Imagine editor.

Open Google Chrome in Kiosk Mode on Mac

set strUrl to "https://example.org"
do shell script "/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --app=" & strUrl tell application "Google Chrome" to activate
tell application "System Events"
keystroke "f" using {command down, control down}
end tell

Remove all .DS_Store files

.DS_Store  files aren't much of a problem to your Mac, these small files provide information about how you want to see the directory laid out, the position of icons within the folder. However, if they disturb your chi you can remove them recursively from /  using the following command:

sudo find / -name ".DS_Store" -depth -exec rm {} \;

These files will of course be regenerated whenever you enter a directory without one via Finder.

Queueing jQuery scripts before the library

When trying to queue jQuery scripts to run before loading the library itself, this usually results in that code not working. If you want to load jQuery at the end of your page (or asynchronously) but you may need to include jQuery within a template part way through the page the following code allows you attach and queue up scripts to run when jQuery initialises.

if ( ! window.deferAfterjQueryLoaded ) {
    window.deferAfterjQueryLoaded = [];
    Object.defineProperty(window, "$", {
        set: function(value) {
            window.setTimeout(function() {
                $.each(window.deferAfterjQueryLoaded, function(index, fn) {
                    fn();
                });
            }, 0);
            Object.defineProperty(window, "$", { value: value });
        },

        configurable: true
    });
}

window.deferAfterjQueryLoaded.push(function() {
    //... some code that needs to be run
});

What this does is:

  1. Defines deferAfterjQueryLoaded  lazily, so you don't need to inject that into head .
  2. Defines a setter for window.$ . When jQuery loads, one of the last things it does is assign to the global $ variable. This allows you to trigger a function when that happens.
  3. Schedules the deferred functions to run as soon as possible after the jQuery script finishes (setTimeout(..., 0);) .
  4. Has the setter remove itself.

For complete cleanliness you could have the scheduled function remove deferAfterjQueryLoaded  as well.

--

This answer is provided from StackOverflow.

GET parameters with JavaScript

function getSearchParameters() {
      var prmstr = window.location.search.substr(1);
      return prmstr != null && prmstr != "" ? transformToAssocArray(prmstr) : {};
}

function transformToAssocArray( prmstr ) {
    var params = {};
    var prmarr = prmstr.split("&");
    for ( var i = 0; i < prmarr.length; i++) {
        var tmparr = prmarr[i].split("=");
        params[tmparr[0]] = tmparr[1];
    }
    return params;
}

var params = getSearchParameters();

Source: StackOverflow

iOS 9: -canOpenURL: failed for URL

If you're receiving the following error in Xcode:

-canOpenURL: failed for URL: "<scheme>://" - error: "This app is not allowed to query for scheme <scheme>"

Apple changed the canOpenURL method on iOS 9. Apps which are checking for URL Schemes have to declare these Schemes as it is submitted to Apple. More info here.

Simply open your app's .plist (usually platforms/ios/<appname>/<appname>-Info.plist ) with an editor and add the following code with your needed Schemes.

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>tweetbot</string>
    <string>twitter</string>
    <string>googlechromes</string>
</array>

Placeholder for HTML Select box

Select boxes don't currently support the 'placeholder' attribute, so here's a workaround that works just as well.

<select>
    <option value="" disabled selected style="display: none;">Please Choose</option>
    <option value="0">Open when powered (most valves do this)</option>
    <option value="1">Closed when powered, auto-opens when power is cut</option>
</select>

The Disabled option stops the <option> being selected with both mouse and keyboard, whereas just using display: none allows the user to still select via the keyboard arrows. The display: none style just makes the list box look 'nice'.

Note: Using an empty value attribute on the "placeholder" option allows validation (required attribute) to work around having the "placeholder", so if the option isn't changed but is required; the browser should prompt the user to choose an option from the list.

This method is confirmed working in the following browsers:

  • Google Chrome - v.43.0.2357.132
  • Mozilla Firefox - v.39.0
  • Safari - v.8.0.7 (Placeholder is visible in dropdown but is not selectable)
  • Microsoft Internet Explorer - v.11 (Placeholder is visible in dropdown but is not selectable)
  • Project Spartan - v.15.10130 (Placeholder is visible in dropdown but is not selectable)

Rebuild Spotlight Index on Mac OS X

Sometimes after several months Spotlight doesn't work very efficiently and starts to slow down your Mac. Fortunately there's a way to reset the Spotlight Index so that it reindexes your drives which may also lead to a smaller index file size.

Just open Terminal via Spotlight or go to Applications > Utilities > Terminal and copy in the following:

sudo mdutil -E /

This will clear everything from Spotlight and the reindex will start immediately.

If you're having problems (or suspect you're having problems) with a particular drive you can reindex only that drive by using the following command:

sudo mdutil -E /Volumes/[DriveName]

Just replace [DriveName] with the actual path or omit the path; drag and drop the drive from Finder to insert it.

You can exclude drives from Spotlight by going to System Preferences > Spotlight > Privacy.