This blog serves as a dumping ground for my own interests. On it you will find anything which I want to keep track of; links, articles, tips and tricks. Mostly it focuses on C++, Javascript and HTML, linux and performance.
Wednesday, 19 August 2015
Send email from script
$ sudo apt-get install ssmtp
Edit the ssmtp config file:
$ sudo vim /etc/ssmtp/ssmtp.conf
Enter this in the file:
root=username@gmail.com
mailhub=smtp.gmail.com:465
rewriteDomain=gmail.com
AuthUser=username
AuthPass=password (create a app-specific password in google accounts)
FromLineOverride=YES
UseTLS=YES
Enter the email address of the person who will receive your email:
$ ssmtp recepient_name@gmail.com
Now enter this:
To: recipient_name@gmail.com
From: username@gmail.com
Subject: Sent from a terminal!
Your content goes here. Lorem ipsum dolor sit amet, consectetur adipisicing.
(Notice the blank space between the subject and the body.)
To send the email: Ctrl + D
You can also save the text mentioned in Point 5 into a text file and send it using:
$ ssmtp recipient_name@gmail.com < filename.txt
http://askubuntu.com/questions/12917/how-to-send-mail-from-the-command-line
Friday, 7 August 2015
Supervisord & Rundeck
supervisord
install
$ sudo easy_install supervisor
generate SHA-1 hash of password to be used for TCP access
$ echo -n password | sha1sum | awk '{print $1}'
enable TCP access
sudo vim /etc/supervisor/supervisord.conf
[inet_http_server]
port = 127.0.0.1:9001
username = user
password = {SHA}1235678
configure supervisorctl command line access (note password cannot be SHA hash, has to be plaintext)
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock
serverurl=http://localhost:9001
username = user
password = abcdef
add a program
sudo vim /etc/supervisor/conf.d/app_example.conf
[program:app_example]
command=app_example
directory=/path/to/app
autostart:false
autorestart:false
startsecs:5
startretries:3
user:prod
redirect_stderr:true
stdout_logfile:/path/to/app/logfile.log
stdout_logfile_maxbytes:1000GB
supervisorctl - enter interactive mode
supervisorctl -s http://localhost:9001 -u user -p password
start/stop
supervisorctl -s http://localhost:9001 -u user -p password start group:app
reread/restart/update
supervisorctl -s http://localhost:9001 -u user -p password update (or reread, restart)
reread just reads config changes, but doesn’t restart any affected processes
restart restarts the names process without loading any config changes
update rereads and restarts apps with changed configuration
rundeck
download and install from http://rundeck.org/downloads.html
add user to rundeck group
$ sudo usermod -a -G rundeck steve
add write permissions to rundeck group
$ sudo chmod g+w -R /var/rundeck
Friday, 24 July 2015
Postgres
Postgres
install server
sudo apt-get install postgresql postgresql-contrib
install client
sudo apt-get install postgresql-client libpqxx-dev pgadmin3
configure server
As user postgres, run psql, connecting to database postgres
sudo -u postgres psql postgres
In the psql shell, set the postgres user’s password, and then press ctrl-d to exit the psql shell
\password postgres
create a new user, with an associated database
as user postgres, run createuser to create a new user dev
sudo -u postgres createuser -D -A -P dev
the options are:
-D: no database creation rights-A: no add user rights-P: ask for password
as user postgres, run createdb to create a new database devbd owned by user dev
sudo -u postgres createdb -O dev devdb
set the new user’s password
sudo -u postgres psql
\password dev
\password prod
install server instrumentation
as user postgres, create the adminpack extension
sudo -u postgres psql
CREATE EXTENSION adminpack;
change server authentication method
default authentication is peer. peer authentication obtains the client’s operating system user name from the kernel and uses it as the allowed database user name. This only works for local connections.
change to md5, which is password-based authentication, with the password sent over the connection as a md5 hash.
sudo vi /etc/postgresql/9.3/main/pg_hba.conf
change the line
# Database administrative login by Unix domain socket
local all postgres peer
to
# Database administrative login by Unix domain socket
local all postgres md5
get postgres to reload the config
sudo /etc/init.d/postgresql reload
Wednesday, 3 June 2015
GNU make variables
$< - name of the first prerequisite
$? - list of all prerequisites newer than target
$^ - list of all unique prerequisites
$+ - list of all prerequisites, including duplicates (useful for linking)
$| - list of all order-only prerequisites
$* - stem; the part of the filename that matched the ‘%’ in the target pattern
$(@D) - directory part of the target (if no '/' appears, it is '.')
$(@F) - filename patr of the target (equivalent to $(notdir $@))
$(<D) - directory part of the first prerequisite
$(*F) - filename part of the stem
Tuesday, 2 June 2015
CheckInstall
tar -zxvf source-app.tar.gz;
cd source/ ;
./configure;
make;
sudo checkinstall make install;
https://wiki.debian.org/CheckInstall
Thursday, 14 May 2015
Convert an enum class to its underlying_type
template<typename E>
constexpr auto to_integral(E e) -> typename std::underlying_type<E>::type
{
return static_cast<typename std::underlying_type<E>::type>(e);
}
Since it is constexpr it can be used as follows:
std::array<int, to_integral(my_fields::field)> b;
http://stackoverflow.com/questions/14589417/can-an-enum-class-be-converted-to-the-underlying-type
Thursday, 9 April 2015
Ubuntu terminal tab colors
$ vim ~/.config/gtk-3.0/gtk.css
TerminalWindow .notebook {
background-color: shade (#333333, 1.02);
background-image: none;
border-radius: 3px;
padding: 2px;
background-clip: border-box;
border-color: shade (#333333, 0.82);
border-width: 1px;
border-style: solid;
/*box-shadow: inset 0 1px shade (#AEA79F, 1.1);*/
/*font-weight: 300;*/
}
TerminalWindow .notebook tab {
background-image: none;
background-color: #333333;
border-style: solid;
border-image: -gtk-gradient (linear, left top, left bottom,
from (alpha (shade (#333333, 0.9), 0.0)),
to (shade (#333333, 0.9))) 1;
border-image-width: 0 1px;
border-color: transparent;
border-width: 0;
box-shadow: none;
/*color: shade (@fg_color, 1.2);*/
color: #AEA79F;
}
TerminalWindow .notebook tab:active {
border-color: shade (#333333, 0.82);
border-style: solid;
border-width: 1px;
background-color: shade (#AEA79F, 1.02);
background-image: none;
/*box-shadow: inset 0 1px shade (#AEA79F, 1.1);*/
color: #333333;
}