Friday 7 October 2016

Android - libGL error: unable to load driver: nouveau_dri.so

Hello,

This is the error you might see:
  • Cannot launch AVD in emulator.
    Output:
    libGL error: unable to load driver: nouveau_dri.so
    libGL error: driver pointer missing
    libGL error: failed to load driver: nouveau
    libGL error: unable to load driver: swrast_dri.so
    libGL error: failed to load driver: swrast
    X Error of failed request:  GLXBadContext
      Major opcode of failed request:  155 (GLX)
      Minor opcode of failed request:  6 (X_GLXIsDirect)
      Serial number of failed request:  49
      Current serial number in output stream:  48
    libGL error: unable to load driver: nouveau_dri.so
    libGL error: driver pointer missing
    libGL error: failed to load driver: nouveau
    libGL error: unable to load driver: swrast_dri.so
    libGL error: failed to load driver: swrast
    X Error of failed request:  GLXBadContext
      Major opcode of failed request:  155 (GLX)
      Minor opcode of failed request:  6 (X_GLXIsDirect)
      Serial number of failed request:  49
      Current serial number in output stream:  48

Here is how to resolve it:
  1. sudo apt-get install lib64stdc++6 (if it is not installed)
  2. cd ~/Android/Sdk/tools/lib64/libstdc++
  3. mv libstdc++.so.6 libstdc++.so.6.original
  4. ln -s /usr/lib64/libstdc++.so.6 ~/Android/Sdk/tools/lib64/libstdc++
  5. sudo apt-get install mesa-utils (if it is not installed)

Source: http://android.stackexchange.com/questions/145437/reinstall-avd-on-ubuntu-16-04

Good luck!

Thursday 29 September 2016

Magento 2 - Owl Carousel makes wrapper a few thousand pixels wide at 767px and below

Hi,

We can solve this issue by multiple way:

  • http://magento.stackexchange.com/questions/105638/owl-carousel-magento-2-not-fully-responsive
    • .columns .column.main {
          overflow: hidden;
      }
      
    • Or
    • .columns .column.main {
          width: 100%;
      }
      
  • Another solution I found:
    • .columns {
          display: block;
      }
      

Good luck!

Wednesday 10 August 2016

Ubuntu - ReactJS with Hot Loader Installation

Hi there,

This is an example for ReactJS with Hot Loader:

  1. You must have NodeJS installed:
    • https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
  2. Running these commands:
    • npm init
    • npm install -S express lodash react react-dom
    • npm install babel-core babel-loader babel-preset-es2015 babel-preset-react react-hot-loader webpack webpack-dev-server --save-dev
    • npm install -g webpack webpack-dev-server
  3. Create webpack-dev-server global command in case it not works:
    • Create bash file bash.sh:
      • #!/bin/bash
        
        path=$(readlink -f .)
        path="$path/node_modules/.bin/webpack-dev-server"
        
        sudo ln -s $path /usr/local/bin
        echo "DONE!";
        
    • sudo bash.sh
  4. Create webpack.config.js file:
    • var webpack = require('webpack');
      var path = require('path');
      
      module.exports = {
          devtool: 'inline-source-map',
          entry: [
              'webpack-dev-server/client?http://127.0.0.1:8080/',
              'webpack/hot/only-dev-server',
              './src'
          ],
          output: {
              path: path.join(__dirname, 'public/build'),
              filename: 'bundle.js',
              sourceMapFilename: 'bundle.map',
              publicPath: '/'
          },
          resolve: {
              modulesDirectories: ['node_modules', 'src'],
              extensions: ['', '.js']
          },
          module: {
              loaders: [
              {
                  test: /\.jsx?$/,
                  exclude: /node_modules/,
                  loaders: ['react-hot', 'babel?presets[]=react,presets[]=es2015']
              }
              ]
          },
          plugins: [
              new webpack.HotModuleReplacementPlugin(),
              new webpack.NoErrorsPlugin()
          ],
          devServer: {
              contentBase: "./public",
              hot: true
          }
      };
      
  5. Create index.html file:
    • <html>
          <head>
              <title>React</title>
          </head>
          <body>
              <div id="app"></div>
      
              <script src="build/bundle.js"></script>
          </body>
      </html>
      
  6. Create index.js file:
    • import React from 'react';
      import { render } from 'react-dom';
      import App from 'components/app';
      
      render(<App />, document.getElementById('app'));
      
  7. Create app.js file:
    • import React from 'react';
      
      export default class App extends React.Component {
          render() {
              return (
                  <div>
                      <h1>Hello world!</h1>
                  </div>
              );
          }
      }
      
  8. At the end, you might have a directory tree like this:
  9. Rebuild:
    • webpack
  10. Run server:
    • webpack-dev-server
    • or
    • node_modules/.bin/webpack-dev-server
  11. Open web browser:
    • http://localhost:8080/

Good luck!

Thursday 4 August 2016

Magento - Installation

Hello,

I got these issues when trying to setup Magento in my local machine using Nginx:
  1. Magento 2.x:
    •  Cannot instantiate interface
      • FastCGI sent in stderr: "PHP message: PHP Fatal error:  Cannot instantiate interface Magento\Framework\App\Config\Scope\ReaderPoolInterface in /xxx/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php on line 73" while reading response header from upstream, client: 127.0.0.1, server: my-magento.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php5.6-fpm.sock:", host: "my-magento.com"
      • Modify the sample nginx config file you have been included in your virtual host:
        • From:
          • location ~* ^/setup($|/) {
        • To:
          • location /setup {
    • security.limit_extensions
      • "Access to the script '/xxx/setup/index.php/session/prolong' has been denied (see security.limit_extensions)"
        • Change
          • cgi.fix_pathinfo=0
        • To:
          • cgi.fix_pathinfo=1
  2. Magento 1.x:
    • Nginx:
      • Virtual host file:
        • location ~ .php/ {
           rewrite ^(.*.php)/ $1 last;
          }
          

Good luck!

Wednesday 3 August 2016

Ubuntu - Swap between PHP 5.5, 5.6 and 7.0

Hello,

This is tutorial how we can do it:
  1. Install PHP 5.5:
    • sudo apt-get install -y php5
  2. Install PHP 5.6:
    • sudo add-apt-repository ppa:ondrej/php
      • In some case, you will need to change Ubuntu codename in this file:
        • sudo vim /etc/apt/sources.list.d/ondrej-ubuntu-php-xenial.list
    •  sudo apt-get update
    • sudo apt-get install -y php5.6
  3. Install PHP 7.0:
    • sudo apt-get install -y php7.0
  4.   Create symlink in your .bashrc file for quick access:
    • vim ~/.bashrc
    • Apache2:
      • #################################################
        ############### PHP Version Toggle ##############
        #################################################
        # Remove the -q to see debugging information if there are problems
        alias enphp5.5="
         sudo a2dismod php5.6 -q;
         sudo a2dismod php7.0 -q;
         sudo a2enmod php5 -q;
         sudo ln -sf /usr/bin/php5 /usr/bin/php;
         sudo service apache2 restart"
        alias enphp5.6="
         sudo a2dismod php5 -q;
         sudo a2dismod php7.0 -q;
         sudo a2enmod php5.6 -q;
         sudo ln -sf /usr/bin/php5.6 /usr/bin/php;
         sudo service apache2 restart"
        alias enphp7.0="
         sudo a2dismod php5 -q;
         sudo a2dismod php5.6 -q;
         sudo a2enmod php7.0 -q;
         sudo ln -sf /usr/bin/php7.0 /usr/bin/php;
         sudo service apache2 restart"
        
    • Nginx:
      • Remove apache2:
        • sudo service apache2 stop
        • sudo apt-get remove apache2*
        • sudo apt-get purge apache2
      • Install php-fpm for all versions
        • sudo apt-get install php5-fpm
        • sudo apt-get install php5.6-fpm
        • sudo apt-get install php7.0-fpm
      • Stop all php-fpm:
        • sudo service php5-fpm stop
        • sudo service php5.6-fpm stop
        • sudo service php7.0-fpm stop
      • #################################################
        ############### PHP Version Toggle ##############
        #################################################
        # Remove the -q to see debugging information if there are problems
        alias enphp5.5="
         sudo ln -sf /usr/bin/php5 /usr/bin/php;
         sudo service php5.6-fpm stop;
         sudo service php7.0-fpm stop;
         sudo service php5-fpm start;
         sudo find /etc/nginx/sites-available -type f -exec sed -i 's,/run/php/php5.6-fpm.sock,/var/run/php5-fpm.sock,g;s,/run/php/php7.0-fpm.sock,/var/run/php5-fpm.sock,g' {} \;
         sudo service nginx restart"
        alias enphp5.6="
         sudo ln -sf /usr/bin/php5.6 /usr/bin/php;
         sudo service php5-fpm stop;
         sudo service php7.0-fpm stop;
         sudo service php5.6-fpm start;
         sudo find /etc/nginx/sites-available -type f -exec sed -i 's,/var/run/php5-fpm.sock,/run/php/php5.6-fpm.sock,g;s,/run/php/php7.0-fpm.sock,/run/php/php5.6-fpm.sock,g' {} \;
         sudo service nginx restart"
        alias enphp7.0="
         sudo ln -sf /usr/bin/php7.0 /usr/bin/php;
         sudo service php5-fpm stop;
         sudo service php5.6-fpm stop;
         sudo service php7.0-fpm start;
         sudo find /etc/nginx/sites-available -type f -exec sed -i 's,/var/run/php5-fpm.sock,/run/php/php7.0-fpm.sock,g;s,/run/php/php5.6-fpm.sock,/run/php/php7.0-fpm.sock,' {} \;
         sudo service nginx restart"
        
  5. Reload your new .bashrc commands:
    • source ~/.bashrc
  6. Done, now you can try it with:
    • enphp5.5
    • php -v
    • enphp5.6
    • php -v
    • enphp7.0
    • php -v

Good luck!
Source: https://github.com/JREAM/phalcon-xenial

Friday 29 July 2016

Android - Websocket

Hi,

This is tutorial how to integrate WebSocket with Android. We need 3 different files:
  1. WebSocketTask.java
    • import android.content.Context;
      import android.os.AsyncTask;
      import android.util.Log;
      
      import org.java_websocket.client.WebSocketClient;
      import org.java_websocket.handshake.ServerHandshake;
      import org.json.JSONException;
      import org.json.JSONObject;
      
      import java.net.URI;
      import java.net.URISyntaxException;
      import java.util.concurrent.ExecutionException;
      
      public class WebSocketTask extends AsyncTask {
          public boolean isConnected = false;
      
          private WebSocketClient webSocketClient;
          private ICallback iCallback;
      
          public WebSocketTask(Context context) {
              this.iCallback = (ICallback) context;
          }
      
          @Override    protected WebSocketClient doInBackground(String... params) {
              final String channel = params[0];
              URI uri;
      
              try {
                  uri = new URI("ws://your-websocket-server.com");
              } catch (URISyntaxException e) {
                  e.printStackTrace();
                  return null;
              }
      
              webSocketClient = new WebSocketClient(uri) {
                  @Override            public void onOpen(ServerHandshake serverHandshake) {
                      isConnected = true;
      
                      JSONObject message = new JSONObject();
                      try {
                          message.put("channel", channel);
                          message.put("subscribe", true);
                      } catch (JSONException e) {
                          e.printStackTrace();
                      }
                      webSocketClient.send(message.toString());
                  }
      
                  @Override            public void onMessage(String s) {
                      try {
                          JSONObject data = new JSONObject(s);
      
                          if (data.has("channel")) {
                              iCallback.webSocketCallback(data);
                          }
                      } catch (JSONException e) {
                          e.printStackTrace();
                      } catch (InterruptedException e) {
                          e.printStackTrace();
                      } catch (ExecutionException e) {
                          e.printStackTrace();
                      }
                  @Override            public void onClose(int i, String s, boolean b) {
                      Log.i("Websocket", "Closed " + s);
                  }
      
                  @Override            public void onError(Exception e) {
                      Log.i("Websocket", "Error " + e.getMessage());
                  }
              };
              webSocketClient.connect();
      
              return webSocketClient;
          }
      
          public void sendMessage(WebSocketClient client, String channel, JSONObject message) throws JSONException {
              JSONObject data = new JSONObject();
      
              data.put("channel", channel);
              data.put("data", message);
      
              client.send(data.toString());
          }
      }
      
  2. ICallback.java
    • import org.json.JSONException;
      import org.json.JSONObject;
      
      import java.util.concurrent.ExecutionException;
      
      public interface ICallback {
          void webSocketCallback(JSONObject data) throws JSONException, ExecutionException, InterruptedException;
      }
      
  3. MainActivity.java
    • import android.os.Bundle;
      import android.os.Handler;
      import android.support.v7.app.AppCompatActivity;
      import android.util.Log;
      
      import org.java_websocket.client.WebSocketClient;
      import org.json.JSONException;
      import org.json.JSONObject;
      
      import java.util.concurrent.ExecutionException;
      
      public class MainActivity extends AppCompatActivity implements ICallback {
      
          WebSocketTask webSocketTask;
          WebSocketClient webSocketBattleChannel;
      
          String myChannelKey = "my-channel";
      
          @Override
          protected void onDestroy() {
              super.onDestroy();
      
              webSocketTask.cancel(true);
          }
      
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
      
              // New websocket task
              webSocketTask = new WebSocketTask(this);
              try {
                  // Connect to websocket channel
                  webSocketBattleChannel = webSocketTask.execute(myChannelKey).get();
              } catch (InterruptedException e) {
                  e.printStackTrace();
              } catch (ExecutionException e) {
                  e.printStackTrace();
              }
          }
      
          // Send message to other users
          private void sendMessage(JSONObject data, boolean isDoubleSend) throws JSONException {
              final JSONObject message = data;
      
              // Check the websocket connection
              if (webSocketTask.isConnected) {
                  webSocketTask.sendMessage(webSocketBattleChannel, myChannelKey, message);
              }
      
              // Try to double send in some case of connection lost
              if (webSocketTask.isConnected && isDoubleSend) {
                  Handler handler = new Handler();
                  handler.postDelayed(new Runnable() {
                      public void run() {
                          try {
                              webSocketTask.sendMessage(webSocketBattleChannel, myChannelKey, message);
                          } catch (JSONException e) {
                              e.printStackTrace();
                          }
                      }
                  }, 1000);
              }
          }
      
          // Listen to other users send message
          @Override
          public void webSocketCallback(JSONObject message) throws JSONException {
              // Get data in the message
              final JSONObject data = message.getJSONObject("data");
      
              // To make sure we can modify view
              runOnUiThread(new Runnable() {
                  @Override
                  public void run() {
                      Log.d("WebSocket", data.toString());
                  }
              });
          }
      }
      

Done. We simply use it by 2 functions:
  1. sendMessage:
    • Send message to who listen to channel: my-channel
  2. webSocketCallback:
    • Listen to channel: my-channel
Good luck!

Sunday 20 December 2015

Restoring Large MySQL Dump

Hello,

This is tutorial how to restore your Database:
  1. Create dump file:
    • mysqldump -uroot -ppassword dbname > dbname_backup.sql
  2. Split dump file:
    • mkdir splits
    • split -n 1000 dbname_backup.sql splits/sql
  3. Create new database: dbname_clone
  4. Restore database:
    • cd splits
    • cat sql* | mysql -uroot -ppassword dbname_clone
Good luck!