07
Sep 11

Integrating libevent2.

We have used libevent2 in one of our projects, I must admit I’m impressed by its performance and ease of use, what could have taken us a couple of weeks to implement only took a couple of days using libevent2.

Now comes the issue of packaging and shipping our product, we realized that linking libevent2 statically with our binary was the most ideal solution since the license allows for it anyway.

We use CMake to build our products and libevent2 uses autotools, trying to build libevent2 with a custom CMake script as listed in this thread was a real PITA and it didn’t work out, it turns out that building it using autotools invoked from CMake was trivial, the only catch is that you need version 2.8.0+ of CMake and 2.8.3+ on Mac OS X for it to work.

Extract the libevent2 source to a directory in your project tree, I chose srclib/libevent , then add the following to your top level CMakeLists.txt

include(ExternalProject)
ExternalProject_Add(
libevent
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/srclib/libevent
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/srclib/libevent/configure
PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/srclib/libevent
BUILD_COMMAND make
BUILD_IN_SOURCE 1
)

now when it comes to linking, I used the following when building the binary, where ‘tumbak’ is the binary


target_link_libraries(tumbak ${PROJECT_SOURCE_DIR}/srclib/libevent/.libs/libevent.a)


10
Apr 11

Bush -Letting The Cables Sleep (N.O.W Remix)

This is one of the most amazing chillout songs I’ve listened to =)


05
Jan 11

Hacking History & Introduction Presentation

This is the presentation that I made on the 4th of Jan 2011 for AmmanTT Hacking Edition.


12
Oct 10

Purging Old ActiveRecord Sessions.

Using ActiveRecord::SessionStore has many benefits but the darwback is that sessions’ data can build up in the table resulting in 10,000+ entries if the application is moderately used, the easiest way to delete old stale sessions is by using the following code snippet.

class SessionCleaner
  def self.remove_stale_sessions
    ActiveRecord::SessionStore::Session.destroy_all( ['updated_at <?', 3.hour.ago] )
  end
end

Stick this code in a file called sessions_cleaner.rb in your /lib folder and execute is using the runner script, you can also schedule it using crontab, make sure you give it the full path though

script/runner -e production "SessionCleaner.remove_stale_sessions"

27
Sep 10

Embedding Google Analytics Charts Into A Rails App

It is a straight forward operation to be honest, it took much reading and much less code to get it done, hope this saves some other folks some time.

This is how it’s gonna look like in the end

highcharts

Continue reading →


13
Sep 10

Palyrria – Nilos Dub Desert Mix


30
Jun 10

Handling Ajax Form Validation in Rails

Handling Ajax requests errors isn’t documented really well and there are many ways to accomplish this, some are simple and some are pretty darn complicated.

the easiest solution I found was rendering different partials depending on the status of the save or update methods, here is a snippet

  def update
    @bid = Bid.find(params[:id])

    respond_to do |format|
      if @bid.update_attributes(params[:bid])
        flash[:notice] = 'Bid was successfully updated.'
        format.js { render :partial => "update" }
      else
        format.js { render :partial => "update_fail"}
      end
    end
  end

It may not be the most elegant solution but is sure simple and does what it says it does.


29
Jun 10

The state of ISPs in Jordan.

This is one of the most frustrating issues in Jordan (that is, to a geek ofcourse), all the ISPs suck, they literally suck your life and money out of you in exchange of a crappy service.

I’ve been an ADSL user for 5 or 6 years, I don’t remember to be honest, here is my take on the ISPs that I have used:

  1. TeData: they used to provide a decent service for the bucks you paid them, it was the only ISP that WoW didn’t massively lag on, I switched because their connection would drop for hours at time, the authentication would not succeed and all they did was to blame JTC, and ofcourse JTC would blame them in return, a very ugly and vicious cycle.
  2. Sama Telecom: their price is the lowest in the market I believe, their package of 10G per month is quite low, I believe that is their only package whether you have 128kb or 2mb, they claim that from 8PM till 8AM you can download to your hearts content, this is simply a lie, my 2mbps connection gets capped at 128kb even at night, I called to ask them why am I capped even after 8PM, they said I’m on their blacklist, yup, they said I download too much so I had to be put on this list so I don’t disturb the service for other users.

Following are some other ISPs whom my friends and family members have used and shared their experiences:

  1. Orange: if there is one massive incompetent company then its hand-down Orange, it takes them at least 72-96 hours to resolve any issue, during this time you have no connection whatsoever, my friend decided to upgrade to their double plan over 2mbps, oh my he was sorry for that, it took them 3 weeks to upgrade his line, and then a massive 4 weeks just to upgrade his account, in the end it all failed miserably and they had to issue a new account for him , he got so pissed that he wanted to cancel but behold, he couldn’t get a single penny back, bearing in mind that he paid a full year in advanced, that is the only way you can get the double plan.
  2. Mada WiMAX: we use this one at the office, they claim 2.4mbps speed but the best we could get is 0.8mbps even though the tower is like 1 kilometer away from the office and signal strength is quite good, their price is not very high but I wouldn’t recommend their service because of the speed you will be getting.
  3. Jordan Cable Services: their connection speed is amazing, we got a 512 connection and we were delivered 512, their price is alright, no limitation whatsoever on the downloads, the only problem is that they only cover Gardens Street.

If you would like to share your experiences and comments please do.


10
Apr 10

متى تغضب؟

متى تغضب؟

د . عبد الغني بن أحمد التميمي

أعيرونا مدافعَكُمْ ليومٍ… لا مدامعَكُمْ

أعيرونا وظلُّوا في مواقعكُمْ

بني الإسلام! ما زالت مواجعَنا مواجعُكُمْ

مصارعَنا مصارعُكُمْ

إذا ما أغرق الطوفان شارعنا

سيغرق منه شارعُكُمْ

يشق صراخنا الآفاق من وجعٍ

فأين تُرى مسامعُكُمْ؟!


27
Mar 10

Migrating from Facebook Page to WordPress.

Facebook has decided to close our group for political reasons, I’m not gonna discuss that here because its their site in the end and they can run it in whatever way they want, all we can do is become less dependent on facebook and migrate our stuff from there, from now on, I will think twice about posting any useful content on facebook and I will recommend everyone else to do just the same.

So we needed to pull out all the notes from the page we had, totalling 454 notes, there is no export functionality in facebook only an RSS feed that would give you the last 10 items.

So I found a post that shows how to use the API test tool to query the FB database, the relevant query is

SELECT note_id, title, created_time, content FROM note WHERE uid = 0000000000

and change the uid into the id of the facebook page you want.

I was able to get all the notes in XML format, now in order to get those into wordpress we need to import them, here is a post that shows a generic xml parser for wordpress, I had to change the script a bit to make is understand fb’s xml format.

here is the file xmltowp.php

Update: 20100402
Now we have migrated our photo albums from facebook aswell, its a bit more complicated but hey, it works :)
here are the queries for the FB API tool, first get your albums

SELECT name,aid FROM album WHERE owner = 00000000

next use the album ID to get the photos info for each album alone

SELECT pid, aid, src_big, src_big_height, src_big_width, link, caption, created, modified, object_id FROM photo WHERE aid= '00000000_00000'

now we have an XML file with all the photos info, lets get the URL and get all the files

$grep '<src_big>' album.xml > urls

in VIM do the following substitutes on the urls file

:%s/    <src_big>//g
:%s/<\/src_big>//g

now feed the urls file to wget through the -i option.
I have used the NextGEN gallery module for WordPress, using that I was able to import whole folders, the folders where wget saved all those photos. Now to get the captions of the original photos in WordPress aswell I have written a small ruby script that parses the albums.xml and generates an SQL file that you need to execute against your wordpress DB, here is the code, ugly but works

#!/usr/bin/ruby

require "rexml/document"
include REXML

file = File.new( "album.xml" )
doc = Document.new file
output = ""
doc.elements.each("*/photo") { |element|
  filename = ''
  caption = ''
  XPath.each( element, "src_big") { |src| filename = File.basename(src.text) }
  XPath.each( element, "caption") { |cap| caption = cap.text }
  output << "update wp_ngg_pictures set description = '#{caption}', alttext='#{caption}' where filename='#{filename}';\n"
}
outfile = File.new("update.sql", "w")
outfile << 'SET CHARACTER_SET_CLIENT=utf8;'
outfile << 'SET CHARACTER_SET_CONNECTION=utf8;'
outfile << 'SET CHARACTER_SET_RESULTS=utf8;'
outfile << output

hope this helps someone in need.