POP Keywords: apache oracle sybase ...

unix – find all files in folder with or without size

To find all files (without following symlinks): find -P . -type f To find all files along with their corresponding size in bytes: find -P . -type f -exec stat -c ‘%s      %n’ {} \; sources http://askubuntu.com/questions/460210/using-find-and-stat-to-display-filenames-and-statistics

Unix – find files modified on a specific date / between two dates

“find” command is our friend here, using “-newer” argument. This is a 2-step process: create reference file(s) with required date limit(s) run find command with reference to this/these file(s) find all files modified after 2015/12/15 6:51pm and 2 seconds touch -t 201512151851.02 /tmp/t find . -newer /tmp/t find all files modified between two dates touch -t <date1> /tmp/t1 touch -t <date2> /tmp/t2 find . -newer /tmp/t1 -and -not -newer /tmp/t2 sources http://stackoverflow.com/questions/158044/how-to-use-find-to-search-for-files-created-on-a-specific-date

oracle – truncate tables based on select query

PL/SQL allows to execute sql statements using a FOR loop, looping through results of another query. In below example we truncate all tables returned by another query: — Q1: empty all audit tables –/ BEGIN — Disable constraints — Truncate tables returned by SELECT query FOR entry IN ( SELECT table_name FROM user_tables WHERE table_name like ‘%AUDIT%’ — and rownum < 3 order by table_name ) LOOP –EXECUTE IMMEDIATE ‘select * from ‘ || entry.table_name || ‘ where rownum < 10’; EXECUTE IMMEDIATE ‘truncate table ‘ || entry.table_name; END LOOP; — Enable constraints END; / Note: make sure to enclose […]

django – how to empty database [SOLVED]

To empty the database, simply run: python manage.py flush To force command line w/o having to confirm: python manage.py flush —noinput sources http://stackoverflow.com/questions/10605940/what-is-the-django-command-to-delete-all-tables https://github.com/django/django/blob/master/django/core/management/commands/flush.py

django rest framework – ensure foreignKey field is optional [SOLVED]

I am using ModelSerializers and faced hardtime ensuring foreign key could be optional: models.py: class Tag(models.Model): label = models.CharField(max_length=100) group = models.ForeignKey(TagGroup, null=True, blank=True, related_name=’tags’ class TagGroup(models.Model): label = models.CharField(max_length=100) serializers.py: class TagSerializer(serializers.ModelSerializer): class Meta: model = Tag fields = (‘id’, ‘label’, ‘group’) group = TagGroupSerializer() class TagGroupSerializer(serializers.ModelSerializer): class Meta: model = TagGroup fields = (‘id’, ‘label’,) With above setup, though foreignKey field is clearly defined as nullable and not-mandatory in models.py, i kept getting following error: ‘{“group”:[“This field may not be null.”]}’ Reason for this is that you also need to specify field as nullable and non-mandatory in the […]

Configure apache to run a django framework based project [solved]

To serve django via apache, using mod_wsgi (recommended option by django documentation), proceed as follow: install apache mod_wsgi: sudo apt-get install libapache2-mod-wsgi-py3 ensure mod_wsgi is indeed into /etc/apache2/mods-enabled: ls -l  /etc/apache2/mods-enabled/ | grep “wsgi” create a python virtualenv for your project (see Run python virtualenv with Ubuntu) go to /etc/apache2/sites-available and create file myproject.conf: sudo vi /etc/apache2/sites-available/myproject.conf Paste following content: <VirtualHost *:80> ServerName mydomain.com ServerAdmin webmaster@localhost DocumentRoot /path/to/myproject ErrorLog ${APACHE_LOG_DIR}/myproject.error.log CustomLog ${APACHE_LOG_DIR}/myproject.access.log combined Alias /static/ /path/to/myproject/static/ <Directory /path/to/myproject/static> Require all granted </Directory> <Directory /path/to/myproject/myproject> <Files wsgi.py> Require all granted </Files> </Directory> WSGIScriptAlias / /path/to/myproject/myproject/wsgi.py WSGIDaemonProcess myproject python-path=/path/to/myproject:/path/to/myproject/virtualenv/lib/python3.4/site-packages WSGIProcessGroup myproject </VirtualHost> […]

Run python virtualenv with ubuntu

By default, my ubuntu runs python2.7 (i.e. simply run python –version). This comes from /usr/bin/python –> /usr/bin/python2.7 I changed the link to point to python3 instead. BIG MISTAKE Python is used all over the place by the system => apt-get update kept failing so I had to revert back to python2.7 link To use virtualenv with python3, things are pretty easy, you simply need to prefix your commands: sudo apt-get install python3-pip sudo pip3 install virtualenv To create a virtualenv: Go to folder where you want to create the virtual env: cd /path/to/my/project To create virtual env, run: virtualenv-3-4 myvirtualenv […]

install lxml inside python virtualenv [solved]

When trying to install lxml inside virtualenv, I kept getting some compilation error messages. I already had lxml installed outside virtualenv, i.e. in my global python library. I got it installed via running: sudo apt-get install python-lxml This is of no use when using virtualenv since by definition each virtual environment will have it’s own libraries. As mentioned, pip failed when running: pip install lxml Error message: In file included from src/lxml/lxml.etree.c:239:0: /tmp/pip-build-gc7tlt4f/lxml/src/lxml/includes/etree_defs.h:14:31: fatal error: libxml/xmlversion.h: No such file or directory #include “libxml/xmlversion.h” ^ compilation terminated. Reason it is occurring is because when installing lxml python library, a compilation occurs. […]

[django] add new field on serializer which is not defined on underlying model instance [SOLVED]

To add a field which will be computed on Serializer itself without flowing through underlying model instance, declare it as follows: class DbconfigExtendedSerializer(serializers.HyperlinkedModelSerializer): password_length = serializers.SerializerMethodField(‘getPasswordLength’) def getPasswordLength(self, instance): return len(instance.password) Simply declare your field of type serializers.SerializerMethodField(‘<method_name>’) and corresponding method will be called. sources http://stackoverflow.com/questions/18396547/django-rest-framework-adding-additional-field-to-modelserializer

[django] Could not resolve URL for hyperlinked relationship using view name “-detail” [SOLVED]

When trying to build my first rest-django app, i faced below error message, which was not easy to solve: Could not resolve URL for hyperlinked relationship using view name: “<model>-detail”. You may have failed to include the related model in your API, or incorrectly configured the `lookup_field` attribute on this field. For simplicity reason, below example is based on django-rest-framework tutorial, where project is named “tutorial” and one app called “snippets” is created inside this project After investigation, the following happens: in snippets/urls.py, ensure to use “name=” attribute as per below, and use the convention of ‘<model>-detail’ for detail view […]