Tuesday, December 11, 2018

Speed up Chrome

Google is also testing out new features for Chrome – some of which can speed up your browser.
You can access these by typing chrome://flags into the address bar. The ones which could prove beneficial are Enable fast tab/window close and Enable tab discarding. Find them both and click Enable.
Be warned, these are experimental so there are no guarantees they’ll work just yet. The good thing is, if you choose to enable them you can always switch them off later if you notice any problems.

Tuesday, November 06, 2018

Thursday, September 27, 2018

Monday, September 24, 2018

Dumping and importing from/to MySQL in an UTF-8 safe way

Dumping safely

# Do not do this, since it might screw up encoding
mysqldump -uroot -p database > utf8.dump # this is bad
Better do:
mysqldump -uroot -p database -r utf8.dump
Note that when your MySQL server is not set to UTF-8 you need to do mysqldump --default-character-set=latin1 (!) to get a correctly encoded dump. In that case you will also need to remove the SET NAMES='latin1' comment at the top of the dump, so the target machine won't change its UTF-8 charset when sourcing.
If you only want to dump the structure without data, use
mysqldump -uroot -p --no-data database -r utf8.dump

Importing a dump safely

# Do not do this, since it might screw up encoding
mysql -u username -p database < dump_file # this is bad
Better do:
mysql -uroot -p --default-character-set=utf8 database
mysql> SET names 'utf8'
mysql> SOURCE utf8.dump
https://makandracards.com/makandra

Saturday, September 22, 2018

Postman alternative

Free
Faster
No electron
https://github.com/RohitAwate/Everest

Java 8 for ubuntu18.04, Java SE 8 (LTS), Extended Support Until March 2025

sudo apt-get install oracle-java8-installer
sudo apt-get install oracle-java8-set-default
sudo update-alternatives --config java
sudo update-alternatives --config java
java -version
javac -version
At the end of this file, add the following line, making sure to replace the highlighted path with your own copied path:
sudo vim /etc/environment
JAVA_HOME="/usr/lib/jvm/java-8-oracle/jre/bin/java/"
echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle/jre/bin/java/

Thursday, September 20, 2018

Kill ssh sessions

ps -ef | grep sshd | grep -v root | grep -v 12345 | grep -v grep | awk '{print "sudo kill -9", $2}' |sh

Thursday, September 13, 2018

Search in gz and plain files recursively

reset;\
find -name \*.log -print0 | xargs -0 grep "delete from"; \
find -name \*.gz -print0 | xargs -0 zgrep "delete from";

Thursday, August 23, 2018

feednix

sudo apt-get install dh-autoreconf libjsoncpp-dev libcurl4-gnutls-dev libncurses5-dev w3m
git clone git@github.com:anders-dc/Feednix.git
cd Feednix
./configure && make && sudo make install 
  
 
{
    "colors" : { 

        /* ====== Color Definitions =======
         *  BLACK   0
         *  RED     1
         *  GREEN   2
         *  YELLOW  3
         *  BLUE    4
         *  MAGENTA 5
         *  CYAN    6
         *  WHITE   7
         * ================================ */

        "background" : 0,
        "active_panel" : 1,
        "idle_panel" : 6,
        "counter" : 5,
        "status_line" : 7,
        "instructions_line" : 4,
        "item_text" : 7,
        "item_highlight" : 2,
        "read_item" : 3
    },
    "ctg_win_width" : 40,
    //"view_win_height" : 200,
    "view_win_height_per" : 50,
    // Count of posts to be retrived per request. Maximum is 10000
    "posts_retrive_count" : "500",
    //Feedly API Allows for two sort types:
        // Newest(default) false 
        // Oldest true 
    "rank" : false,
    "preview_active" : true 
}

Tuesday, August 21, 2018

From assumptions to assertions


From assumptions to assertions

22nd July 2015

In your journey as a developer you not only develop applications, you also develop yourself. You and I both know there's more to developing than writing code that works, it's writing good code that works well. If you're like me then you probably started developing websites from scratch, later decided you wanted to build your own CMS and so on. In that stage as a developer you are usually very focused on getting stuff to work and not really on the unhappy paths.
As you continue to write code and continue to develop yourself you will eventually find yourself writing code like this, keep an eye on the is not null checks:
$lastOrder = null;

if ($user->getOrders()->count() > 0) {
    $orders = $this->filterByCompleted($user->getOrders());
    $lastOrder = $orders->last();
}

if ($lastOrder !== null) {
    if ($order->getBillingAddress() === null) {
        $order->setBillingAddress($lastOrder->getBillingAddress());
    }

    if ($order->getShippingAddress() === null) {
        $order->setShippingAddress($lastOrder->getShippingAddress());
    }
}
In the code above we retrieve the last order and use some information from there if it's missing in our current order (prefilling). Code like this is quite common and is sprinkled through most codebases I've worked with and contributed to. The problem with this code is that we're still making assumptions instead of assertions, just like we did back when we didn't check for unhappy paths at all and assumed all was good. The big cause of this are the is not null checks, they're a habit some of us have and it's not doing us as much good as we think it's doing.
Just to give you some insight, the $orders variable is of type Doctrine\Common\Collections\ArrayCollection and the last() functionactually uses PHP's end() function, if we check the documentation on that we can see that end() returns false when the array is empty. This may be something you already knew but this is not necessarily something you think about everytime you write code. With this in mind we can see that our code is flawed, it will run the if $lastOrder is not null check, pass and it will try to run $lastOrder->getBillingAddress() while $lastOrder is set to false. Our assumption was: "if $lastOrder is not null, it must be an object of type Order", just like we're assuming that $order->getBillingAddress()'s default value is null.
This brings me to the point of blacklisting vs whitelisting, I strongly believe we should be whitelisting in this case to turn assumptions into proper assertions. The above code could be rewritten as:
if ($lastOrder instanceof OrderInterface) {
    if (!$order->getBillingAddress() instanceof AddressInterface) {
        $order->setBillingAddress($lastOrder->getBillingAddress());
    }

    if (!$order->getShippingAddress() instanceof AddressInterface) {
        $order->setShippingAddress($lastOrder->getShippingAddress());
    }
}
This code clearly asserts that we're working with the right objects and there's no room for error. The nice thing is that PhpStorm picks up on this and will give you proper autocompletion (if it didn't already), this beats using /** @var Object $obj */.
Assert your expectations, don't assume

Original: https://rskuipers.com/entry/from-assumptions-to-assertions

Friday, June 29, 2018

How to configure PHPStorm to use PHP-CS-Fixer

Program: /usr/local/bin/php-cs-fixer
Arguments: fix $ProjectFileDir$/src --rules=@Symfony,line_ending,full_opening_tag,indentation_type --verbose --show-progress=dots
Working Directory: $ProjectFileDir$





Keymap


Click or search for Keymap in settings. Then in the keymap window find External Tools and then again External Tools and Then whatever you named your external tool we just configured. Double click your external tool or the green pencil at the top and select Add Keyboard Shortcut from the list. Then type a key combo (I use Alt+F) and hit OK, and then, hit OK again on settings.

Alt-Tab does not switch immediately in xfce

Yes, I noticed that too! I'm surprised they forgot something as important as that.
Install CompizConfig Settings Manager:
To open terminal hit Alt+Ctrl+T and run following commands:
sudo apt-get install compizconfig-settings-manager
Or search for compizconfig-settings-manager in Software Center and install from there.
Then go to System Tools > Preferences > CompizConfig, if you can't find System Tools, look for CompizConfig Settings Manager in Unity Dash.
Go at the very bottom where it says Windows Management
Put a check-mark in Application Switcher

Set Up PHP Coding Standards Fixer for Sublime Text 3

Set Up PHP Coding Standards Fixer for Sublime Text 3 on OS X

   Originally published at mariorodriguez.co on Apr 07, 2016

You can save yourself quite some time by running a simple command to automatically format your PHP/Laravel code to follow the PSR-1 and PSR-2 standards. Let me show you how you can set it all up to work with Sublime Text 3 on OS X.

Install php-cs-fixer

You must have at least PHP 5.3.6 on your system. Check with php --version.
Run the following commands to download php-cs-fixer:
cd ~/Downloads
wget http://get.sensiolabs.org/php-cs-fixer.phar -O php-cs-fixer
If you don’t have wget installed, follow these instructions to install it. Inspect this page so you can get the latest version.
or use curl:
curl http://get.sensiolabs.org/php-cs-fixer.phar -o php-cs-fixer
If you prefer a different download method such as composer or homebrew, check out these instructions.
Now that you’ve downloaded php-cs-fixer, make it executable:
sudo chmod a+x php-cs-fixer
Move it to a global location:
sudo mv php-cs-fixer /usr/local/bin/php-cs-fixer
Check that it works by running:
php-cs-fixer
If everything is fine, you should see the version and usage information.

Configure a Build Command in Sublime Text 3

  • Open Sublime Text
  • Got to Tools > Build System > New Build System…
  • Enter the following command and save:
{
    "shell_cmd": "php-cs-fixer fix $file --level=psr2"
}
That’s it. When you run this command, php-cs-fixer will apply psr-2 standards to the current file you have open.
Run the command by pressing Command + B.
Cheers!

Sunday, June 17, 2018

Solution” to Intel Graphics Screen Tearing/Flickering Causes Excessive Fan Use in Ubuntu 16.10/17.04/17.10

https://askubuntu.com/questions/945895/solution-to-intel-graphics-screen-tearing-flickering-causes-excessive-fan-use?noredirect=1&lq=1


sudo gedit /usr/share/X11/xorg.conf.d/20-intel-graphics.conf
Section "Device"
  Identifier  "Intel Graphics"
  Driver      "intel"
  Option      "TripleBuffer" "true"
  Option      "TearFree"     "true"
  Option      "DRI"          "false"
EndSection

Thursday, June 14, 2018

Tuesday, June 12, 2018

How can I find broken symlinks


find . -type l ! -exec test -e {} \; -print

Find and delete files recursively in unix

recursively list files by extension
find ./ -type f | awk -F . '{print $NF}' | sort --unique
recursively list files by specific extension
find . -type f -iname "*.css" 

recursively delete them
find . -name "*.html" -type f -delete

Monday, June 11, 2018

Docker wordpress

mkdir wordpress
cd wordpress

touch docker-compose.yml
vi docker-compose.yml

version: '3.3'

services:
   db:
     image: mysql:5.7
     ports:
       - "3306:3306"
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: wordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "80:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
volumes:
    db_data:



docker image prune --all
docker-compose restart
docker-compose build
docker-compose stop
docker-compose start
docker-compose up


sudo ufw enable
sudo ufw allow ssh
sudo ufw allow 80/tcp
sudo ufw allow 3306
sudo service ufw restart
sudo ufw status


Friday, May 18, 2018

Ubuntu open ports

Impossible to disable this...
sudo netstat -plunt

udp 3840 0 0.0.0.0:5353 0.0.0.0:* 24467/ --disk-cache

udp6    2304      0 :::5353                 :::*                                24467/ --disk-cache


chrome://flags/#device-discovery-notifications

chrome --disable-device-discovery-notifications

Thursday, May 10, 2018

steam on ubuntu 18.04

#steam on ubuntu 18.04
LD_PRELOAD='/usr/$LIB/libstdc++.so.6 /usr/$LIB/libgcc_s.so.1 /usr/$LIB/libxcb.so.1 /usr/$LIB/libgpg-error.so' /usr/bin/steam

Ubuntu 18.04 slow boot (apt-daily.service)

This service doesn't need to be in boot
Edit the timer for some time later

sudo systemctl edit apt-daily.timer

with this:
# apt-daily timer configuration override
[Timer]
OnBootSec=1d
OnUnitActiveSec=1d
AccuracySec=1h
RandomizedDelaySec=1d


To see if it works:
systemd-analyze blame


Tuesday, May 01, 2018

How to fix Apache 2 not executing PHP files

sudo a2dismod mpm_event && sudo a2enmod mpm_prefork && sudo a2enmod php7.2

MYSQL 5.7 ROOT LOGIN WITHOUT SUDO

Goal

TO BE ABLE TO LOGIN TO YOUR MYSQL 5.7+ SERVER AS ROOT WITHOUT SUDO

Description

This recipe is for people using MySQL locally for development that wants to use root user to access the database without a password and without the need to issue a sudo command to be able to access it.
Notice, however, that this recipe should not be used for production environments and, instead, you should use specific users with their own schema permissions for the applications you develop (e.g., if you are implementing an application named application1, maybe you should have a database schema named application1 and a user named application1 to access that schema)!

How to

As an important note before going through the steps of the recipe, I have to point out this post, from which this solution was originally inspired.
  1. Connect to MySQL with root:
    1
    $ > sudo mysql -uroot
  2. Check table user in schema mysql. In the resulting command, you should have a root/localhost result that you will have to change:
    1
    mysql > SELECT User, Host FROM mysql.user;
  3. Delete the user root for host localhost
    1
    mysql > DROP USER 'root'@'localhost';
  4. Recreate root user for host localhost:
    1
    mysql > CREATE USER 'root'@'localhost' IDENTIFIED BY '';
  5. Grant the necessary privileges to user root for localhost, including the flush privileges command, as follows:
    1
    2
    mysql > GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
    mysql > FLUSH PRIVILEGES;
  6. Exit mysql (either by inserting CTRL+D or quit in the MySQL command prompt) and try to reconnect with the following command:
    1
    $ > mysql -uroot

Explanations

MySQL 5.7 changed the security model: now, MySQL root login requires sudo (while the password can still be blank). The best solution now is to access MySQL through a new user with its own privileges, thus avoiding using root user for normal access.
However, and if you are a developer like myself, you probably don’t mind to use root to access your local database. If that is the case, then the steps provided within this recipe should do the trick.
Alternatively, you may (I would even say that his suggestion is a better alternative), simply change the authentication “algorithm” for root user, as such:
1
2
mysql > ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';
mysql > FLUSH PRIVILEGES;

How to revert comments Youtube layout?

#see video for details  https://www.youtube.com/watch?v=J0L_nYtNlqs #uBlock Origin  https://chrome.google.com/webstore/detail/ublock-o...