Monday, March 28, 2016

WP ACF - one extra space and the field is not getting saved

ACF plugin in WP is sensitive to whitespaces when using add_row() to add new rows to repeater fields.

Sunday, March 27, 2016

YouTube uploading via PHP API - a few comments

A few comments on uploading to YouTube using YouTube PHP API v3:

In case of smaller chunks (<=25MB), there's a higher chance the upload will resume.

However, the speed of upload in that case might increase, due to the fact that CPU has to glue together many tiny parts.

Also, streaming from shared hosting is slow (starts/stops the video all the time). You should either use some kind of dedicated video server or just upload your videos to YouTube :)

Saturday, March 26, 2016

BrakcetHighlighter is a cool Sublime plugin

If you are using Sublime as your primary code editor, you should check the BracketHighlighter plugin.
It enables you to easily find non-closed brackets of any kind.

Put this in BracketHighlighter's, User Key Bindings option:

[

//SELECTION INSIDE QUOTES:
    {
        "keys": ["ctrl+8"], "command": "expand_selection_to_quotes"
    }


]


and it will enable you to select the whole text between single or double quotes by simple CTRL+8 keyboard shortcut!

There's much more power in this nice plugin , so make sure you try it. You can install it from Preferences->Browse Packages->Install package.

Why Angular and Angular-like techs are the future?

There is one feature of Angular that saves us so much time. It's the two-way binding!

Two-way binding is makes handling multiple, distributed states transparent and easy.

For example, if you create a textbox with ng-model tag, you basically create a new state.

This state usually needs to be in-sync with the state representing the textbox in js code. Angular does this automatically, under the hood, and thus leaves us much more time to worry on real code.

D.R.Y. is an always underestimated principle of GREAT design.

Bolierplate code  / spaghetti code is the enemy of great design.

Great code always tries to reduce the software entropy, while making the execution paths predictable.

Friday, March 25, 2016

curl with Plesk 12 Cron Jobs

If you're using a curl based scheduled job in plesk, and your site requires Basic Auth (curl -u parameter) , make sure you escape % character. Just make it \%.

Otherwise you might see either syntax errors, or prematurely terminated command strings.

Common errors:
curl ->no url specified
curl -> unterminated quotes
curl->Syntax error

Sunday, March 20, 2016

Grant Cardone: What did you do in the last 24 hours? What did you do that had no chance of generating any money?

Non programming related. Sales expert, Grant Cardone explains a great thing for anyone interested in making more money:

https://youtu.be/cUwQjJMTCPg?t=1017

YouTube API v3 -> connection timeout on uploading large videos

If you are getting a Connection timeout error / exception, saying that after 1000000 ms, the connection timeout happened, you can help yourself by increasing the timeout for the actual insert request. You need to do that by calling your clients, getIo() and the setting the higher timeout by setTimeout().

It should help you to successfully upload larger vidoes to YoutTube :)


If not, then you can speed up the upload, at least in some situations, by sending larger chunks.
For example,

  $chunkSizeBytes = 30 *1 * 1024 * 1024;
$media = new Google_Http_MediaFileUpload(
            $client,
            $insertRequest,
            'video/*',
            null,
            true,
            $chunkSizeBytes
        );

This will send 30MB chunks instead of default 1MB chunks, which will make uploads go much faster if your server has an excellect connection to the net (as it should have), and enough of RAM :)

Cool ideas:


http://stackoverflow.com/questions/31196930/how-do-i-resume-a-crashed-upload

https://developers.google.com/api-client-library/php/guide/migration#changes-in-members-accessibility

http://stackoverflow.com/questions/972925/persistent-keepalive-http-with-the-php-curl-library

http://stackoverflow.com/questions/27800007/google-api-php-client-send-etag

GoDaddy's limitation of ~120 seconds timeout is still there, but mitigated with these workarounds , changes in the uploader design :)

Plus, GoDaddy's error log  still shows no errors , albeit the script is terminated at 120seconds.

Also , non-native PHP does seem to work better in terms that it makes resumable uploads possible, after the first ERR_CONNECTION_RESET failure (while uploading to GoDaddy server from a local computer).

Saturday, March 19, 2016

max_execution_time might not be catchable?

Testing on a GoDaddy account, I don't see a way to catch error max_execution_time allowed. All the error logs are empty, internal error 500 returned, register_shutdown_function is ignored (runtime exits before that function gets called? )

GoDaddy, various troubles with max_execution_time and long running scripts:


https://jumblecat.com/post/2432


https://www.zen-cart.com/showthread.php?110621-500-Internal-Server-Error-FastCGI-incomplete-headers-(0-bytes)-received-from-server/page2


https://wordpress.org/support/topic/500-internal-server-error-on-godaddy-1


http://stackoverflow.com/questions/21926795/how-to-create-php-ini-file-in-godaddy

This seems to be a classical issue with cloud providers. They can terminate your script any time they want. This requires a better strategic approach to overcome......

Algorithm changes, error detection changes, and so on (since the main error log is not available and the standard error log is empty)!

Sample approach in case of a large video file upload on a shared hosting:

Incremental creation of a large video file, by separate, sequential processes piece by piece, instead of a large bulky single process creation from file chunks. Tested on GoDaddy server , and works :)


UPDATE:
GoDaddy seems to be dropping long TCP connections. ERR_CONNECTION_RESET occurs even with the chunked file approach. Probably because the TCP connection is shared among the HTTP requests.....


NEW UPDATE:

Two giant changes:

->First, if you use non-native version of PHP, it does not seem to issue ERR_CONNECTION_RESET. This could be due to the fact that in this case the system really respects the max_execution_time and other params, which are set in PHP options in CPANEL!!!!!

Wednesday, March 16, 2016

Add a .git repo to your bower.json as a component / dependency

Example, add picoFeed github repo to our project:


"dependencies": {
  "eonasdan-bootstrap-datetimepicker": "^4.17.37",
  "rsvp.js": "rsvp#^3.1.0",
  "gulp": "^3.9.1",
  "slick-carousel": "slick.js#^1.5.9",


  "picoFeedRepo":"https://github.com/fguillot/picoFeed.git"
}

Install using simple :

bower install picoFeedRepo 

:)


http://stackoverflow.com/questions/19348076/installing-a-dependency-with-bower-from-url-and-specify-version

http://stackoverflow.com/questions/16949173/how-to-install-latest-untagged-state-of-a-repo-using-bower


One thing to note:

Server side packages are usually delivered via composer, and bower is mostly used for client-side code (i.e.JS libraries)

Git basiscs : how to keep your feature branch in sync with master

Three cool threads:



http://stackoverflow.com/questions/5601931/best-and-safest-way-to-merge-a-git-branch-into-master

https://help.github.com/articles/resolving-a-merge-conflict-from-the-command-line/


http://stackoverflow.com/questions/16329776/git-howto-keep-a-branch-in-sync-with-master


Monday, March 14, 2016

debug_backtrace() is not always executable

In case it fails inside a include or include_once, it won't be executed. This needs more testing.
That's because it's E_COMPILE_ERROR probably (FATAL ERROR)....

Thursday, March 10, 2016

Regenerate missing WP .htaccess

If your WP's .htaccess file is missing, you can simply regenerate it by re-saving Settings->Permalinks in WP-ADMIN.

Windows - don't forget that you can have hidden devices in your Device Manager

In Winodws 8/10 you can have malfunctioning devices in your Device Manager, which are not being shown when you go to CTRL+X/Device Manager.

You can enable showing those by choosing View -> Show Hidden Devices.

Tuesday, March 8, 2016

When PDO prepare() returns false

If your PDO::prepare() sets the connection object to false , that's probably because of the wrong query / params inside the prepare statement. It's another pretty silent error from PHP.

2 dangerous silent failures - IN PHP and JS

In PHP , PDO/MySQL can fail silently (with just a warning "MySQL has gone away"), after a connection timeout......


In JS, Promises (even RSVP ones) can eat your exceptions. You can fix this by adding a .catch() after .then() (in a chain). Otherwise, code stops at error, and the console is empty.

SILENT ERRORS - the worst nightmare of all programmers.

PSR-1 and PSR-2 coding standards for PHP

Visual aspects of code play a significant role in raising or drowning developer's productivity. In case that there's too much clutte...