Segmenation fault – core dump error assembly 32bit code on 64bit machine

I have a shiny 64 bit dell machine that tops ubuntu on it.
I working working on some other machine a bit of assemly code and I didn’t have a problem.
But when I run the same code my 64 machine i was getting the a segmentation falut error. Not surprising actually.
here is what I have done to resolve it:

1. Don’t forget to add .code32 at the beginning of your assembly file. [ talking about x86 architecture ]
2. Have the gcc multilib on your machine

sudo apt-get install gcc-4.7-multilib

3. When assembling and linking your file use

gcc -m32 -nostartfiles -o executablename filename.s

Change your executablename and filename.s accordingly

A hello world in Assebly language tha would show the first number that is greater than 80

# 
# Simple program to stop when it gets the first number greater than 80
#

.section .data
number_store: #fixed name for the address holding
    .long 34,78,23,90,12,234,76,23,1 #Numbers to be dealt with. 
.section .text
.globl _start

_start:
    mov $0, %esi #initialize the esi 
    mov number_store(, %esi, 4), %eax # load the first number on the eax register

    begin_loop:
        cmp $80, %eax #compare the value on eax with 80
        jge exit_door #yup exit if the comparison met..
        inc %esi
        mov number_store(,%esi,4), %eax #load the next number from the array
        jmp begin_loop #go back to the loop

    exit_door:
        mov %eax, %ebx #load the last value we have to ebx register
        mov $1, %eax # call the exit call here
        int $0x80 #interubt it

This will be running on the x86 processor.
To run it on the linux do the following from the command line:
The following command would- create the object file:

as greater.asm -o greater.o 

The next one will be the linker – we need it to create the executable

ld -o greater greater.0

and run it as

./greater

Now the value would be accumulated on the register ebx.. Since the exit parameter will be stored on the ebx, and we have a value being loaded on the ebx it will be just showing that:

echo $?

this is A HELLO WORLD TO ASSEMBLY

Allowing others to use mysql from user machine on ubuntu- simple one!

It is customary sometimes to share the part of the database from sandbox to a fellow developer or to access it from the other machine – umm.. is it not how the servers are doing it?? what are you talking about 😉

Anyway here is a simple note to make it happen.1. We need to bind the machine name for the server. to do that
open your my.cnf – inside the /etc/mysql/my.cnf for debianish machines and search for the
[mysqld] and add the following
bind-address = your ip address goes here
you can find your ip address from

ifconfig

then save the file and restart your mysql

sudo /etc/init.d/mysql restart

There are ways to assign for a specified user from the specified ip addresses as well.
Like if you have database db1 and user1 from ip address 168.192.3.4 then

grant select, insert, update on db1.* to 'user1'@'168.192.3.4'

Installing Imagick for php using pecl

If you are dealing with CAPTCHA or some graphics stuff you have definitely come across with Imagick.. it is a nice library that you should check out..
to install.. it is much really easy with pecl
here is the step by step process to install it..

pecl download imagick
tar -zxvf imagick-VERSION.NUMBER.GOES.HERE.tgz
cd imagick-VERSION.NUMBER.GOES.HERE
phpize
./configure --with-imagick=/opt/local
make
make install

Then, on successful make, you will see the path where the “dot so” is saved..
go to you php.ini file and add

extension=imagick.so

then restart you apache and check if the imagic is available on phpinfo()..

DONe!

handling array inputs in zend. Passing inputs that are generated from javascript to zend controller

Hello There,
Was working on a project that is on zend framework. The task involves having having javascript generated input boxes and passing those to the controller.
I have done that before using some other mechanism but they were not somehow natural ways to do it.
It can be done in a much easier way -NATURALLY- though 🙂
lets assume your form has javascript powered email address adding inputboxes. There would be some link you would hit as add emails and it will create input boxes for you..

1. have the input box in your zend form as

		$this->addElement('text', 'emails', array(
			'label'        => 'Emails',
			'isArray'      => TRUE,
			'name'         => 'emails[]'
		));

Or however you are creating the inputbox – or anyother input
2. Then in the javascript where you are creating the input, use the same name as the element’s name

	    var new_email = document.createElement('input');
	    new_email.name = 'emails[]';
	    new_email.type = 'text';
	    new_email.setAttribute('size', 30);

3. yes, you are done!. When the form is submitted, the element with name emails[] would be passed along with the other form elements.
In your controller you would have an array of emails[] and the rest is …

Happy zenjsing

wireless not working on ubuntu 12.04 on dell inspiron

I have a dual boot on my dell inspiron 15. I had an issue with the wireless driver.
Here are the steps I followed to fix it.
Temporary fix
1. go to software resources, you can get it using dash home which is the first icon of the ones listed on the left and type software sources.
2. then select additional drivers menu and select “using broadcom..”

This will fix the problem temporarily but, when you restart the machine you would have to do it again..

Fix.
1. Go to ubuntu software center, you can get it the same way I mentioned on the first part except you would search for “software center” or you can pick it from the unity menu
2. inside the software center, go to the search text box and enter “b43”
3. uninstall/remove the firmware-b43-installer
4. install b43-fwcutter and firmware-b43-lpphy-installer
5. reboot your computer and wireless should show the 🙂 face..

Array Merging in PHP preserving keys. array_merge reindexing arrays

Merging arrays in php keeping the keys

Say you have two arrays with the following values in them:


$array1 = array(13=>'bad luck', 7=>'billion people');
$array2 = array(1=>'number');

And you want the final result to be


$final = (1=>'number', 13=>'billion people', 13=>'bad luck');

But when you merge arrays and using array_merge, u got the indexes being ripped out from the second or first array whose keys are numeric?

The result using array_merge would be

(0 => 'bad luck', 1 => 'billion people', 2 => 'number')

And you don’t want that

Here is a simple way – just use operator overloading of the plus sign

$array1 = array(13=>'bad luck', 7=>'billon population');
$array2 = array(1=>'number');
$merged = $array1 + array2;

Note: This is provided the keys are not overlapping, otherwise, the first array would take ownership of keeping the value.

Do you know how to run single phpunit test

Know who is calling your php script browser or script?

SSH without password not working: mac to ubuntu

if you are doing a lot of server activities, then you are a friend of SSH.
One thing we would do would be to make ssh password-less..
I am trying to log into ubuntu server from mac client. here is the process.

on the MAC,
1. Make sure you have ssh installed. You can check using

which ssh or
ssh -v : this will tell the version

If for some reason it is not installed or if you want to upgrade it, you can install it using mac port – this would be another discussion but the overall stuff would be

$ sudo port -d selfupdate
$ sudo port install openssh

2. Now, create public/private keys using the following command

ssh-keygen -t rsa

you will find these keys in the ~/.ssh folder
This would be much you would do on the client side

On the server (ubuntu server)
1. Create the user on the server using adduser command. Let’s create user macuser

adduser macuser

then follow the instruction to create the user.
2. Go to /etc/ssh/ and update the sshd_config file
Most of the settings of this file would be responsible for the famous problem of asking the password all the time..
3. in the sshd_config file update the following:

StrictModes no
RSAAuthentication yes
PubkeyAuthentication yes
PasswordAuthentication yes

AuthorizedKeysFile      %h/.ssh/authorized_keys

After this restart the ssh using

sudo service ssh restart

Now go back to the mac client and copy the public keys to the server as follows

ssh-copy-id macuser@ubuntuServerOrIP-goes-here

here you will be asked for your password. Give the password you assigned while creating the user on the server.

Then log into the server using

ssh macuser@ubuntuServerOrIP-goes-here

if it is still asking for the password check the following

1. on the ubuntu server go to the ~/.ssh/authorized_keys and see if the public key of mac is registered
2. Check the folder’s permission level is 700 and that of autorized_keys is 600
3. Check the above setting of sshd_config file are saved and restart the ssh on the server