Free binary GeoLite Country database by MaxMind is being updated every month. To update it automatically you can put this script to cron at the beginning of a month. #!/bin/sh cd /usr/share/GeoIP wget -q http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz gzip -d -f GeoIP.dat.gz [root@playground ~]# sh -x /usr/local/sbin/geoip-update.sh + cd /usr/share/GeoIP + wget -q http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz + gzip -d -f…
All posts by Oleksii Tykhonov
RPM: building proctitle for PHP
Sometimes it’s convenient to change PHP script name, it allows to check if it’s running by typing just pstree. You can perform that with use of proctitle. Unfortunately there is no rpm for this package for Fedora 15. So to use it you need to build it. Firstly you need to download source package to…
RPM: how to build Redis library package for PHP
At Supportex we use Redis a lot. It’s extremely fast and doesn’t consume a lot of resources. Besides it’s easy to use for developers (especially for those who worked with Memcache). Unlike Python which has only one mature client, PHP has various of them. For instance, Predis, phpredis, Rediska, etc. We prefer phpredis. It’s written…
Bash: check if a zip or a rar file has password-protection
If you need to check if zip or rar file has password protection you can do it this way. For zip fip: crypted=$( 7z l -slt — $file | grep -i -c “Encrypted = +” ) if [ “$crypted” -eq “1” ]; then protected=1 fi And for rar: unrar x -p- -y -o+ “$file” 1>…
Python: sorting dict by value
Probably one of the most often task while working with dictionaries in Python is sorting by value. That is how it can be done: >>> d = {‘Canada’: 513, ‘Sao Tome and Principe’: 3, ‘Fiji’: 1, ‘Montenegro’: 12, ‘Lithuania’: 47} >>> sorted_list = sorted(d, key=d.get, reverse=True) >>> for i in sorted_list: … print i, d[i]…
Troubleshooting: Cannot open TUN/TAP dev /dev/net/tun
If you are getting error ‘Cannot open TUN/TAP dev /dev/net/tun‘ while starting OpenVPN server, it means that you should load ‘tun’ module which features TUN/TAP device driver: OpenVPN 2.1.1 i386-redhat-linux-gnu [SSL] [LZO2] [EPOLL] [PKCS11] built on Jan 26 2010 NOTE: the current –script-security setting may allow this configuration to call user-defined scripts LZO compression initialized…
Python: uploading file via HTTP with pyCurl and Requests
Here is a simple way to upload file in Python. You should have PyCurl installed. import pycurl from cStringIO import StringIO filename=’test_file’ c = pycurl.Curl() c.setopt(c.POST, 1) c.setopt(c.HTTPPOST, [(‘title’, ‘test’), ((‘file’, (c.FORM_FILE, filename)))]) c.setopt(c.VERBOSE, 1) bodyOutput = StringIO() headersOutput = StringIO() c.setopt(c.WRITEFUNCTION, bodyOutput.write) c.setopt(c.URL, “http://upload.example.com” ) c.setopt(c.HEADERFUNCTION, headersOutput.write) c.perform() print bodyOutput.getvalue() Upd. File upload with…
Python: distribution systems world
At the very beginning Python packaging world may seem too confusing. But only at first sight. There are a lot of different packages package formats, libraries and tools for distributing and packages management in Python world. There is also PyPI – the Python Package Index is a repository of software for the Python. Most often…
AWK: quick way to get squid users traffic usage
If you need quick and simple way to get squid users traffic usage you can use this script: #!/bin/bash awk ‘{ user = $8 traffic[user] += $5; } END { OFS = “tt” for (i in traffic) {printf “%s – tt size: %10.2f Mbn”, i, ( traffic[i] / (1024 * 1024 ) ) } }’…
RPM: Bulding Python package for Redis
To build RPM package for Python library is really easy task if developer has kindly included setup.py file in it. Let’s build RPM for redis-py package by Andy Mccurdy. First of all we need archive with last version of redis-py. [root@develop ~]# wget https://github.com/downloads/andymccurdy/redis-py/redis-2.4.9.tar.gz Unpack it. [root@develop ~]# tar xzvf redis-2.4.9.tar.gz [root@develop ~]# cd redis-2.4.9/…