martedì, dicembre 27, 2016

Ping host and log output with timestamp

If you have some random network issue (specially on virtual machine) and you have to collect the time when it occur this command line can be helpful for you.

ping host | perl -nle 'BEGIN {$|++} print scalar(localtime), " ", $_' > outputfile

Source: http://stackoverflow.com/questions/10679807/how-to-timestamp-every-ping-result

venerdì, ottobre 28, 2016

httpie - http for everyone!

The life for a web app developer it's so difficult without a real tool for test HTTP request/response, in particular with xhr ajax near-realtime apps.

HTTPie - aitch-tee-tee-pie - (httpie.org) is an open source CLI HTTP client that will make you smile: a user-friendly curl alternative that provides a simple http command designed for painless debugging and interaction with HTTP servers, RESTful APIs, and web services.

For example, it's very simple to make a simple GET request with only one parameter:

# http httpbin.org/ip

It's available on multiplatform (Linux, Windows, MacOS X) and it's well documented.

So, what else ? Go to documentation, read all and make your http request easy!

giovedì, febbraio 04, 2016

Windows Shortcuts

General

  • Win+Up Maximize
  • Win+Down Restore / Minimize
  • Win+Left Snap to left
  • Win+Right Snap to right
  • Win+Shift+Left Jump to left monitor
  • Win+Shift+Right Jump to right monitor
  • Win+Home Minimize / Restore all other windows
  • Win+T Focus the first taskbar entry (Pressing again will cycle through them, you can can arrow around.)
  • Win+Shift+T cycles backwards.
  • Win+Space Peek at the desktop
  • Win+P External display options (mirror, extend desktop, etc)
  • Win+# (# = a number key) Launches a new instance of the application in the Nth slot on the taskbar. Example: Win+1 launches first pinned app, Win+2 launches second, etc.
  • Win + + and Win + – (plus or minus key) Zoom in or out.

Explorer

  • Alt+P Show/hide Preview Pane


Taskbar modifiers

  • Shift + Click on icon Open a new instance
  • Middle click on icon Open a new instance
  • Ctrl + Shift + Click on icon Open a new instance with Admin privileges
  • Shift + Right-click on icon Show window menu (Restore / Minimize / Move / etc) Note: Normally you can just right-click on the window thumbnail to get this menu
  • Shift + Right-click on grouped icon Menu with Restore All / Minimize All / Close All, etc.
  • Ctrl + Click on grouped icon Cycle between the windows (or tabs) in the group



sabato, gennaio 23, 2016

How to get the sizes of the tables of a mysql database

If you have a very big database with a lot of tables and you want to know which tables use more spaces, run the following query replacing %DB_NAME% with your database and %TABLE_NAME% if you know the table name.

SELECT 
    table_name AS `Table`, 
    round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB` 
FROM information_schema.TABLES 
WHERE table_schema = "$DB_NAME"
    AND table_name = "$TABLE_NAME";


Ref: http://stackoverflow.com/questions/9620198/how-to-get-the-sizes-of-the-tables-of-a-mysql-database

martedì, dicembre 22, 2015

Grep Quick Reference

Basic grep usage



Get lines which does not begin with "#" or ";"?
# grep "^[^#;]" /path/to/my/file 
Search recursively through single file extension
# grep -r --include=<pattern> <string> <directory>

Download Oracle JDK with single command


Today I want to show you how to download JDK with one single command. Yes, because if you want to get java from oracle web site you have to accept license before start the download.


If you want to don't want to use browser and you have to get it from command line you can use


# curl -LO ${URL} -H "Cookie: oraclelicense=accept-securebackup-cookie" 

where {URL} can be:


  • http://download.oracle.com/otn-pub/java/jdk/8u25-b17/jdk-8u25-linux-x64.tar.gz for JDK 8
  • http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.tar.gz for JDK 7






mercoledì, dicembre 09, 2015

How to securely connect to IMAP using OpenSSL

I never knew how to connect to an IMAP server when SSL/TLS were forced. With unencrypted connections, you can just Telnet in, but this exposes your login credentials and data, so many servers will not allow that. The secure equivalent to Telnet, I found, is OpenSSL's s_client tool. The documentation clearly labels it as a debug tool.

You'd resort to either connection method for verification or troubleshooting purposes; I can't imagine anyone wanting to do employ Telnet or s_client regularly — rather than use some mail client.


As an example, here's how you could log into an Exchange account, select the Inbox folder, and log out:


# openssl s_client -connect server:port -crlf
? LOGIN username password
? SELECT Inbox
? LOGOUT

giovedì, novembre 12, 2015

How to generate and send an time stamp request ?

Hi,

today the problem is how to generate and send a time stamp request to a Time Stamp Authority (TSA).

For this quick guide I use free time stamp service (limited to 5 timestamps per day and IP) available on https://tsa.safecreative.org/

Alright, cut the chatter, men. Enjoy!

First we have to create the file you will want to timestamp:

# echo "This is the content of test file." > inputfile.txt

Then generate a timestamp request that we want to sign:

# openssl ts -query -data inputfile.txt -cert -sha256 -no_nonce -out request.tsq

Then send the request to timestamp server

# curl -k  -H "Content-Type: application/timestamp-query" --data-binary @request.tsq "https://tsa.safecreative.org/" > inputfile.txt.tsr

If all it's fine the content of inputfile.txt.tsr is the response of your request.

If you want to verify the content you can do:


# curl -k  -H "Content-Type: application/timestamp-query" --data-binary @request.tsq "https://tsa.safecreative.org/" > inputfile.txt.tsr





mercoledì, novembre 11, 2015

How to change editor for for crontab file

If you want to specify an editor, when opening crontab file. And not just use the default for your system. You need to use VISUAL environment variable.

Export the value of VISUAL and then run crontab -e command.

# export VISUAL=nano; crontab -e

Of course you need to have vim or nano installed in your system if you want to use them.

mercoledì, ottobre 14, 2015

How to analyze long output of a MySQL query?

Using MySQL in command line mode can be a problem when you have to analyze query result that have long lines.

If you use Linux for you can set the pager option of mysqlclient

mysql> pager less -n -i -S

If you want to make it permanently you can setup your my.cnf with this:

[client]
pager = less -n -i -S

Ref: http://stackoverflow.com/questions/4285664/how-to-adjust-display-settings-of-mysql-command-line

mercoledì, settembre 30, 2015

Ceph Quick Reference

In this post you can found a lot of helpful commands that you can use with Ceph.

RBD


sudo rbd map disk_name --pool pool_name
Map the image to a block device.
sudo rbd unmap /dev/rbd/pool_name/disk_name
Unmap the image to a block device.