Tuesday, February 21, 2012

Disable Google Chrome Developer Tools

Finally, I found a way to disable google chrome developer tools. I need it because I have some browser based application that I need to deploy, and google chrome is really suitable for my need. The only thing that prevented me doing so is the dev tools. I don't want user to play around with the dev tools, do some hacking and stuff. No way!
Now, here is how to disable devtools:
Edit ~/.config/google-chrome/Default/Preferences
On Mac OSX: ~/Library/Application Support/Google/Chrome/Default
Add "disabled": true to the "devtools" key, so it becomes like the following:
"devtools": { "disabled": true, "split_location": 256 }
Save it, and restart browser. Done!
Here is where I originally found the solution.

Monday, January 16, 2012

Ubuntu 11.10 Virtual NIC IP Workaround

The normal way of adding virtual nic ip is by setting it in /etc/network/interfaces, like the following:

auto eth0:0
iface eth0:0 inet static
address 192.168.0.111
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.1

Unfortunately, there is a known bug which prevent such configuration to work. Take a look here.

The first workaround that I figured out is by using /etc/rc.local script.
Add the following lines before exit(0) inside that script:
#################################
sleep 4  # This due to concurrency, set some delay in order for the networking to be set up properly first
ifconfig eth0:0 192.168.0.111 netmask 255.255.255.0 broadcast 192.168.0.255
# or use below command to replace above ifconfig command
# ip addr add 192.168.0.111 dev eth0
#################################

The second workaround is, IMHO, better. No sleep hack necessary, since upstart script is used instead of rc.local script.
Create /etc/init/network-interface-virtual.conf (or use different name as you like), with the following lines inside:
#################################
description "configure virtual network device"
respawn
console none

start on (net-device-up IFACE=eth0)
stop on runlevel [!12345]

script
exec ip addr add 192.168.0.111 dev eth0
# or use ifconfig command below
# ifconfig eth0:0 192.168.0.111 netmask 255.255.255.0 broadcast 192.168.0.255
end script
#################################

Reboot your system if necessary and everything is set and the virtual nic ip is ready to use. Oh, one more thing. There is also a bug (I think), which makes the virtual nic ip not showing with the ifconfig -a command. Just ping the virtual ip address to test whether it's up or not. 

Ubuntu 11.10 and Realtek (RTL8111/RTL8168) NIC driver problem

Finally, I figured out the problem that I had with network connection. The problem was with Realtek (RTL8111/RTL8168) NIC, which somehow detected differently by ubuntu 11.10 and uses r8169 kernel module driver.
To be sure, do check your NIC using:
$ sudo lscpi

You should see something like ...Realtek (RTL8111/RTL8168)...
Next step is to remove the r8169 module using:
$ rmmod r8169

If necessary install build-essential, etc:
$ sudo apt-get install build-essential linux-headers-$(uname -r) linux-source

Then, download the proper driver for that particular NIC from here. The file name should be something like r8168-8.027.00.tar.bz2.
Uncompress the file, and run the shell script file, as root:
# ./autorun.sh

Check the newly compiled driver:

$ sudo lsmod | grep r8168
$ ifconfig -a


Blacklist the r8169 module driver, by editing /etc/modprobe.d/blacklist.conf, add:
#blacklist r8169 driver
blacklist r8169

Reboot your system if necessary.

Wednesday, December 21, 2011

netcat as WebServer

I needed to have a (dummy) web server which gives only 201 CREATED response, for testing purpose. Instead of using real web server, I found a simpler way to achieve that. Using netcat like the following is enough for me to do some testing on my programs.

$ nc -C -l 8080 -q 1 << EOF
HTTP/1.0 201 CREATED
Content-Type: text/html
EOF

Saturday, November 26, 2011

Interacting with Django Tastypie API Using Python Librarys

If you already have some django web-app, consider extending its functionality with django-tastypie. It has pretty decent docs as well. With django-tastypie you can create RESTful Web Service. I am not going to talk about django-tastypie in this post, instead I would like to share how to interact with django-tastypie api using python's urllib and urllib2 libraries.

The following codes gives some idea about how to get data using the API, with ApiKeyAuthentication method.

import urllib, urllib2

api_url = 'http://localhost:8080/api/app1/model1/?username=apiuser1&api_key=apikey_for_apiuser1'
http_req = urllib2.Request(api_url, headers={'ACCEPT': 'application/json, text/html'})
try:
    resp = urllib2.urlopen(http_req)
    contents = resp.read()
    print contents
except urllib2.HTTPError, error:
    print he.getcode()


The codes below gives some idea about how to create data using the API, with ApiKeyAuthentication method.


import urllib, urllib2
import simplejson as json


api_url = 'http://localhost:8080/api/app1/model1/?username=apiuser1&api_key=apikey_for_apiuser1'
json_post = json.dumps({"model_name": "TEST13"})
http_req = urllib2.Request(api_url, json_post, {'Content-Type': 'application/json', 'ACCEPT': 'application/json, text/html'})
try:
response = urllib2.urlopen(http_req)
print response.read()
print response.getcode()
print response.info()
print response.msg
except urllib2.HTTPError as he:
print he.getcode()
print he.info()
print he.msg
except urllib2.URLError as ue:
print ue

Both examples using json data format. Remember to set the appropriate Content-Type and ACCEPT header data if using different data format.
If it is necessary to use https secure connection and proxy, refer to this post to get more information.


Distributing Large Files - Implementation Part 1

This post is related to my previous post about distributing large files http://murzal-arsya.blogspot.com/2011/11/distributing-large-files.html.

Finally I implemented my distribution strategy as I explained in my previous post. Let me give a little bit info about the infrastructure.

1 Server:
Brand/Type: IBM System x3650 M3
OS: Centos 6
Service: Samba
NIC: 2 Gigabit

1 Switch: HP Procurve 1810 24g (Gigabit)

10 Clients:
Brand/Type: HP Pavilion HPE
OS: Windows 7
Apps: QGIS
NIC: 1 Gigabit


I have samba configured as shared storage. Within the share folder I put the large image files to be distributed to the clients. My strategy is creating a chain distribution, from the Server to PC-01, PC-01 to PC-02, and so on, until PC-10. I choose robocopy for its simplicity and it does the job well.
So, I created a batch file

Since I need to access the shared folder, I need to make sure that the connection could be established using correct user for authentication. In order to do that, before I run robocopy, I use net use command for authenticating.
>net use \\SERVER\share_images /USER:user1 password1
then I could execute robocopy with something like the following:
>robocopy /E /PURGE /COPY:DAT \\SERVER\share_images C:\images

The most ideal way to trigger the synchronization is when there is change in each share folder, and queuing the sync processes when there are multiple changes detected. It is beyond the scope of this post.