mercoledì 21 agosto 2019

martedì 12 febbraio 2019

Windows 10 keyboard shortcuts

Keyboard shortcut Action
Windows key Open or close Start Menu.
Windows key + A Open Action center.
Windows key + C Open Cortana in listening mode.
Windows key + D Display and hide the desktop.
Windows key + E Open File Explorer.
Windows key + G Open Game bar when a game is open.
Windows key + H Open the Share charm.
Windows key + I Open Settings.
Windows key + K Open the Connect quick action.
Windows key + L Lock your PC or switch accounts.
Windows key + M Minimize all windows.
Windows key + R Open Run dialog box.
Windows key + S Open Search.
Windows key + U Open Ease of Access Center.
Windows key + X Open Quick Link menu.
Windows key + Number Open the app pinned to the taskbar in the position indicated by the number.
Windows key + Left arrow key Snap app windows left.
Windows key + Right arrow key Snap app windows right.
Windows key + Up arrow key Maximize app windows.
Windows key + Down arrow key Minimize app windows.
Windows key + Comma Temporarily peek at the desktop.
Windows key + Ctrl +D Add a virtual desktop.
Windows key + Ctrl + Left or Right arrow Switch between virtual desktops.
Windows key + Ctrl + F4 Close current virtual desktop.
Windows key + Enter Open Narrator.
Windows key + Home Minimize all but the active desktop window (restores all windows on second stroke).
Windows key + PrtScn Capture a screenshot and save in Screenshots folder.
Windows key + Shift + Up arrow Stretch the desktop window to the top and bottom of the screen.
Windows key + Tab Open Task view.
Windows key + "+" key Zoom in using the magnifier.
Windows key + "-" key Zoom out using the magnifier.
Ctrl + Shift + Esc Open Task Manager.
Alt + Tab Switch between open apps.
Alt + Left arrow key Go back.
Alt + Right arrow key Go foward.
Alt + Page Up Move up one screen.
Alt + Page down Move down one screen.
Ctrl + Alt +Tab View open apps
Ctrl + C Copy selected items to clipboard.
Ctrl + X Cut selected items.
Ctrl + V Paste content from clipboard.
Ctrl + A Select all content.
Ctrl + Z Undo an action.
Ctrl + Y Redo an action.
Ctrl + D Delete the selected item and move it to the Recycle Bin.
Ctrl + Esc Open the Start Menu.
Ctrl + Shift Switch the keyboard layout.
Ctrl + Shift + Esc Open Task Manager.
Ctrl + F4 Close the active window.

martedì 16 ottobre 2018

10 Twig tips

Simply an interesting article sharing 10 Twig tips.

lunedì 17 settembre 2018

My technology sites list

A group of sites sharing interesting articles for developers. Other sites along the way.

Let's start:
- https://hackernoon.com
- https://flaviocopes.com
- https://www.howtogeek.com
- https://codeburst.io

giovedì 13 settembre 2018

How to Create Symbolic Links in Windows 10

You need to open "command prompt" (not "power shell") as administrator and then you can easily do it by "mklink" command.
To find "command prompt" icon you can use Cortana and then click right bottom mouse and select command prompt (admin)

Files symbolic link

Grammar
mklink Link Target

Example
mklink "E.\path\symbolic_link.txt" "E.\path\real_file.txt"

Directory symbolic link

Grammar
mklink /D Link Target

Example
mklink /d "E.\path\symbolic_link" "E.\path\real_folder"

Ref:
https://www.maketecheasier.com/create-symbolic-links-windows10/

sabato 16 giugno 2018

Relations between models


Relations between models are a fundamental topic in ORM and a key knowledge in coding and is not easy to find good explanations.

Here it is some good articles about it:

Relation Many to Many
Pivot tables and many-to-many relationships

domenica 13 maggio 2018

Reset user password in Linux Bash on Windows 10

  1. edit file (in notepad or notepad++):
    %localappdata%\lxss\rootfs\etc\shadow
    
  2. find your normal user, for example:
    user1:$jsdjksadgfhsdf.saflsdf.sadf.safd:17299:0:99999:7:::
    
    and simply remove the hash part (below part)
    $jsdjksadgfhsdf.saflsdf.sadf.safd
    
    you will see a different hash - I hope :), so should look like:
    user1::17299:0:99999:7:::
    
  3. Save the file
  4. start bash again
  5. sudo bash
  6. password this will ask for your new password without requiring previous one.

sabato 3 febbraio 2018

Which linux version we have to do with?

Here is a memo to find it:

Check linux kernel version number

Open a shell prompt and type the following command to see your current Linux kernel version:

$ uname -a

Sample outputs:
Linux vivek-laptop 2.6.32-23-generic-pae #37-Ubuntu SMP Fri Jun 11 09:26:55 UTC 2010 i686 GNU/Linux
Where:
- 2.6.32-23 – Linux kernel version number
- pae – pae kernel type indicate that I’m accssing more than 4GB ram using 32 bit kernel.
- SMP – Kernel that supports multi core and multiple cpus.

/proc/version file

Type the following command to see Linux version info:

$ cat /proc/version

Sample outputs:
Linux version 3.2.0-0.bpo.1-amd64 (Debian 3.2.4-1~bpo60+1) (ben@decadent.org.uk) (gcc version 4.4.5 (Debian 4.4.5-8) ) #1 SMP Sat Feb 11 08:41:32 UTC 2012
The above output identifies the kernel version that is currently running.

Find Distribution Version

Type the following command:

$ cat /etc/*release

OR

$ lsb_release -a

Sample outputs:

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 10.04 LTS
Release: 10.04
Codename: lucid

Rif: 
https://www.cyberciti.biz/faq/command-to-show-linux-version/

Some resources about Eloquent ORM


Here the links:

venerdì 8 dicembre 2017

Can you store password in Putty sessions?

The short answer is no. But you have a workaround that can help you to reach the same result: a one-click Putty shortcut to your server from your desktop.
That's the issue of this article.

Here is how to do:

  1. Create on the desktop a shortcut to Putty.exe
  2. Right click on the shortcut, select "properties" and edit the target attribute
  3. Change
    "C:\ProgramFiles\putty.exe"
    in
    "C:\ProgramFiles\putty.exe" root@207.150.12.233 -pw YourPassword
    where
    "C:\ProgramFiles\putty.exe" is the correct path of your putty.exe file
    "root" to the user you would use to login to your remote server
    "207.150.12.233" is the remote server IP
    "YourPassword" is the correct password.
  4. Click "Apply" then "OK" to commit the change.

Now simply double-click on your new shortcut and you'll be logged on your server.

domenica 26 novembre 2017

Eloquent collections methods

The Eloquent ORM provides a beautiful, simple ActiveRecord implementation for working with your database.
The results of Eloquent queries are always returned as Collection instances and Eloquent has a list of methods to work with Collections.

Here it is an interesting article about 10 less-known Eloquent collections methods:
avg()
chunk()
contains()
every()
filter()
forget()
implode()
keyBy()
map()
plunk()

Howto preview sql query code generated in Eloquent

The simplest method to show the query generated by Eloquent is by utilizing a ->toSql() method.
We only need to replace the closing ->get() with ->toSql() and then print out the results with dd() or die() funnction.

Here is an example:

    
    $users = DB::table('users')
        ->where('email', 'x@y.xxx')
        ->where('is_active', true)
        ->toSql();
//        ->get();
    dd($users);

This is the output:

"select * from `users` where `name` = ? and `is_active` = ?"

A little more complex and complete way is to enable and use the QueryLog method.

Here the example:

    DB::enableQueryLog();
    $users = DB::table('users')
    ->where('email', 'x@y.xxx')
    ->get();

    dd(DB::getQueryLog());

This is the output:

array:1 [
  0 => array:3 [
    "query" => "select * from `users` where `email` = ?"
    "bindings" => array:1 [
      0 => "x@y.xxx"
    ]
    "time" => 61.13
  ]
]

domenica 12 novembre 2017

Linux commands and tools for networking and sysadmin

I 20 comandi indispensabili per un amministratore di sistema.
20 Linux commands every sysadmin should know

Comandi e tools linux interessanti per il networking.
https://itsubuntu.com/linux-networking-commands-and-scripts/

lunedì 17 luglio 2017

Ricerca in VIM

Comandi per ricercare una stringa in un file con l'editor VIM:

/ + ENTER

Per passare all'occorrenza successiva premere "n"
Per passare all'occorrenza precedente premere "N"

venerdì 30 giugno 2017

Aumentare la dimensione massima di file caricabili sul server in post

Occorre intervenire su sulla configurazione di PHP e sul web server.
Ipotizziamo di utilizzare un macchina Ubuntu 16.04 con PHP 7.0 e web server nginx.
Per quanto riguarda php occorre modificare nel file php.ini i valori dei parametri

upload_max_filesize
post_max_size

Per quanto riguarda il server web, ipotizzando di utilizzare nginx,

  • in caso di modifica per tutto il server occorre modificare il file nginx.conf inserendo il valore client_max_body_size nel blocco http
  • in caso di modifica per un solo dominio occorre modificare il file di configurazione del dominio (/etc/nginx/sites-avalible/.conf) inserendo la stesso stringa nel blocco server

In caso di file di dimensioni particolarmente elevate occorre intervenire anche sul tempo massimo di durata dello script sia in PHP che in nginx

Finite le modifiche ricordarsi di riavviare PHP e nginx

sudo service php7.0-fpm restart
sudo service nginx restart

Riferimenti 

  • https://easyengine.io/tutorials/php/increase-file-upload-size-limit/
  • https://easyengine.io/tutorials/php/increase-script-execution-time/

giovedì 1 giugno 2017

Bloccare l'accesso dei BOT al sito


Questa la procedura migliore che ho trovato assemblando varie indicazioni trovate in rete:

1. Rilevare gli user-agent che hanno avuto accesso al server ordinandoli per numerosità di accessi interroganto il file access.log
cat access.log | awk -F\" '{print $6}' | sort | uniq -c | sort -n

2. Inserire degli user-agent dei bot nel file robots.txt con indicazione di blocco:
User-agent:
Disallow: /

3. Inserire la condizione di blocco nel file .htaccess
Condizione per il singolo user-agent:
  RewriteEngine on
  RewriteCond %{HTTP_USER_AGENT} Twitterbot [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} Baiduspider [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ApacheBench [NC]
  RewriteRule .* - [F,L]

Condizione per più user-agent:
  RewriteCond %{HTTP_USER_AGENT} ^(Twitterbot|Baiduspider|ApacheBench) [NC]
  RewriteRule .* - [F,L]

4. Inserire il blocco dell'ip del bot nel file htaccess
 deny aaa.bbb.ccc.ddd

Per un approccio più esteso considerare di trasferire il sito sotto Cloudflare

Riferimenti
- https://ma.ttias.be/block-user-agent-in-htaccess-for-apache-webserver/
- http://www.blogtips.org/web-crawlers-love-the-good-but-kill-the-bad-and-the-ugly/
- https://support.hypernode.com/knowledgebase/fixing-bad-performance-caused-by-search-engines/

Script time evaluation in PHP

Piccolo promemoria del codice per valutare il tempo di esecuzione di uno script:

Registro l'inizio
$time_start = microtime(true);

Eseguo lo script script
...

Registro la fine
$time_end = microtime(true);

Calcolo la durata
$execution_time = ($time_end - $time_start);          

La stampo
echo 'Total Execution Time: '.$execution_time.' Secs'; //execution time of the cicle in seconds


martedì 30 maggio 2017

Rendere eseguibile ed eseguire un file/script in Linux

Per essere eseguito uno script deve avere i permessi corretti; questi vengono attribuiti attraverso il comando chmod:
chmod +x nomefile.sh

Per la sua esecuzione:
bash: ./nomefile.sh
eventualmente preceduta da sudo o con sh al posto di bash in base al contenuto dello script

giovedì 25 maggio 2017

Hiren's BootCD

In un unico CD o su una chiavetta avviabile una raccolta di programmi potrebbe essere molto utile:
https://www.hiren.info/pages/bootcd