Month: December 2011

Preg_replace regex delete tags link url completely with text inside using php

Preg_replace regex delete tags link url completely with text inside using php

We need to completely remove anchor links with text inside using PHP. Then, we can use preg_replace() and removing all tags links with string completely by : 1preg_replace(‘/<a[^>]*>(.*)</a>/iU’,”, $text); Or seconds alternative is : 1preg_replace(‘#(<a.*?>).*?(</a>)#’, ”, $text); Now you can remove / delete all anchor links 🙂

Solve Vagrant “The guest additions do not match the install version of VirtualBox”

Solve Vagrant “The guest additions do not match the install version of VirtualBox”

After upgrading my Virtualbox, I try build my base box and got this errors : 12345678[ff] The guest additions on this VM do not match the install version of VirtualBox! This may cause things such as forwarded ports, shared folders, and more to not work properly. If any of those things fail on this machine, …

+ Read More

Running WordPressure NodeJS in EC2

Running WordPressure NodeJS in EC2

Today I see Dchud release WordPressure, NodeJS + Python apps which aggregate new post in WordPress.com Real-time. Curious how it would be, then I put my unused domain ani-rss.org as my experiments. I use Amazon EC2 with Ubuntu 11.10 64bit (Oneiric). So, here are the steps. 1. Install base packages 1sudo apt-get install git redis-server …

+ Read More

Solving could should increase server_names_hash_bucket_size: 32 NGINX Ubuntu

Solving could should increase server_names_hash_bucket_size: 32 NGINX Ubuntu

After I configure several sites that have a long names in NGINX virtualhost, I restart my NGINX and got this error : 123sudo service nginx restart Restarting nginx: nginx: [emerg] could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32 nginx: configuration file /etc/nginx/nginx.conf test failed Well this is because my NGINX conf only limit …

+ Read More

How to receive reset password hpcloud by whitelist email in gmail account

How to receive reset password hpcloud by whitelist email in gmail account

Yesterday, I wanna login into my hpcloud account and accidentally forgot my password. Then I go to forgot password page and put my email there. Waiting for more than 3 hours, there no confirmation email yet from HPCloud in my Gmail inbox. Try with three times and no result yet. Event spambox still empty. Then …

+ Read More

How to use reverse URL names without resource_name Django tastypie

How to use reverse URL names without resource_name Django tastypie

Using reverse URL in Django-tastypie with names will ease our development or making unit test. When I wrote this, I was helped by Joshbohde from Django-tastypie IRC. So, if you have some problem when using Tastypie, I suggest you ask to via IRC. I have APP/insurance here for example. By default, I can access Django-Tastypie …

+ Read More

How to run cron and execute function inside plugin in WordPress 3

How to run cron and execute function inside plugin in WordPress 3

Running cronjobs in WordPress is easy but seem there are lack of documentation that talking about this. Especially, if we want to running our custom plugin in WordPress from our cronjobs. Actually, there are two methods of running cron in WordPress. First, it’s running from loaded pages. Seconds, it’s running through cron UNIX servers (wget, …

+ Read More

Setup VPS / Server from beginning for WordPress sites with NGINX + MySQL Ubuntu

Setup VPS / Server from beginning for WordPress sites with NGINX + MySQL Ubuntu

I will guide you about how to setup brand new VPS / Server to host WordPress with optimize configuration. I prefer use NGINX + MySQL here. Remember, I start from zero configuration with mean no software installed , no pre-installed program and default Ubuntu. If you want to install several VPS / Server, then you …

+ Read More

Download image and attach into post programmatically in WordPress 3

Download image and attach into post programmatically in WordPress 3

All we know, we can use wp_insert_post() to create content programmatically in WordPress. But, there more magic goodies bag in WordPress. We can download images and attach into post programmatically by using media_sideload_image(). There are several issue while using this function because lack of documentation about how to implement it. The common error when using …

+ Read More

Run latest PhantomJS with shell_exec PHP on Ubuntu 11.10 Oneiric

Run latest PhantomJS with shell_exec PHP on Ubuntu 11.10 Oneiric

Running PhantomJS with exec() or shell_exec PHP and grab it results may lead you into several headache problems. Several web that talking how to run phantomjs in PHP just send me into fail results. I will show you several pitfalls for instance, here a small scripts to run PhantomJS : test.php : 1234<?php $result = …

+ Read More

Learn how to make custom filter debug variables with ipdb in Django 1.3

Learn how to make custom filter debug variables with ipdb in Django 1.3

Template filter in Django is great. We usually use it when processing variable that passed from views into templates. There are several built-in filters in Django that powerfull to process variable in templates. You can see them on https://docs.djangoproject.com/en/1.3/ref/templates/builtins/#ref-templates-builtins-filters. Here are some basic template filter eg : 1{{ bon|upper }} If you already have debug …

+ Read More

Separate settings.py while developing many apps in Django for your sake

Separate settings.py while developing many apps in Django for your sake

Developing many apps in Django can’t avoided when system getting large and growing. Usually, a new Django developer put all configuration of several APPS in “ONLY” settings.py. Is this wrong? No! Is this effective ? Not really!. What I mean, you will have no problem if APPS just sit in development stage. But, when you …

+ Read More

Install python PIL ( Python image Library ) on Ubuntu 11.10 Oneiric

Install python PIL ( Python image Library ) on Ubuntu 11.10 Oneiric

Installing PIL in Ubuntu 11.10 Oneiric 64-bit using pip raise problem on JPEG, Zlib or freetype support. First, you need to uninstall PIL by : 1sudo pip uninstall PIL Then you should install default Ubuntu packages : 1sudo apt-get install libjpeg8 libjpeg62-dev libfreetype6 libfreetype6-dev We should fix PIL path libraries by : 123sudo ln -s …

+ Read More

Solve “error_message”: “‘WSGIRequest’ object has no attribute ‘items'”

Solve “error_message”: “‘WSGIRequest’ object has no attribute ‘items'”

When you need to pass “request” into some instance, maybe on Django-haystack or some another django apps, somehow you got this kind of error : 12"error_message": "’WSGIRequest’ object has no attribute ‘items’", "traceback": "Traceback (most recent call last):nn File "/usr/local/lib/python2.7/dist-packages/tastypie/resources.py", line 192, in wrappern response = callback(request, *args, **kwargs)nn File "/home/vagrant/htdocs/ff/airport/../airport/services/api.py", line 61, in get_searchn …

+ Read More

Solve psycopg2.ProgrammingError: autocommit in Django 1.3.1 + Postgresql run test

Solve psycopg2.ProgrammingError: autocommit in Django 1.3.1 + Postgresql run test

When I test my django application which use Postgresql and using python-psycopg2 (Ubuntu 11.10) as wrapper, I got this kind of error : Run python manage.py myapp : 1234567Creating test database for alias ‘default’… Traceback (most recent call last):   File "manage.py", line 14, in <module> File "/usr/local/lib/python2.7/dist-packages/django/db/backends/creation.py", line 481, in set_autocommit     self.connection.connection.autocommit …

+ Read More

Deep Dive into Python Path Construction

Deep Dive into Python Path Construction

Today I found great tutorial that explain how sys.path is working. Follow this link to see through : If a script is executed, the interpreter sets the first entry of sys.path to that script’s directory. If Python is launched interactively, the first entry is the empty string (“”), meaning Python will scan the present working …

+ Read More

Creating Form automatically with ModelForm in Django 1.3

Creating Form automatically with ModelForm in Django 1.3

Building form in Django 1.3 is pretty easy with ModelForm. Basically, when we create Model, it will need some CRUD from then. Django give Modelform to ease our steps from defining forms which may have same description with models. For instance, I have models.py which contain Query models : 123456789101112from django.db import models from django.forms …

+ Read More

How to saving dict into models in Views Django

How to saving dict into models in Views Django

If you deploy views and need to saving data into models, you should considering dictionaries type rather with standard. For instance, this is standard way to save data into django models : 12345# This is standar way def index(request):     mymodel = Bug(qid = ‘1’, subject = ‘subject’,             …

+ Read More

Understanding about namespaces, attributes and scopes in Python

Understanding about namespaces, attributes and scopes in Python

I assume you don’t understand about namespaces, attributes and scopes in Python. Because I will explain about this three things that mostly missed by people who start learning with Python. Actually, this things will help us in the future about understanding Python even for advanced programmer. So, let begin with namespaces. Namespaces according to Wikipedia …

+ Read More

How to Install Django 1.3.1, Apache ModWSGI and PostgreSQL in Ubuntu Oneiric 11.10

How to Install Django 1.3.1, Apache ModWSGI and PostgreSQL in Ubuntu Oneiric 11.10

Full guide to build Django 1.3.1, Apache2 + ModWSGI and PostgreSQL in Ubuntu 11.10 Oneiric. There are several dependencies packages, python modules and a little configuration to make Django run with PostgreSQL. Let start! 1. Install dependencies Ubuntu packages We need to install base packages, python modules, postgresql , apache2 and mod-wsgi. 12345sudo apt-get update …

+ Read More

The right configuration virtualhost for Apache + ModWSGI run Django

The right configuration virtualhost for Apache + ModWSGI run Django

We know that Django doesn’t serve files itself. Django suggest us to run separate Web server for running media and another. We may use NGINX, Lighthttpd, Cheeroke or anothers. But, there it’s not wrong to host Django with Apache + ModWSGI. I use it for development which it have monitoring to our files and auto-reload …

+ Read More

Solving admin CSS not loaded or not found in Django

Solving admin CSS not loaded or not found in Django

When running Django with development server, open “/admin” will show perfectly without any problem. But, running Django with Apache + ModWSGI or NGINX + UWSGI, CSS admin not loaded and not found. So, Django admin showing plain without CSS. This problem is commonly happen when we deploy Django on production. Why this is happen ?

Learning how create regex URLCONF route in Django 1.3

Learning how create regex URLCONF route in Django 1.3

Few developers complaining about hard to create url routes in Django. Regex always like nightmare, but we must get along with it. And don’t worry, in Django 1.3, you doesn’t need to know whole knowledge about regex. Meanwhile, design url usually common and not to complicate. Know we see this example of URLCONF : 123456from …

+ Read More

Understanding Django Workflow, structure, files and deep inside

Understanding Django Workflow, structure, files and deep inside

Django is special framework that build base on Python. If you familiar with PHP Framework like CodeIgniter, CakePHP or another else, you will find Django is different. For futhermore explanation, I assume you using Ubuntu (I use 11.10) , know how to install Django and run through “python manage.py runserver”. Back to why Django is …

+ Read More

How to load urlconf route apps into projects in django 1.3

How to load urlconf route apps into projects in django 1.3

Django has special method to process URL and you can design the URL design however you want. To create URL design, you should create URLCONF modules. This modules will mapping url patterns to views. Before looking more, we should know about this basic things. How Django processes a request ? When a user requests a …

+ Read More

Deep understanding XML-RPC Server – Client in Python

Deep understanding XML-RPC Server – Client in Python

XMLRPC (XML Remote Procedure Call) which send XML through HTTP for transporting data is common way to communicate between Server and Client. Basically, Client can call methods with parameters on a remote server and get structured data for results. Python have XML-RPC standard library, which it’s mean native installed and ready to use. First, I …

+ Read More