Saturday, 31 March 2012

Power and temprature issues in Linux with NVIDIA Optimus

I have Dell Inspiron N5110 laptop which has OPTIMUS technology, so you can switch between NVIDIA GT525 and the Intel Chip. Unfortunately from what i have read, that technology is only supported on Windows and NVIDIA does not have the intention to support it on their Linux drivers ( kind of solved that problem for me when i need something on the NVIDIA chip).

From what i read both VGAs run at the same time because of that problem, causing power consumption is on its max and the machine really gets hot in no time with the fan is running without stop, so i have to stop one of the two manually. Fortunately there is a very simple tool that enables the job.

The tool is called acpi_call, with it you can issue acpi calls manually. I just cloned it locally and built it and then ran the following command to install the module.
 sudo insmod acpi_call.ko
and then
sudo depmod -a
They have already made test script called "", once i ran it the fan calmed down after 30 seconds or so. You have to run that tool every time you start your machine.

Note: that test script may not run on your machine so try the following link to get ACPI calls, that might help.

Sunday, 18 December 2011

Trying to use kanban as a lazy procrastinator

First of all i learned the word "Procrastinator" from Mike Elgan's blog post The ultimate productivity guide for lazy procrastinators (like me)!. Thanks Mike :).

I have been trying to adopt a method to at least organize my programming tasks and not my personal life tasks, my main problem is that i am easily get distracted with losing focus and interest in tasks in hand, that makes me multitask in many tasks as possible.

So i thought of trying to use some agile methodologies ideas like Scrum, but i really did not find things that are suitable for my needs because i think scrum's main concerns are release management and team management. also i found that kanban with its less constrains is mostly concerned with flow of tasks and how can make it as smooth as possible, and i found it can be a perfect match for me.

I will do it first for my personal pet projects. I will divide my project into user stories and i will be committed for completing the user story from start to end,  but for my kanban board i will limit my WIP stories in the DOING column to 2 or 3 for a start, so i have some freedom for my "lose of interest" thing :) but without losing total control of that.

What is your opinion?, any one tried that?

Sunday, 25 September 2011

Very simple ngspice circuit profiling framework using Google Perf Tools

I am trying to make some speedups in Ngspice the open source circuit simulator using CUDA and the GPU. I needed some profiling so i can determine which parts of Ngspice that have potential speed up and parallelization.

I used Google Perf Tools because it is really fast compared to Valgrind for example, despite being a Valgrind fan but i needed fast profiling because SPICE is very processing intensive.

Here is a very simple shell script that runs ngspice on every circuit in "circuits" directory and spits callgrind format to "profiling_info" directory. I used some of CircuitSim90 circuits & MCNC

To use it you should compile Ngspice for google profiler, so install google perf tools, and compile Ngspice using -lprofiler

./configure LIBS=-lprofiler
That script is for made on Ubuntu 11.04, the only difference for other distros will be the google profiler package and executable names.

sudo apt-get install libgoogle-perftools0 libgoogle-perftools0-dev google-perftools0 

If any one has a suggestion please feel free to tell me about it, also if anybody has a netlist for a big MOSFET circuit (1000+ MOSFETs) please tell me about it.

Thursday, 23 June 2011

sanitize_sql and dynamic select in ActiveRecord Relation in Rails 3

I needed to select a calculated field based on an outer parameter passed to the select function, and of course with protection of sql injection.

Something like this:['name,count(*) AS cnt,(LOWER(name) = ?) AS is_search_word',params[:search]])
Where the '?' will be given outside the SQL.
After reading a bit in the  "ActiveRecord::QueryMethods" module, i found that when calling where() with an array they call sanitize_sql on the parameters.

so the correct version:['name,count(*) AS cnt,(LOWER(name) = ?) AS is_search_word',params[:search]]))

I find sanitize_sql  is very useful since you can pass a partial statement using that method and it will sanitize it. 

Thursday, 9 June 2011

Thinking Sphinx and Delta Indexing on production

I had some problems when using delta indexing, if you don't have any problems in permissions and you don't have delta indexing:

  • I have unicorn and nginx setup, i had to add bin_path: '/usr/bin' to my sphinx.yml, because my sphinx tools are in /usr/bin.
  • In production always restart unicorn after changes, or any other way to reload the cache, so when doing changes to the model like adding delta property to the model, you have to restart unicorn.
  • Any existing entities in the db will not indexed when enabling delta indexing when doing ts:rebuild, you must update_all('delta=t') and rebuilding.
Final thing when you are doing update_all, your delta index won't get updated, because before_save won't be called, You have to do the following:
 Entity.update_all(["myattribute = ?,delta = ?", false,true], :id =>ids)

Saturday, 4 June 2011

Sphinx & Thinking Sphinx

I needed a Full-Text Search engine for my rails app, and i found out that Sphinx is great for my needs (and being from Egypt is another reason haha).

I was struggling at first in understanding how i combine both my sql queries and my full text searching data, but it appears that i don't need that. Now I just thinks of Sphinx index as a simple Document Database that i store all my needed data in it and just query it for my needs, so i can now do all queries i want and just cache the results into sphinx, the index now has very complex calculated values based on complex queries i was doing at request time, but now i do them only in update time so the retreival now is very fast.

like for example, adding these simple index attributes:
popular =>  "ABS(up_votes - down_votes) > 500"
first_char => "upper(substring(word from 1 for 1))"
has 'CRC32(LOWER(word))',:type => :integer, :as => :word_hash  (for group_by)

What i really miss in Thinking Sphinx, the ability to define an index from an arbitrary query, and the fluent syntax of Arel in creating search.

Tuesday, 31 May 2011

"no such file to load -- bundler/setup" when running rake on linux

I am deploying a rails app to amazon ec2 and after deploying everything, and when running rake command i got that error:
"no such file to load -- bundler/setup"
After sometime of installing, uninstalling and reinstalling of gems, i got the idea that maybe that rake is looking to a different gems location than bundler does. so i did
 which rake 
I got  /usr/local/bin/rake

and then doing which bundler i got /usr/local/bundler.

I have two rakes actually one is in the /local/ and the other in the bin directly.

What i did is recompiling ruby using
./configure --prefix /usr