-
Boost Django running unit testing faster with mysql database loaded into Ramdisk / Memory
Running unit testing in Django using “python manage test ” is not enough. Usually unit-testing takes a lot of time to make it done. FYI, I use Fedora 17 and MySQL for my development and usually, it takes about 2-4 minutes to get testing on single application done. Using SQLite is not good option since […]
-
How to compare and get only the matched between two list in Python
There is conditions when we need to matching two of big list of data which it’s called “intersection”. Python is a great language which provide many ways to achieve solution of this problem. First, we have the list datasets: 12first = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] second = [2, 4, […]
-
Solving Django fixtures unit testing load data IntegrityError: (1452, ‘Cannot add or update a child row: a foreign key constraint fails using INNODB engine
When you’re using MySQL with InnoDB for unit-testing, you may stumbled into this problems when try loading fixtures in test case. 1IntegrityError: (1452, ‘Cannot add or update a child row: a foreign key constraint fails (`DATABASE`.`TABLE_NAME`, CONSTRAINT `COLUMN_id_refs_id_ea62e552` FOREIGN KEY (`room_id`) REFERENCES `ANOTHER_TABLE` (`id`))’) You may solve this problem with this quickfix solution: 1. Change […]
-
Solve python OSError: [Errno 24] Too many open files: ‘/dev/urandom’
When you’re using random intensively, then at some conditions, you will get this errors: 1OSError: [Errno 24] Too many open files: ‘/dev/urandom’ And this will makes another tasks that need to generate random getting affected. To solve this issue, you need to raise OS-level limitation of /dev/random or /dev/urandom. I use Fedora 17 at this […]
-
Understanding Getter and Setter in Java
Getter and Setter is new things for me since I have experience in Python which all attribute in a Class can be invoked anytime. It’s different in Java which all data should be thread-safe and manipulation between data should be isolated and not interfere another process/task. Btw, did i mean “encapsulation” here? Well, there are […]
-
Solve how to compile and run Java in SublimeText 2
I found a lot of people discussing about how to compile and run the results of Java (single file) in SublimeText 2. Well, after trying another alternative and failing, finally I found how to make it works. It’s easy actualy, all you need are: 1. Edit SublimeText2 Java Build 1~/.config/sublime-text-2/Packages/Java/JavaC.sublime-build
-
Solve slow DNS in HpCloud due to double reload on the website
I found something weird with my Bind in HPCloud which it’s working well in my EC2. After trying several experiment, I found the correct way to set bind in HPCloud. This is for example: 1234567891011121314151617; ; BIND data file for local loopback interface ; $TTL 3600 @ IN SOA […]
-
Configure Phpmyadmin in NGINX to combine with NODEJS or another non-php applications
Configuring Phpmyadmin to be able working with another non-PHP applications is a little bit tricky. For instance, you have NODEJS application running in NGINX with root (“/”). When you’re opening http://yourdomain.com, then it will running NODEJS applications. Then, you want to make this domain have “/phpmyadmin” which it will running phpmyadmin. At this steps, you […]
-
Export SELECT WHERE query MYSQL into .sql files using mysqldump
You will need this scripts if you have two databases and want to synchronize each other. First, we need to export SELECT QUERY into .sql files by: 1mysqldump –databases DATABASE_NAME –tables TABLE_NAME –where=’YOUR_COLUMN_NAME IN ("SOME-ID", "SOME-ID")’ -u root -pYOUR_PASSWORD > data.sql The last thing, you need to edit this “sql” files and change the DATABASE_NAME […]
-
Django test form errors and validation results in Unit Testing
Testing forms in Unit testing Django is necessary and important. Instead of using “self.client” for opening URL, we can post data into form in the webpage. We want to testing different input into forms and seeing how forms handle these input. Here is an example how to testing form in Django unit-testing: 123456789101112131415from django.test import […]
-
Test Django session in unit testing for created and modified session by views
Sometimes we need to test Django session in our unit testing to see that view already modified / created a session. Basically, we only need to use File Backend Storage to handle sessions that made in Unit testing. So, let starts with create a new test : 123456789101112131415161718192021222324from importlib import import_module from django.test import TestCase […]
-
Solving Alacarte can’t open gi._glib.GError: Error opening file: No such file or director in Fedora
I see a lot of people have problem with alacarte but seems nobody know how to fix it quickly. When you run “alacarte” from your command line, you will see : 123456789101112131415161718Traceback (most recent call last): File "/usr/bin/alacarte", line 36, in <module> main() File "/usr/bin/alacarte", line 33, in main […]
-
Solve Fedora 17 boot problem repair filesystem fsck
It’s weird when my Fedora suddenly crash and it’s give this error message when boot-up and asking for “repair filesystem”: 123456789101112Loading initial ramdisk… _Fedora-16-Beta-: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY. (i.e., without -a or -p options) dracut Warning: e2fsck returned with 4 dracut Warning:_Fedora-17-contains a file system with errors, check forced. dracut Warning:_Fedora-17: Inodes that were […]
-
Solve local settings not being imported from settings.py in Django
Usually we create local_settings.py for overwrite settings.py configuration due to environment or custom conditions. We can put local_settings.py into django project that have same place with settings.py. To load local_settings.py, we can use : 1234try: from local_settings import * except ImportError: pass But problem come when local_settings not being called by […]
-
Create an independent Python logger and save reports into file
This is just a trivial task which we want to run a python files and logging all actions. We want to save all the reports into file. Then, you can just doing this way: 12345678910111213import os import logging logger = logging.getLogger(‘test’) log_path = os.path.abspath(os.path.join(os.path.dirname(__file__), ‘test.log’)) log_file = logging.FileHandler(log_path) formatter = logging.Formatter(‘%(asctime)s %(levelname)s %(message)s’) log_file.setFormatter(formatter) logger.addHandler(log_file) […]
-
Solve MYSQL: Cannot delete or update a parent row: a foreign key constraint fails InnoDB when DROP table
There is conditions when we need to remove table / data in InnoDB and replaced with the new one. But the problems is, you will facing this error when DROP table that contain relational data : 1MYSQL: Cannot delete or update a parent row: a foreign key constraint fails How to solve this? It’s actually […]
-
ValueError: “unsupported format character ‘a’ (0x61) at index 9” in Python
Do you ever got this error message when running code like: 1print("Hello world this should be a long paragraph and you need %s, %s and some of % needed by %s" % (var1, var2, var3, var4)) Well, when this problem show-up, it’s not about Unicode and you should convert all variable value into ASCII. This […]
-
Solving retrieve objects from Amazon S3 using boto get_all_keys() and get limited results
When you have more than 1000 objects in S3, you will realize that get_all_keys() doesn’t give you all objects you have. This is because get_all_keys() have limitation. To fetch / retrieve all objects, please using list(). For example : 1234s3 = boto.connect_s3() bucket = s3.get_bucket(‘your-bucket-name’) for obj in bucket.list(): print obj.name Now you […]
-
Solving Bind DNS un-resolved when nslookup domain without WWW
This is common mistake when we try to nslookup our domain that working with “WWW” but not without “WWW”. This is some bind9 configuration : 123456789101112131415; ; BIND data file for local loopback interface ; $TTL 3600 @ IN SOA obroll.com. admin.obroll.com. ( […]
-
Convert string with tuple format into tuple objects in Python
There will come condition when you have MySQL data that have structure like tuples in Python. For example, given data in categories.txt: 123456789101112131415161718192021(‘Woodenware’, 2594), (‘Woodworking’, 2595), (‘Woodworking Equipment and Supplies’, 2596), (‘Word Processing Service’, 2597), (‘Work Clothing – Retail’, 2598), (‘Work Clothing – Whol and Mfrs’, 2599), (‘Wrecker and Towing Services’, 2600), (‘Wrecking Contractors’, 2601), […]
-
Setup Amazon S3 backup system using Python with BOTO in Fedora
Boto (https://github.com/boto/boto) is a must have tools when we need to communicate with Amazon Services using Python. Before we start, FYI, I use Fedora 17 in this articles. That’s mean several code may doesn’t works in your Linux OS (If we have different OS). But there are should be a minor issue since there no […]
-
Why function overloading in Python doesn’t works meanwhile overriding is okay?
This is basic question that frequently asked by a lot of people who learning Python. Basically, we know there are two method when calling function inside class : 1. Method Overriding This function overiding allow Child or derived class to overwrite function in Parent class by define same function. This is common thing in inheritance […]
-
Using Gevent to fetch urls website with python using non-blocking method
I have a lot urls links and need to check which one that have 404 (Not Found) or Server Down. With python, everything looks possible and easy. We can use simple urllib2 module to fetch webpages based on given links. But, problem comes when we dealing with IO Bound. When we iterating links and doing […]
-
How to replace primary storage with new EBS in Amazon EC2 instance
This based on the need, we want create a big EBS, remove the old 8GB EBS and replace with the new one as primary storage. Using new EBS storage as primary is a little bit tricky and you should carefull when doing this. We should be careful when upgrading EBS storage in Amazon EC2. Make […]
-
Make stand-alone python scripts to load Django environment
Sometimes we need to make some executable scripts inside Django applications that standalone and independent. Usually this for generate / processing data without accessing / open any Django views. For instance, I have “Posts” application, I need to modified all Post and send them to some 3rdparty. So, this will be: 1234project |___ posts […]