Sunday, September 3, 2017

Visual aspects of code play a significant role in raising or drowning developer's productivity. In case that there's too much clutter, no clear patterns and no lots of randomness in style, code reading can be difficult, and even stressful. This is why developers are constructing ways of dealing with the code complexity. They hope it can make everyday programming life easier. And I'd say they have the point. It really is important to have a clean, flowing, easy to read code.

One good example of such a coding standard is PSR-1, and it's extension PSR-2. Some of the rules of these standards are:

Saturday, August 12, 2017

If your app was written for older versions of MySQL and is not compatible with strict SQL mode in MySQL 5.7, you can disable strict SQL mode. For example, apps such as WHMCS 6 and Craft 2 do not support strict SQL mode.

If you're using WHMCS 7, see our article on customizing MySQL for WHMCS 7.
To disable strict SQL mode, SSH in to your server as root and create this file:

/etc/mysql/conf.d/disable_strict_mode.cnf
Open the file and enter these two lines:

Friday, August 4, 2017

If you are using npm inside of a Homestead box which is being hosted in Windows, and you see a "Exit status 1" error , or EIO error thrown by npm scripts, make sure that you have downloaded the npm packages inside of Homestead box, and not in Windows.

Apparently, there could be some differences in encoding / character set which can result in npm errors inside of Homestead box.

So, inside your Homestead box, remove the node_modules file and re-run npm install. Now you should be able to run npm scripts normally.

Sunday, July 23, 2017

I think the recommended way to recover that databases is start MySQL with innodb_force_recovery = 4 (or higher values) and dump the databases to a SQL.Then drop it and recover from backup. Instead of dropping the original database I prefer to create the new databases with another name or in another server and check the content first.

STEPS TO BE FOLLOWED

In mysqld section of my.cnf add a line innodb_force_recovery = 4 and then restart MySQL server using /etc/init.d/mysql restart.

Sunday, July 9, 2017

In ReactJS, the first obvious reason for componentWillReceiveProps() not firing is the use of mutable data. However, if that's not the case, you should always double check the form of your mapStateToProps() function.

Here, the first example works as expected, but the second one contains a logical, but not syntax error which can be a problem to find sometimes.

Friday, July 7, 2017

Super useful article about SPF records which got rejected by mail servers, although they look valid in validators ( it's all about hyphen sign, which looks similar , but it's not the same in validator and at the actual SPF record registry):

Friday, June 30, 2017

You are trying to run npm install on an existing git repository, but your npm install stops somewhere at fetchMetadata and throws an error code 128, which doesn't tell you much.

First of all, there are multiple possible causes for error code 128, most of them have something to do with permissions, so make sure you have access permissions and you're using proper ssh key(if any).

However, if that doesn't solve the problem, you might try this:
Try to split the package.json file's dependency list into N subgroups and run npm install on those chunks.

This way, it will download some packages every time, and it won't download them anymore when you run npm install for the next chunk.

I'm not sure what's root cause of this bug, but it seems to be a potential bug in npm v.5.0.0+. This needs some more research, but for the moment, I hope that the trick of splitting the npm install load will do the trick for you!

This was tested with node v8.0.0.0 and v8.1.3 with npm v5.0.0 and v5.1.3.
OS: Ubuntu 16.04
(nvm was used as the node manager, and the package.json contained both free and private git repos hosted at bitbucket and github).

UPDATE:
Possible reason for this error is the too high number of connections npm is trying to open. For some internet routers / connections, it might simply be too much. Currently, there's no official ability to limit max connections from npm, even there were some discussions on this in past. Lets hope this will be added into the newer versions.

Also, npm's error log is very bad at reporting the root cause of this error. In most cases, it simply says error code 128. However, every once in a while, it will print out something like Connection refused, or cannot connect to remote repository - host unknown, or something.

This error has a tendency to show up at large repos , filled with lots of git+ssh entries.

This issue might be somewhat related to this problem too:
https://github.com/npm/npm/issues/7862

Sunday, June 25, 2017

If you are experiencing missing Session Cookie while using NodeJS (and probably any other server side framework), remember that:

Your client and your server should be on exactly the same domain. For example, if client is set to http://127.0.0.1 and connecting to server at http://localhost, cookie won't be saved - Web Browser is going to reject it (rejects Set-Cookie command to protect your safety)

Sunday, June 18, 2017

In his superb book "Getting Things Done", David Allen introduced a phenomenal approach to creative project management. In one important section, he talks about natural order of thinking when looking to complete a non-trivial project. It is a powerful 5-step process:1. Why

You MUST have a super strong WHY, if you hope to ever complete a complex project. Nothing below makes sense without a very powerful WHY.
If there are problems on lower levels of this hierarchy , always go back and redefine your WHY.

2- Vision of successful outcome

See yourself after the success. Vividly. It opens up your subconscious eyes to see things you've ignored all the time.

3. Brainstorming
This is beginning of How part. Write down, draw down all things that come to your mind for which you believe that could potentially help you realize the successful outcome you envisioned in step #2.

Mind mapping by Tony Buzan can help here.
Make no judgement and no analysis at this step. Every idea is a good idea.

4.Organization

Connect the dots, isolate the processes, streamline actions. Make some Gantt charts if needed.

5. Next actions
Make concrete action plan and execute them. After execution, move to Next action and redo.
Reward yourself for every action completed - it's one step forward to your successful outcome, it's a big thing!

Also, written plan of next actions help us focus and maintain it for a longer period. Most of us cannot focus more than a couple of minutes to the task at hand, without a significant external motivation. This is why written plan of next actions, and the vision of whole project is really helpful - it makes us feel more control over the project and increases our confidence in the whole project.

These tips are about Vagrant on Windows, coupled with NFS using VirtualBox NFS plugin.

#1 If Vagrant ssh terminal is getting stuck
If your Vagrant ssh terminal is getting stuck all the time, check if you have multiple running vagrants:
vagrant global-status
and then halt / destroy them by id.

#2 If Vagrant VM is slow
Any wrong flag or option in Vagrantfile shared folder settings can degrade your VM's performance by 10x! For example, this is a valid synced folder entry for windows host using NFS:

config.vm.synced_folder ".", "/vagrant", type: "nfs"

Be careful when modifying this basic line, as any extra option can be the cause of slowliness of your VM.

Wednesday, June 14, 2017

We all run dozens of programs running simultaneously. We all use ALT-TAB to quickly jump between those programs. ALT-TAB looks like a time saver. And it probably is. On the other side, we never consider a potential downside of using this, and other similar, keyboard shortcuts:

Pressing ALT-TAB will bring a new program to our screen instantly. Computer has no problems with fast context switching. But what about us - human beings? I'm not entirely convinced that we can do a quick context switch, without sacrificing our current thoughts.

Here is my challenge for you:

Can you try to avoid using ALT + TAB for 1 whole week. If you succeed at it, let us know how it felt? Has your productivity soared, jumped a little bit, or degraded?

I'm sure that there are some productivity awards for those who can endure this challenge. :)

Tuesday, May 30, 2017

In Android native development, when using TextView's setText() function, one needs to be careful to use a proper overloaded version.

For example, if you provide a string as the first and only parameter of this function, it will set the label of the component to that string. This is usually what developer wants.

However, if you provde an integer as parameter, then setText() will search for a resource with corresponding Resource ID. It won't simply convert to string and display that value. If the resource is not found, it will throw the following error:

You try to deploy your Android for debugging to a Genymotion virtual phone. Eclipse ADT doesn't react to that action. In the bottom right corner you can see "Android SDK Loader" and nothing like "Launching YOUR APP NAME".

What can be wrong?

Check this:

Make sure your adb is connected to the phone.

If it is, then go to Genymotion window, click inside of it, and press ESC on keyboard, to awake it from sleep. That usually helps. Try to re-run (re-deploy) your app from Eclipse ADT again.

Monday, May 29, 2017

Here are a few very important reminders for ReactJS CSS3 animations using ReactCSSTransitionGroup:

1. Your ReactCSSTransitionGroup should be mounted (rendered) before the content that should be dynamically changed.
This means that ReactCSSTransitionGroup and it's child element(s) must not appear at the same action. For example, if both ReactCSSTransitionGroup and it's child element get mounted at the time when property prop1 gets changed, your animation won't work.

So, child elements need to be mounted later then their parent ReactCSSTransitionGroup.

2. Any change of the child elements visibility must come with it's own unique key. If the child elements have no unique keys, the animations won't appear at all!

Monday, May 22, 2017

If your WP Admin replies with http error code 403, and an error message like this:
"Sorry, you are not allowed to access this page"
,
and if you cannot find out the cause for this, check the url you are trying to access. Maybe it is not valid.

In example, this url will generate HTTP status 403:
http://localhost/wptest1/wp-admin/admin.php?page=run-connector?a=3

This will be ok:
http://localhost/wptest1/wp-admin/admin.php?page=run-connector&a=3

Saturday, April 29, 2017

Over the past few weeks we opened our discussion of machine learning and neural networks with an introduction to linear classification that discussed the concept of parameterized learning, and how this type of learning enables us to define a scoring function that maps our input data to output class labels.

This scoring function is defined in terms of parameters; specifically, our weight matrix W and our bias vector b. Our scoring function accepts these parameters as inputs and returns a predicted class label for each input data point .

From there, we discussed two common loss functions: Multi-class SVM loss and cross-entropy loss (commonly referred to in the same breath as “Softmax classifiers”). Loss functions, at the most basic level, are used to quantify how “good” or “bad” a given predictor (i.e., a set of parameters) are at classifying the input data points in our dataset.

Given these building blocks, we can now move on to arguably the most important aspect of machine learning, neural networks, and deep learning — optimization.

Throughout this discussion we’ve learned that high classification accuracy is dependent on finding a set of weights W such that our data points are correctly classified. Given W, can compute our output class labels via our scoring function. And finally, we can determine how good/poor our classifications are given some W via our loss function.

But how do we go about finding and obtaining a weight matrix W that obtains high classification accuracy?

Do we randomly initialize W, evaluate, and repeat over and over again, hoping that at some point we land on a W that obtains reasonable classification accuracy?

Well we could — and it some cases that might work just fine.

But in most situations, we instead need to define an optimization algorithm that allows us to iteratively improve our weight matrix W.

In today’s blog post, we’ll be looking at arguably the most common algorithm used to find optimal values of W — gradient descent.

Tuesday, April 11, 2017

If you need to update your php version , just dowload PHP executable and save it to a folder. Add that folder to PATH and make sure it's the first php.exe in the PATH's folder list.
Rename php.ini.development to php.ini and uncomment the extension you need. You will need mbstring and openssl for sure (otherwise composer update will fail).

Sunday, March 26, 2017

React Redux state is changed. However, the component which listens for state changes does not receive a call to componentWillReceiveProps().

Possible cause:

State should be an immutable object. Updates to it should be made by assigning new objects to its properties, not by modifying current properties like mutable objects. You might be passing the same object ( just modified) as the new updated state.

Solution:
Make sure your state is updated by adding a new object, not just by a modification of an existing state object. If you pass the same old object ( by reference), redux won't detect it as a change. This was done to ensure that we use immutable objects for state.

Thursday, March 16, 2017

You issue multiple AJAX requests to your ASP.NET (or any other similar Web Server). In Inspector Console, your requests are fired at the same time. However, it appears that one is starting to execute only after one request is finished.

Probable explanation:

Locking at the server side is the probable reason for this behavior. For example, if all your server side scripts access Session object, they need to wait in a queue for Session to become available. Session becomes available only when one of the simultaneous requests is finished. This is why it appears as a serial execution.

One easy workaround:
If you can , declare your ASP.NET MVC controller / page as readonly when it comes to accessing the Session object.

From the Stack Overflow thread:

Session is blocking access to other ones.

This is because session is single threaded per session. Requests to ASP scripts for the same session can only be processed sequentially so only one request will be handled at a time. To stop this you will need to stop using session on the page and turn it off: http://support.microsoft.com/kb/244465/en-us. If you need session you may need to instead use a database.

Sunday, March 12, 2017

In this post, I would like to make a few simple examples showing the way JavaScript handles the standard programming language features - pass by reference and pass by value.

A very good summation of JS behavior in this area is given here at StackOverflow post:

Javascript is always pass by value, but when a variable refers to an object (including arrays), the "value" is a reference to the object.

Changing the value of a variable never changes the underlying primitive or object, it just points the variable to a new primitive or object.

However, changing a property of an object referenced by a variable does change the underlying object.

Based on these facts, we can easily resolve the following simple operation:

var a=12;
a=13;
b=a;
b=14;
document.write("A="+a+"<br/>");
document.write("B="+b);
/*
since a and b are primitive types:
a is now 13
b is now 14
*/

Here is a Fiddle of a more complex scenario. This scenario shows an example of dealing with objects and arrays. It's clear that that in case of assignment operation with objects, the JS will behave as any other language which uses "pass by reference":

I wonder if you can see, now that it's the container [1] that knows about redux and dispatch and store and state and ... stuff.

The component in the pattern, FancyAlerter, which does the rendering doesn't need to know about any of that stuff: it gets its method to call at onClick of the button, via its props.

And ... mapDispatchToProps was the useful means that redux provides to let the container easily pass that function into the wrapped component on its props.

All this looks very like the todo example in docs, and another answer here, but I have tried to cast it in the light of the pattern to emphasize why.

(Note: you can't use mapStateToProps for the same purpose as mapDispatchToProps for the basic reason that you don't have access to dispatch inside mapStateToProp. So you couldn't use mapStateToProps to give the wrapped component a method that uses dispatch.

I don't know why they chose to break it into two mapping functions - it might have been tidier to have mapToProps(state, dispatch, props) IE one function to do both!)