May 29, 2016
Change and rebuild an RPM on CentOS
Test
sudo yum groupinstall "Development Tools"
sudo yum install epel-release.noarch
sudo yum install yum-utils rpmdevtools
mkdir -p ~/rpmbuild/{SOURCES,SPECS}
wget http://example.com/lame-3.99.5.tar.gz
mv lame-3.99.5.tar.gz ~/rpmbuild/SOURCES
rpmdev-newspec lame
mv lame.spec ~/rpmbuild/SPECS
cat < < EOF > ~/rpmbuild/SPECS/lame.spec
# ------------------------------------------------------------
Name: lame
Version: 3.99.5
Release: 1%{?dist}
Summary: LAME MP3 Encoder
License: N/A
Source0: lame-3.99.5.tar.gz
%description
Educational tool to be used for learning about MP3 encoding. LAME aims to be the basis of a patent free audio compression codec.
February 17, 2016
Limit String Length in Printf in C
I can’t believe how many times I forget this trick! so I am writing it down so I won’t forget it!
Normally when you use printf function with “%s” formatting to print a string (char *) you rely on C convention of terminating a string with a NULL character (i.e. value 0).
So if you want to print small part of longer string, you copy the part you need to a new buffer and terminate it will NULL.
January 31, 2016
Django: How to pass an url as parameter of include
In Django web applications I usually have a single template file for navigation or bread crumb that I include from other template files, it is easy and straight forward to pass parameter to the included template file, some thing like:
{% include "nav.html" with title="title" object=my_object %} But it would be a little tricker to send a URL as a parameter, i.e. you can’t write it:
{# WRONG DOESN'T WORK #} {% include "nav.
January 25, 2016
Django CRUD Parent/Child Edition
I’ve written before about implementing CRUD operations on a single table in Django, and the post was very popular on my blog and I hope many people learned something from it.
The next logical step is to write a CRUD application with Parent/Child relationship, the application is bit more verbose but it follow the same simple logic used in the first post.
In fact I didn’t write a single application, I wrote five stand alone applications that shows different ways to implement CRUD operations:
August 30, 2015
اقتراحات لتفعيل خدمة لاسلكي الهواة
كتبت رسالة الى معالي الدكتور محمد السويل وزير الاتصالات باقتراحات لتفعيل خدمة لاسلكي الهواة او ما يعرف بـ “Amature Radio” او “Ham Radio” ردا على طلبه للعموم باقتراحات لتطوير خدمة الاتصالات في المملكة:
https://twitter.com/MIsuwaiel/status/580704446520291328
وفي ما يلي نصها، للتاريخ وكذلك كمرجع لي.
السلام عليكم ورحمة الله،
معالي الدكتور محمد السويل اكتب لكم بمقترحات لتشجيع خدمة لاسلكي الهواة في المملكة العربية السعودية.
قبل قرابة السنتين احببت ان اتعلم تقنيات اللاسلكي ولاسلكي الهواة لاكتشف عدة عوائق لاستخدام الخدمة في المملكة.
June 14, 2015
My first public Python Package “pyagentx”
I’ve just published my first public Python package “pyagentx”, the package will help you build “AgentX” agents to extend a master SNMP agent.
Let’s assume that you want to monitor your custom application from your Network Managment System (NMS), but the NMS only speak SNMP, this package allows you to extend the master SNMP agent to include your custom application metrics.
Project page on Github
Package page on Python Package Index
April 19, 2015
Django Image and File Field Caveats
Every time I work with Image or File fields in Django I forget some tiny detail that waste 10-20 minutes until I remember what was I missing, I always say I will remember it next time but I never do! so I made a list of common errors I keep doing while working with Image/File fields:
For complete working project: (https://github.com/rayed/dj-imagefield-example)
Setting MEDIA_URL and MEDIA_ROOT Make sure you set proper values for MEDIA_URL and MEDIA_ROOT in your settings.
January 22, 2015
Intro to Ansible Presentation
My presentation at Riyadh Linux User Group about Ansible
January 15, 2015
Git directory outside working directory
I have an old PHP website that I wanted to have its code/content versioned with Git, normally Git setup the repo directory in the “.git” directory inside the working directory, but I faced a problem, if the working directory is accessible from the web server it means “.git” is also accessible too.
Luckily git have an option to have the repo directory located somewhere else using the GIT_DIR environment variable, so here what I did:
December 31, 2014
Install psycopg2 (PostgreSQL adapter for Python) on OSX
I was playing with Django with Postgres backend, and I had little difficulty installing “psycopg2” the Python DB adapter for Postgres on my Mac OSX.
I’ve installed Postgres using Postgres.app for OSX which is straight forward and standard Mac app.
But when I tried installing “psycopg2” using “pip” (the python package manager) I got an error:
$ pip install psycopg2 : Error: pg_config executable not found. : I just searched for “pg_config” in my system: