Crontab as another user Ubuntu

Sometimes you need to run commands as another user in order to avoid permission errors, you can run a crontab as another user with the following command

sudo crontab -u USER_RUNNER -e

Just change USER_RUNNER for an existent user on your system and it will run as that user.

And by the way, if you need some assistance on how to create the different values for your cron times, and how they are defined, this is a great tool.

https://crontab.guru/

Create a private repository for composer with Satis

Download Satis or clone it from the repository
git clone https://github.com/composer/satis.git

Access the folder satis just created and install the dependencies with composer
composer install

Configure to use the command satis, export the bin/ folder to the PATH or create a symbolic link
sudo ln -s /path/satis/bin/satis /usr/local/bin/satis

Create the JSON including your repositories information, for this example it will be privateRepos.json

{
 "name": "Private repository SSH (dnetix)",
 "homepage": "https://your_domain.com/",
 "repositories": [
 {
 "type": "vcs",
 "url": "git@bitbucket.org:dnetix/example.git"
 },
 {
 "type": "vcs",
 "url": "git@bitbucket.org:dnetix/example2.git"
 }
 ],
 "require-dependencies": true
}

Create a public web folder accesible from the homepage given, say that is /var/www/repository so you will construct the web page

Note that the URL needs accesible from the machines that will use the repository and it needs to have a valid SSL certificate, only works with https

Run the build command and it will create the necessary web files for it
satis build privateRepos.json /var/www/repository

It will prompt for access to those repositories so use the method you want

Add it to the each project’s composer.json to let know to composer that it needs to use also your private repository

"repositories": [
 {
 "type": "composer",
 "url": "https://your_domain.com"
 }
 ],

Now you can include your own with a composer require dnetix/example

How to create a REST client to POST a JSON object to a server and receive the data in Java

I just went through a lot of internet search in order to do exactly what the title says, looks like in the Java world you need to have always a IDE like Eclipse, or even worse, Netbeans, but sometimes I just need to test a concept and I don’t want to create a project for it.

In this case I just wanted to make a simple REST client posting a JSON object and receiving the information, lots of posts uses libraries, frameworks and all kind of stuffs, but I wanted to make it the simpler possible so, here’s my code:

Continue reading