Showing posts with label DevOps. Show all posts
Showing posts with label DevOps. Show all posts

How to install peerblock to improve web/p2p privacy in debian?

Peerblock is a program that prevents some peers to connect to your host when you use some P2P application. On Debian I wanted to install something similar, to avoid defining the firewall policies by hand.

Moblock is the name of the Debian side solution that corresponds to Peerblock. It's documented on the source forge page of the project.


To install moblock on debian squeeze:

sudo vim /etc/apt/sources.list

Add the following lines:
 
deb http://moblock-deb.sourceforge.net/debian squeeze main
deb-src http://moblock-deb.sourceforge.net/debian squeeze main

Then, run the following commands:
 
sudo make me a sandwich
sudo make me a sandwich (Photo credit: Fred​)
gpg --keyserver keyserver.ubuntu.com --recv-keys C0145138
gpg --export --armor C0145138 | sudo apt-key add
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install pgld pglcmd pglgui
sudo service pgl start
pglgui
service pgl status

A window should open, it permits you to configure your traffic filtering policies. Have fun !


Share:
Read More

What to buy to implement a raspberry pi based media center?

Raspberry Pi
Raspberry Pi (Photo credit: barbourians)
English: Extract from Raspberry Pi board at Tr...
If you want to setup a raspberry-pi based media center, you will need to buy the following elements:
  • A raspberry pi computer
  • An SD card to host the OS of your raspberry pi. 8 Go are sufficient for this.
Of course, you will need a way to configure the raspberry pi. That means that you will require a USB keyboard, or if you like fancy gadgets, a dongle + a wireless keyboard.

When you have all these elements, jump to my tutorial on how to transform your raspberry pi into a great media center support XBMC for samba shares and controlled through android !!

Other links:

Raspberry Pi
Enhanced by Zemanta
Share:
Read More

Debian clock problems: solution to permanent time shifts problems in the clock

For french people: ce post décrit une solution au problème d'horloge sous debian (squeeze) quand l'horloge de gnome est décalée en permanence d'une ou deux heures.

Solution:

sudo vim /etc/default/rcS
In this file, change the UTC line as follows: 
UTC=no
#UTC=yes

Reboot, and the clock should display your local time.


Share:
Read More
, ,

Mounting shares permanently in debian

English: Debian OpenLogo Italiano: Logo Debian...
Have you ever wondered how to mount shares permanently in Debian? That's a question I see often on forums. In fact it's simple once you have understood the role and syntax of the famous "/etc/fstab" file.

First, get an idea of your disks and partitions:
 
root@myDebian:/home/toto# df -h -T

This command provides the list of your partitions and their size, for instance
 
/dev/sdb2     ext4     38G   18G   18G  50% /
tmpfs tmpfs 5,9G 0 5,9G 0% /lib/init/rw
udev tmpfs 5,9G 252K 5,9G 1% /dev
tmpfs tmpfs 5,9G 0 5,9G 0% /dev/shm
/dev/sdc4 fuseblk 924G 770G 155G 84% /media/DATA
/dev/sde1 vfat 7,7G 23M 7,7G 1% /media/NIKON D90
/dev/sdb1 fuseblk 71G 59G 13G 83% /media/SSD

IF you want to mount a partition permanently, you have to edit the /etc/fstab file. The following tutorial will help you a lot.

In my case, I added:
 
/dev/sdc4       /media/DATA     auto    auto,user,noexec,rw     0       0 
 
 
Share:
Read More

Debian, what to do if the numerical keypad does not work?

my new microsoft wireless mouse and keyboard set!
In Debian, what do you do if the numerical keypad does not work? In fact it's a very common problem! To solve it, you just need to know this killer tip: try pressing shift + numlock instead of just numlock.

It works in most cases. Otherwise, your keyboard might be miss-configured and you should have a look to the /etc/X11/xorg.conf .

I hope it helps...
Share:
Read More

Setting proxy for bash in debian

English: Xfce Terminal. on Debian Lenny. 日本語: ...
English: Xfce Terminal. on Debian Lenny. 日本語: Xfce Terminal。Debian Lennyで。 (Photo credit: Wikipedia)

In this post, I will explain you how to configure the default proxy for bash in Debian. I often see questions about this in forums, so I hope it will help. If so, I would love to see links pointing to this article: it will help others find it more easily thanks to a better ranking in Google search. Thanks!

Setting up the proxy globally

You can set the proxy globally in the files:
/etc/environment
/etc/profile

In this file you can specify the proxy for a given application for instance (see http://askubuntu.com/questions/158557/setting-proxy-from-terminal):

http_proxy=http://10.1.3.1:8080 firefox

For bash

It's possible to specify the proxy in bash directly:
sudo env http_proxy=http://10.1.3.1:8080

Or in your .bashrc profile (not advised as it may not be taken into account by some applications):
export http_proxy=http://username:password@proxyhost:port/ 
export ftp_proxy=http://username:password@proxyhost:port/

For aptitude (apt-get)

If you want to set the proxy for apt, the proper way is to edit /etc/apt/apt.conf and add:

Acquire::http::proxy "http://10.1.3.1:8080/";

For pip / easy_install

For pip, you can use the --proxy option to specify a proxy:
pip install toto --proxy "user:password@proxy.server:port"
pip install toto --proxy "example.com:1080"

English: Diagram of an open forward proxy.
English: Diagram of an open forward proxy. (Photo credit: Wikipedia)
But pip sometimes calls setup.py files that do not follow the proxy directives. In this case the best way is to position http_proxy environment variable, and use easy_install as an alternative to pip.

For SSH

You can use ssh through a SOCKS proxy, but you need to install a few tools:

sudo apt-get install connect-proxy
man connect-proxy
vim ~/.ssh/config

In this configuration file, you specify which proxy you want to use for which hosts. For example, on this site, they provide the following configuration sample:

## Outside of the firewall, with HTTPS proxy
Host my-ssh-server-host.net
ProxyCommand connect -H proxy.free.fr:3128 %h 443
## Inside the firewall (do not use proxy)
Host *
ProxyCommand connect %h %p

Note the -S command, that is used for SOCKS proxy (-H) is for HTTP proxies, for example:
ProxyCommand /usr/bin/connect-proxy -4 -S pproxy:port %h %p

SANS institute published a good article about all what you can do with SSH trough a proxy :)

If you have liked this article, please put a link to it on your Google+ profile are any other kind of web site: it will help others find it in the search engines. Thanks!

configuring a proxy in bash terminal for Linux
Share:
Read More
,

How to replicate / export a virtualenv from a machine to another ?

Sudo
Sudo (Photo credit: Scelus' Comix)
If you code in Python, you probably use virtualenv to maintain a clean setup and avoid problems with different versions of pythons. But sometimes, you need to replicate / export a virtualenv from a machine to another. This post will explain you exactly how to do this.

First, use the following commands on the origin machine:

source ./bin/activate
pip freeze > requirements.txt

Then, copy your source code files from the virtualenv folder (called virtualenv_1) on the target machine. Do NOT copy the virtualenv files in folders such as bin, lib etc. We will eventually create these files with virtualenv on the new system:

sudo apt-get install python-virtualenv
sudo  virtualenv virtualenv_1

Then install all the required packages:

cd virtualenv_1
source bin/activate
sudo pip install -r requirements.txt

That's it! If you have liked this article, please put a link to it on your Google+  / facebook profile are any other kind of web site: it will help others find it in the search engines. Thanks!




Share:
Read More

How to install brother HL 227DW driver on debian x64?

Debian OpenLogo
First, a big up to Brother: their printers are excellent, and they provide drivers for Linux! In only hate it that they display a warning before the toner is actually empty... But that's another story. So in this post, I will explain you how to install brother HL 227DW driver on debian x64.

To install the driver on the x64 architecture you should go to Brother's driver download page: http://welcome.solutions.brother.com/bsc/public_s/id/linux/en/download_prn.html and download the .deb packages corresponding to your printer model. Then to install these packages:

sudo apt-get install ia32-libs
sudo dpkg -i --force-all hl2270dwlpr-2.1.0-1.i386.deb cupswrapperHL2270DW-2.0.4-2.i386.deb
sudo  dpkg  -l  |  grep  Brother
firefox http://localhost:631/printers
 
I hope it helps. If you have liked this article, please put a link to it on your Google+ / facebook profile are any other kind of web site: it will help others find it in the search engines. Thanks!


Share:
Read More

What to do if you accidently delete the admin user in a django project?

Django logo
Django logo (Photo credit: Wikipedia)
Have you ever wondered what to do if you accidently delete the admin user in a django project? That's a nasty problem in appearance, but not too serious in practice: Django provides a command line utility to solve that kind of problems:

manage.py createsuperuser --username=joe --email=joe@example.com


Share:
Read More
,

NoReverseMatch error in python django... The solution

More accurate representation of relationship b...
More accurate representation of relationship between URIs, URNs, and URLs. Revised version of File:URI Venn Diagram.svg, per Talk:Uniform Resource Identifier#Misleading Venn Diagram in a different way. (Photo credit: Wikipedia)
NoReverseMatch error is nasty with python Django. It happens often when you add a new page. In this post I will explain you how to solve this bug easily.

Typically the famous NoReverseMatch error occurs when you put quotes or not around your url name in a url tag of a template. For instance:

If you used:
{% url 'index' %}
Try:
{% url index %}
And conversely...

The source of this problem is the different syntax depending on whether you include url from future in your template or not.


Share:
Read More

How to install keepass2 in debian squeeze

If you want to install Keepass2 under Debian Squeeze, you will have a problem: keepass2 is not in the official repositories. Only keepassX is available.

In this blog post I explain how to install Keepass2 nevertheless.

The KeePass Password Safe icon.
At first glance, I see two potential solutions:
  1. We can find the keepass2 package on the web, download it, and install it. That's the solution I chose.
  2. Otherwise, a perhaps cleaner solution would be to download the source package and compile it. That's cumbersome because Keepass is windows oriented.

The installation of a .deb package, is usually simpler. I cleaned a bit the packages on my machine, installed the main dependencies, and gave a try to the installation of the ubuntu Natty package.

sudo apt-get autoremove
sudo apt-get install -f
sudo apt-get install mono-devel xdotool
wget http://launchpadlibrarian.net/71859414/keepass2_2.15%2Bdfsg-2%7Enatty1_all.deb
dpkg -i keepass2_2.15+dfsg-2~natty1_all.deb
keepass2

It worked !
If you have liked this article, please put a link to it on your Google+ profile are any other kind of web site: it will help others find it in the search engines. Thanks!


A screencapture from Keepass2
Share:
Read More

Django hosting: experience with webfaction

Webfaction payment history
Webfaction payment history (Photo credit: yashh)
I hesitated a lot among several options for hosting a django based web app. After reading a lot of posts, I decided to go with webfaction, because there was a lot of positive feedback from existing customers and they have a two month cost free cancellation policy (that means a two-month free trial period). So, I subscribed.

But then, I changed my mind and thought that I would rather like to try heroku, because there's some buzz about them and they have good documentation. So, here is my experience with webfaction's cancellation process: I canceled and less than 1 hour later Paypal informed me that webfaction had refunded me due to their 60-day cost free cancellation program. Then, I received an email from webfaction's support team telling me that they were sad to see me go and that they thanked me for having provided feedback about the reasons why I left.

Conclusion: I have really appreciated my short experience with webfaction because they were  professional and polite, and they hold the promise of their cost free cancellation guarantee. If, I am not satisfied with heroku, I will definitely come back to them.
Share:
Read More
,

How to configure Django with PostgreSQL?

In this post, I will explain you how to configure Django with PostgreSQL instead of MySQL.

The blue/white elephant logo of the PostgreSQL...
I did several changes locally before deploying my app to heroku and Amazon S3.

I changed my configuration to use postgreSQL instead of mySQL. I did not have any data stored in MySQL, so I reinitiated a brand new database. To do that, I had to come back to django's tutorial and edit settings.py:

        #'ENGINE': 'django.db.backends.mysql', # USE MYSQL
'ENGINE': 'django.db.backends.postgresql_psycopg2', # USE postgreSQL

Of course, I had to install PostgreSQL and to create the database, end user, and password referenced in my django settings.py according to the tutorial. The installation of psycopg2 through easy_install may lead to various errors such as the ones below:

ImportError: No module named psycopg2.extensions
or
Error: pg_config executable not found.
 
That's why we include several packages in the first apt-get install directive. These packages solve the above errors.

sudo apt-get update
sudo apt-get install postgresql postgresql-client python-psycopg2 libpq-dev  postgresql-server-dev-all python-dev python-psycopg2 --fix-missing
easy_install psycopg2
sudo adduser MYUSER
sudo su postgres
psql
postgres=# CREATE USER MYUSER WITH PASSWORD 'MYPASSWORD';
postgres=# CREATE DATABASE thenameofmydb;
postgres=# GRANT ALL PRIVILEGES ON DATABASE thenameofmydb to MYUSER;
postgres=# \q
exit
sudo vim /etc/postgresql/8.4/main/pg_hba.conf

In this file, check the following configuration directive:

# "local" is for Unix domain socket connections only
local all all trust

Then, we restart psql and log in:

sudo /etc/init.d/postgresql reload
psql -d thenameofmydb -U MYUSER 
 
 
 
Share:
Read More
, ,

Which server for deploying a scalable django powered web app? How to install nginx and gunicorn for django.

Debian OpenLogo
Debian OpenLogo (Photo credit: Wikipedia)
English: Nginx Logo Español: Logo de Nginx
English: Nginx Logo Español: Logo de Nginx (Photo credit: Wikipedia)
This post explains how to install nginx and gunicorn for django under linux Debian.

From my readings, nginx should be used to serve static files. Nginx should proxy all other requests to gunicorn.

These two tools are easy to install on my debian squeeze:

sudo apt-get install python-software-properties -y
sudo apt-get install nginx
sudo apt-get remove apache2
sudo apt-get autoremove
pip install gunicorn

Then we have to configure nginx. For this part, I relied on a the following tutorial.
sudo vim /etc/nginx/nginx.conf

I did not change this file as default configuration options seemed reasonable. At this stage, the 'it works page' should be served on localhost:
firefox http://127.0.0.1/ &

Then we have to tell nginx where the static files are located, and what URL to use to proxy other
requests to guincorn. As I use nginx for a single site, I edit directly the default configuration file:
sudo vim /etc/nginx/sites-enabled/default 

In this file, I remove all the defined "location" directives. And I add the ones related to my django app, to the static files of its admin page, and to the static files (/home/toto/myapp/app/static/*):
    location /static {
root /home/toto/virtualenv_1/myapp/app/;
}

location /static/admin {
root /home/toto/virtualenv_1/lib/python2.6/site-packages/django/contrib/admin/;
} location / {
proxy_pass http://127.0.0.1:8888;
}

Then, I restart nginx:
sudo /etc/init.d/nginx restart

If you have an error such as:
Starting nginx: [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to [::]:80 failed (98: Address already in use)

try using the following command to see which server runs already, and kill it:
sudo lsof -i tcp:80

 Finally, we configure gunicorn. It's incredibly easy.

First, we edit django's settings.py according to the documentation and add "gunicorn" to INSTALLED_APPS. Set the value of the STATIC* variables to '' to the URLs served by Nginx as the static files are all served from nginx. Modify also urls.py to remove the lines related to the static files. Then we simply launch the server:
./manage.py run_gunicorn
 
 
 
 
Share:
Read More
,

Celery and warning messages (print) to stdout

In this post, I will explain you how to use Celery and print warning messages to stdout.
Cross section of celery stalk, showing vascula...
Cross section of celery stalk, showing vascular bundles, which include both phloem and xylem. (Photo credit: Wikipedia)
If you use celery, you might be frustrated by the absence of the 'print' assertions that you put in your code for debugging. There is a very simple way to solve this point and see all print. As an added benefit, it will permit you to display nice warning in a python way :).

The solution is very simple!  Just import the warning package in the module that you call with celery:
 
import warnings 
 
 
Share:
Read More

How to install lxml (how to force easy_install to use a given version)?

Synaptic Package Manager 0.61 on ubuntu
Synaptic Package Manager 0.61 on ubuntu (Photo credit: Wikipedia)

To install lxml in your virtualenv, do:

sudo apt-get install libxml2-dev libxslt-dev
easy_install lxml==2.2.8



Share:
Read More

Using regexp (regular expressions) in python

Regular expressions are really useful whenever you want to search for or replace text in a file or a string. That means, all the time! They are concise, elegant, powerful and simple. So let's have a look to some examples.

I provide below a simple code example to show the usage of regular expressions in python.

import re
text= r"\begin{environment}"
left = r'\\begin'
right = r''
r=re.compile(left)
text=r.sub(right,text)print text

This code returns:
{environment}

Take care to the 'r' before the strings: they manage all the character escape subtleties for you (see http://docs.python.org/2/howto/regex.html for the explanations about the "backslash plague")

If you want to master regex, have a look to O'Reilly books, they are amazing.


Share:
Read More
,

Configuring IRC on pidgin

Screenshot de Pidgin pour un Wikilivre.
Configuring the famous Pidgin instant messaging client to support IRC is very easy on Linux Debian:
sudo apt-get install pidgin pidgin-otr

Open pidgin, add an IRC account with the nickname and password you want. For the server, you probably want to use:
irc.freenode.net

When that is done, go to contact > add a chatroom. In this dialog, select your IRC account in the drop down menu. Then, fill in the details, for instance the discussion might be #python. That's it, you'll see the chatroom in your contact list.

Some chatrooms require you to register your nickname. To do that, open the chatroom and type in the following message:
/msg nickserv help register

A new window should open and provide instructions on how to register your nickname.


Share:
Read More

Changing the size of geany's execution window

English: Python logo Deutsch: Python Logo
English: Python logo Deutsch: Python Logo (Photo credit: Wikipedia)
Xterm
Xterm (Photo credit: SiRGt)
Geany is a great Integrated Development Environmnent (IDE) for Python on Linux. I love everything in Geany except the size of the execution windows that opens when running a program: it is far too small.

To configure the size of the terminal in which Geany will run your Python programs, go to
edit > preferences > tools 
and change the terminal command to:

xterm -geometry 1000x600

If you do not like xterm, you can also chose another console type. For instance, you could use gnome terminal with the command below (but I prefer xterm).

gnome-terminal --maximize
Share:
Read More
,

How to convert html to text (html2text) in python

How to convert HTML code to Text with Python (solved)

There are several tools to convert html to text (html2text) in python. My favorite is beautiful soup. Under linux systems, you install the beautiful soup python module with the following two commands:
easy_install beautifulsoup4
easy_install html5lib

Then, in your source code, you can call beautiful soup functions to translate html text into simple text (removing all the HTML tags or replacing them with alternative relevant content) :

html_doc = """Some HTML code that you want to convert"""
from bs4 import BeautifulSoup
soup = BeautifulSoup(html_doc)
print(soup.get_text())

Of course, you need to import the module if you want to call its functions. That the role of the line in bold above (from bs4 import BeautifulSoup).

Html-source-code
Html-source-code (Photo credit: Wikipedia)

Alternatives to BeautifulSoup to implement HTML2text

Striptogram might be an alternative to beautiful soup, but I must say, I am fully satisfied by beautiful soup.

from stripogram import html2text, html2safehtml
# Only allow <b>, <a>, <i>, <br>, and <p> tags
clean_html = html2safehtml(original_html,valid_tags=("b", "a", "i", "br", "p"))
# Don't process <img> tags, just strip them out. Use an indent of 4 spaces
# and a page that's 80 characters wide.
text = html2text(original_html,ignore_tags=("img",),indent_width=4,page_width=80
 
 

 

If you want to improve your coding skills, I advise you to look at "Cracking the Coding Interview: 150 Programming Questions and Solutions". It was written by Gayle Laakmann McDowell, a former recruiter from Google who also worked at Apple and I find it really great!

  
Share:
Read More