I hava a small utility which accept some input from command line from another system. To keep the utility more open, i don’t want to restrict some parameters, the caller can provide more parameters, i will just need to ignore them. In Python, we use argparse for this job, by default if the user provide more parameters that you expect, it will trigger the error. There is a way to overcome this Below is the script i use for this job,   parser = argparse.ArgumentParser() parser.add_argument( ‘–url’,default=None,dest=’url’) parser.add_argument( ‘–id’,default=”id”,dest=’id’) parser.add_argument( ‘–script’,default=None,dest=’script’) parser.add_argument( ‘args’,nargs=”*”) #this is how we can ignore all other parameters args,unkown = parser.parse_known_args()Read More →

Supposed that you have a command line like this:   How do you get that options in php?  Please note the “:” in the option myscript.php –url “http://www.google.com” –proxy “127.0.0.1:8080”   <?php $options = getopt(“”,array(“url:”,”proxy:”)); print_r($options); ?>Read More →

let say you have a query string ?var1=test;abc&var2=ok when you use function parse_qsl to parse query to get the variable , you will see you have a several variables: var1 = testabc=””var2=ok This is because parse_qsl use “&” and “;” as a separate , to overcome this we need to replace “;” with %3B , then we’ll replace it back in our variable valuesRead More →

When you start to write your own http python server, the easiest way is to start with with BaseHTTPServer class. there are many behavior that you want to customize such as the timeout , or error handling. This is the link to original BaseHTTPServer, it’s for your reference to modify it https://svn.python.org/projects/python/trunk/Lib/BaseHTTPServer.py This is my timeout and finish override function def setup(self): BaseHTTPRequestHandler.setup(self) self.rfile._sock.settimeout(2) def finish(self,*args,**kw): try: if not self.wfile.closed: self.wfile.flush() self.wfile.close() except socket.error: do_debug(“remote client disconnected”) self.job_finish() pass self.rfile.close()Read More →

Somehow my server opens port 111, i don’t have time to investigate which program is opening that port, my quick fix was to block that port from external /sbin/iptables -A INPUT -p tcp –destination-port 111 -j DROP /sbin/iptables -A INPUT -p udp –destination-port 111 -j DROP #remember to save your iptables config iptables-save > /etc/iptables.conf #and restore it when your machine restarts iptables-resotre </etc/iptables.confRead More →

When it comes to web monitoring, we normally use Curl to accomplish it. But things getting more complex such password protection, single sign-on using Microsoft ADFS, these new authentication requires some javascript integration which Curl is failed to do. I did some works with Sitespeed for end user monitoring. We use sitespeed docker to visit the website and collect browser metric. By the way, if you don’t know what sitespeed is , visit http://www.sitespeed.io Sitespeed is doing pretty well in collecting the metrics, there is a very nice feature that Sitespeeds does is the ability writing our own selenium script. So imagine that , weRead More →

I have a folder like this: total 4.0K -rwxrwx—. 1 root vboxsf 101 Dec 25 08:03 notes.txt drwxrwx—. 1 root vboxsf 64 Dec 24 22:43 test drwxrwx—. 1 root vboxsf 64 Dec 25 07:45 test2 Then I run a docker sudo docker run -i -v /Data:/Data ubuntu bash cd /Data mkdir test3 I got permission denied. After some research, it turned out that this related to SELinux, it’s a security feature to limit root access. You can easily identify this by looking at the dot (.) at the end of the listing. You can temporary disable it by using: su -c “setenforce 0” To makeRead More →

Having some spare time during Christmas, i spent sometime to install Redhat on my Imac 2011. I followed this guides: https://www.mimiz.fr/install-rhel7-virtualbox-macos.html It’s very straight forward, you don’t need to read all, but you might face some challenges like me. My issue was with internet connection, i do not have internet after the installation. It turned out that i haven’t turned on the network during the installation. To fix this i have to do this manually by run this command: ifup enp0s3 In order to install additional software, we normally use yum utility to install. Redhat require us to register with their subscription manager, it’s free.Read More →

Is your iMac 2011 working? is it too hot? You are so lucky. But you need to keep it cooler otherwise you will have the same problem as me. One day you might see that it’s not booting and you see some stripes in the screen. If you see that, that means your GPU (graphic card) is failed. It’s could be an easy/cheap fix if you can buy a used part on eBay. My original card is HD 6970M 2GB, it’s still now almost $200 on eBay. So I finally have to use an older card , it’s about $40. It’s 6770M 512MB. It’s originallyRead More →

I’m using Curl 7.5.x, but somehow when i use the –ntlm option, the server seems not accepted. After many tries, i finally make it worked by install the curl 7.46 cd ~ sudo apt-get build-dep curl wget http://curl.haxx.se/download/curl-7.46.0.tar.bz2 tar -xvjf curl-7.46.0.tar.bz2 cd curl-7.46.0 ./configure –with-nghttp2 –with-ssl –with-libssl-prefix=/usr/local/ssl # This is the line I had the most trouble with, especially figure out –with-libssl-prefix make sudo make installRead More →