Friday, July 13, 2018

linux - Run parallel multiple commands at once in the same terminal - Stack Overflow

linux - Run parallel multiple commands at once in the same terminal - Stack Overflow



This bash script is for N parallel threads. Each argument is a command.
trap will kill all subprocesses when SIGINT is catched.
wait $PID_LIST is waiting each process to complete. When all processes have completed, the program exits.
#!/bin/bash

for cmd in "$@"; do {
  echo "Process \"$cmd\" started";
  $cmd & pid=$!
  PID_LIST+=" $pid";
} done

trap "kill $PID_LIST" SIGINT

echo "Parallel processes have started";

wait $PID_LIST

echo
echo "All processes have completed";
Save this script as parallel_commands and make it executable.
This is how to use this script:
parallel_commands "cmd arg0 arg1 arg2" "other_cmd arg0 arg2 arg3"
Example:
parallel_commands "sleep 1" "sleep 2" "sleep 3" "sleep 4"
Start 4 parallel sleep and waits until "sleep 4" finishes.

Sunday, July 01, 2018

aria2 on Raspberry Pi | Installation and Troubleshooting

https://edwinvakkachan.wordpress.com/2018/02/07/aria2-on-raspberry-pi-installation-and-troubleshooting/

Installing aria2 on Raspberry Pi

aria2 is a lightweight multi-protocol & multi-source command-line download utility. It supports HTTP/HTTPS, FTP, SFTP, BitTorrent and Metalink. aria2 can be manipulated via built-in JSON-RPC and XML-RPC interfaces. They said.

Installation:

First thing first, always update your repository.
sudo apt-get update
Next, download aria2.
sudo apt-get install aria2
Now, we make a config file for aria2. First, make the directory for it.
sudo mkdir /home/pi/.aria2
And make the config file.
sudo nano /home/pi/.aria2/aria2.conf
Here’s my configuration, you can always configure it yourself using this guide.
dir=/home/pi/downloads
file-allocation=falloc
continue
log-level=error
max-connection-per-server=4
summary-interval=120
daemon=true
enable-rpc=true
rpc-listen-port=6800
rpc-listen-all=true
max-concurrent-downloads=1
disable-ipv6=true
disk-cache=25M
timeout=600
retry-wait=30
max-tries=50
Now, we make aria2 can run on boot. First, make init.d file.
sudo nano /etc/init.d/aria2
Here’s my script:
#! /bin/sh
# /etc/init.d/aria2
### BEGIN INIT INFO
# Provides: aria2cRPC
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: aria2c RPC init script.
# Description: Starts and stops aria2 RPC services.
### END INIT INFO
RETVAL=0
case “$1” in
start)
echo -n “Starting aria2c daemon ”
umask 0000
aria2c –daemon=true –enable-rpc –rpc-listen-all -D –conf-path=/home/pi/.aria2/aria2.conf
RETVAL=$?
echo
;;
stop)
echo -n “Shutting down aria2c daemon ”
/usr/bin/killall aria2c
RETVAL=$?
echo
;;
restart)
stop
sleep 3
start
;;
*)
echo $”Usage: $0 {start|stop|restart}”
RETVAL=1
esac
exit $RETVAL
Now change aria2’s init.d script permission so it can run as executable.
sudo chmod +x /etc/init.d/aria2
Make aria2 run on boot.
sudo update-rc.d aria2 defaults
Now reboot your Raspberry Pi
sudo shutdown -r now
You can always access aria2 on local network using this webgui provided by ziahamza.
To configure the webgui, go to Setting>Connection Setting.
Enter the host, in this case your Raspberry Pi IP address. And your aria2 port which is inside your aria2.conf, in this case 6800.

Troubleshooting:

1. Download was not successful, download directory are external harddrive
Open aria2.conf and change file-allocation=falloc to file-allocation=none

Tuesday, June 12, 2018

Raspberry Pi Packet Sniffer

1,
SETTING UP A RASPBERRY PI AS AN ACCESS POINT IN A STANDALONE NETWORK (NAT)

tips:

After upgrade, you may need reboot.

After upgrade, you may need update again.

If it says no 'hostapd', make sure upgraded, updated.

If it says iptables can not find table, most likely you didn't reboot after upgrade.

Make sure your previous WiFi deleted/commented from /etc/wpa_supplicant/wpa_supplicant.conf, otherwise your pi will connect to your own WiFi and because the wlan0 been occupied, you can not connect to your pi via wireless.

2,

An HTTP and HTTPS sniffing tool created using a Raspberry Pi

tips:

you can install mitmproxy via apt-get install mitmproxy

make sure you run ./mitm.sh

Friday, June 08, 2018

Working On An iPad Pro For Developers

This is preparation of my new iPad Pro. I'm going to use it for some development work and I collected following information

Thanks to:

Shane Dowling

The iPad Pro as a focused, simple coding machine

***

Working On An iPad Pro For Developers

***

Hey Apple, I Tried The iPad Pro As A Dev Machine. It’s *Almost* Awesome

***

The iPad Pro as main computer for programming



Conclusion:

Local dev: No; Remote Dev: Yes

Tools:

1, VPS - I'll build my own Linux box
options:
DigitalOcean, static IP, better APP to manage;
AWS,  Amazon Cloud9 IDE is perfect to work together;
Linode;
Vulture

2, SSH
Termius - I'm using it, I'm happy with it.
options:
Prompt
Prompt 2
ServerAuditor
vSSH HD
Blink Shell -- worth it

3, Editor
vim - I'm a vim person
options:
GoCoEdit -- sublime text like
Working Copy -- with git client
Coda  -- good for front end dev
Spacemacs -- for Emacs person


4, DB client
mycli


5, Server Environment 
Vagrant - for personal development, I prefer Vagrant
Docker

6, Tips

6.1, For vim,  'Ctrl + ['  equals to 'Esc'
6.2, Screens for vnc
6.3, it is of course definitely possible to connect an external monitor to an IPP with the USB-C connector (or beamer). Either through VGA or HDMI.  Via Lightning to USB Camera Adapter

6.4,
So one thing that might be useful is when you exit your little server to have it automatically shut down so you don’t need to keep remembering to kill the server via the app. If you want to do this without needing to enter a password each time, firstly run this command to start editing the sudoers file.
sudo visudo
Then add this line to allow passwordless access to poweroff commands.
username   ALL=(ALL) NOPASSWD: /sbin/poweroff, /sbin/reboot, /sbin/shutdown
Then create an alias for your user so that when you hit exit, it actually shuts down the machine. Put this in your .bashrc or .zshrc or whatever rc your shell uses.
alias exit=’sudo poweroff’

Thursday, May 24, 2018

Raspberry Pi PHP Http Proxy

This post is about how to setup your Raspberry Pi to be a web server and work as a Http Proxy on internet.

I"m using a Raspberry Pi 3.

You need:

1, install Apache and PHP
2, install Athlon1600/php-proxy-app
3, port forwarding on your modem / router
4, use HTTPS (optional)
5, use dynamic DNS (optional)

1, install Apache and PHP
https://www.stewright.me/2016/03/turn-raspberry-pi-3-php-7-powered-web-server

Step 1 – Add new repository sources

At the time of writing, PHP 7.0 hasn’t yet made the official repository sources, so we need to add one which provides us with the PHP 7.0 packages. Edit your sources file with this command:
sudo nano /etc/apt/sources.list
Below the existing entries in the file on a blank line, add the following two lines:
deb http://repozytorium.mati75.eu/raspbian jessie-backports main contrib non-free
#deb-src http://repozytorium.mati75.eu/raspbian jessie-backports main contrib non-free
Your file should look a little like this:
Install Apache 2 and PHP 7 on Raspberry Pi 3
Next we need to add a couple of certificates in order to allow us to use the sources with apt-get. Run the following two commands:
sudo gpg --keyserver pgpkeys.mit.edu --recv-key CCD91D6111A06851
sudo gpg --armor --export CCD91D6111A06851 | sudo apt-key add -
And finally we need to update the package list by running:
sudo apt-get update

Step 2 – Install the core Apache2 and PHP 7 packages

We’re ready to install Apache2 and PHP7, along with some common packages that we may need for most web applications such as Symfony2, WordPress, Drupal etc. Run the following command to install these packages:
apt-get install apache2 php7.0 php7.0-curl php7.0-gd php7.0-imap php7.0-json php7.0-mcrypt php7.0-mysql php7.0-opcache php7.0-xmlrpc libapache2-mod-php7.0
This may take a little time, but as soon as we’re done, we are essentially finished.

Step 3 – Test Apache2 and PHP 7

Assuming all went well, we’re ready to test to see if everything went OK with the installation. First we’ll test the version of PHP that CLI is using:
php -v
You should see something like this:
Install PHP 7 on Raspbian
Next we’ll test two things; Apache2 and PHP 7. In your web browser, visit the IP address of your Raspberry Pi. If you haven’t used ssh and have followed these steps on your Raspberry Pi 3 itself, just visit http://127.0.0.1, otherwise change 127.0.0.1 for the IP address of your Raspberry Pi.
You should see the default Debian holding page:
Turn Raspberry Pi into a web server
Next we’ll test PHP. Run the following command to create a test file:
echo "> /var/www/html/phpinfo.php
Yet again, visit the IP address of your Raspberry Pi, this time adding /phpinfo.php to the URL. You should see the PHP Information.

Tips: if you got error of cUrl extension not installed, you can do:
sudo apt-get install php-curl
sudo service apache2 restart
reference: https://stackoverflow.com/questions/33775897/how-do-i-install-the-ext-curl-extension-with-php-7?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

2, install Athlon1600/php-proxy-app

https://github.com/Athlon1600/php-proxy-app

3, port forwarding on your modem / router

https://maker.pro/raspberry-pi/projects/raspberry-pi-web-server

4, use HTTPS (optional)

https://variax.wordpress.com/2017/03/18/adding-https-to-the-raspberry-pi-apache-web-server/comment-page-1/

5, use dynamic DNS (optional)

https://desec.io/#!/en/docs/dyndns-client#option2

Thursday, May 17, 2018

ReportCrash High CPU & How to Disable reportcrash in Mac OSX - Gregory Varghese

ReportCrash High CPU & How to Disable reportcrash in Mac OSX - Gregory Varghese



For a while now, all of my MacBooks have run extremely hot and the fans have gone nuts. While troubleshooting the issue, Activity Monitor showed that an app named reportcrash has run very high on the CPU and has killed my battery life. Force quitting the app didn’t help as it would start right back up in a few seconds and climb back to 80-100% usage of the CPU.

What is CrashReporter?

CrashReporter runs in any time an application crashes and it’s designed to saves the application state to aid developers in working out why the app crashed. Basically a process is launching, crashing (and invoking CrashReporter) and then re-launching, repeating this cycle never ending.

How to Identify What’s Crashing

To show which process is triggering this cycle and stop it, CrashReporter is pretty verbose in its logging which makes finding the problem app somewhat easier. Open up the console.app (/Applications/Utilities/Console.app) and look towards the end of your system.log to see what app is crashing.
Unfortunately for me, the problem is a driver by some company called EFI and getting the latest drivers didn’t resolve the issue. The next obvious solution was to disable reportcrash.

How to Disable ReportCrash

Fire up terminal and run the following commands to disable reportcrash:

How to Enable ReportCrash

If you need to reenable crash report, run the following commands in terminal: