viernes, 14 de marzo de 2014

Ubuntu memory stress tool

Hey there again...  If you need to exhaust the linux OS memory to its limits there is an useful tool at: http://people.seas.harvard.edu/~apw/stress/

You can find the most accurate information there for that tool. I found there places with follow steps and these were not updated, so in a while mine also might be obsolete, anyway here we go:

Step 1 Get the tool
Step 2 Build/Install it
Step 3 Execute it

# wget http://people.seas.harvard.edu/~apw/stress/stress-1.0.4.tar.gz
# tar -xvf stress-1.0.4.tar.gz
# cd stress-1.0.4
# ./configure
# make
# sudo make install


# stress --help

# stress --cpu 8 --io 4 --vm 2 --vm-bytes 128M --timeout 10s
stress: info: [4487] dispatching hogs: 8 cpu, 4 io, 2 vm, 0 hdd
stress: info: [4487] successful run completed in 10s
alex@acer-kozlex:~/tmp$

note: make sure you have gcc installed #yum install gcc

Enjoy!
P.S. Currently there is a proposal to change New Zealand flag

martes, 10 de diciembre de 2013

Decompress .deb packages content

You probably had noticed that these are more personal notes tnat a real blog;

So in the same sense this is how to uncompress debian packages and see its content.


To decompress a deb file an 'ar' command is used:

# ar vx zncrypt_3.3.0-720ubuntu1~precise_amd64.deb
x - debian-binary
x - control.tar.gz
x - data.tar.gz
root@kozlex:/home/agonzalez/bugs/git/master_upstar/zncrypt/remove# ls
control.tar.gz  debian-binary                               zncrypt-kernel-module_3.3.0-720ubuntu1~precise_all.deb
data.tar.gz     zncrypt_3.3.0-720ubuntu1~precise_amd64.deb


Now this there are normal tar files, uncompress with tar:

# tar -xvf control.tar.gz
./
./postinst
./md5sums
./conffiles
./control

# ls
conffiles       data.tar.gz    postinst
control         debian-binary  zncrypt_3.3.0-720ubuntu1~precise_amd64.deb
control.tar.gz  md5sums        zncrypt-kernel-module_3.3.0-720ubuntu1~precise_all.deb



Enjoy!
P.S. Some flags

lunes, 9 de diciembre de 2013

django - Add a haysack Full Text Search in a model window

Well, I have been creating a website and found a way to "popou" a modal window that would contain an FTS.

The credits of this procedure are not mine, these belong to
Mike Hibbert: http://www.youtube.com/user/MickeySoFine1972
Kevin Lew: http://www.queness.com/post/77/simple-jquery-modal-window-tutorial

You can follow mikes tutorial to setup an FTS. I will do somethig similar adding the Lew's modal window.


I will start by creating the model window.

1. Add the code in a template where you cant to add the link that will call the model window:

<a href="#dialog_presenter" name="modal">Add presenter jquery</a>

#dialog presenter is the div name of the model window.

2. Add the corresponding div, might be at the top of your html.

    <!-- #dialog is the id of a DIV defined in the code below -->
    <div id="boxes">

        <!-- #customize your modal window here -->
        <div id="dialog_presenter" class="window">
            <b>Select presenter to add </b>


            <!-- close button is defined as close class -->
            <a href="#" class="close">Close it</a>
        </div>

        <!-- Do not remove div#mask, because you'll need it to fill the whole screen -->
        <div id="mask"></div>
    </div>

Notice that so far had jkust been added "select presenter to Add" ... Nothing else in the model window.

3.  Add some style:


    <style>
    /* Z-index of #mask must lower than #boxes .window */
    #mask {
    position:absolute;
    z-index:9000;
    background-color:#cccccc;
    display:none;
    }
    #boxes  .window {
    position:fixed;
    width:440px;
    height:200px;
    display:none;
    z-index:9999;
    padding:20px;
    }

    /* Customize your modal window here, you can add background image too */
    #boxes #dialog_presenter  {
    width:375px;
    height:203px;
    }
    </style>

4. Add the javascript for a modal window:


    <script>
    $(document).ready(function() {   
        //select all the a tag with name equal to modal
        $('a[name=modal]').click(function(e) {
            //Cancel the link behavior
            e.preventDefault();
            //Get the A tag
            var id = $(this).attr('href');
       
            //Get the screen height and width
            var maskHeight = $(document).height();
            var maskWidth = $(window).width();
       
            //Set height and width to mask to fill up the whole screen
            $('#mask').css({'width':maskWidth,'height':maskHeight});
           
            //transition effect       
            $('#mask').fadeIn(1000);   
            $('#mask').fadeTo("slow",0.8);   
       
            //Get the window height and width
            var winH = $(window).height();
            var winW = $(window).width();
            //Set the popup window to center
            $(id).css('top', winH/2-$(id).height()/2);
            $(id).css('left', winW/2-$(id).width()/2);
       
            //transition effect
            $(id).fadeIn(2000);
       
        });
       
        //if close button is clicked
        $('.window .close').click(function (e) {
            //Cancel the link behavior
            e.preventDefault();
            $('#mask, .window').hide();
        });       
       
        //if mask is clicked
        $('#mask').click(function () {
            $(this).hide();
            $('.window').hide();
        });           
       
    });
    </script>


THAT IS IT FOR THE MODAL WINDOW


5. Now for FTS install whoosh and haysack:

pip install whoosh
pip install django-haystack




6. Add to your project settings.py:

WHOOSH_INDEX = os.path.join(PROJECT_DIRECTORY,'whoosh/')

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
        'PATH': WHOOSH_INDEX,
    },
}


Also... add also to INSTALLED_APPS haytack and django

INSTALLED_APPS = (
    'whoosh',
    'haystack',
)



7. Now I would recommend to follow Mikes youtube's tutorial for FTS, it is clear and complete, just keep in mind that your modal window div would be like:



    <!-- #dialog is the id of a DIV defined in the code below -->
    <div id="boxes">
        <!-- #customize your modal window here -->
        <div id="dialog_presenter" class="window">
            <b>Select presenter to add </b>
            <h3> search </h3>
            {% csrf_token%}
            <input type="text" id="search_presenter" name="search_presenter" />
            <ul id="search-results-presenter">
            </ul>

            <!-- close button is defined as close class -->
            <a href="#" class="close">Close it</a>
        </div>
        <!-- Do not remove div#mask, because you'll need it to fill the whole screen -->
        <div id="mask"></div>
    </div>




Notice that the search input is what the FTS uses as source textbox.



I will just remark the most important steps:

8.- As already said in 7, add the search input.

9.- on ajax.js (java script) add:

$(function(){

    $('#search_presenter').keyup(function() {

        $.ajax({
            type: "POST",
            url: "/ticwiapp/search_user_add_presenter_ajax/",
            data: {
                'search_text' : $('#search_presenter').val(),
                'csrfmiddlewaretoken' : $("input[name=csrfmiddlewaretoken]").val()
            },
            success: searchSuccessPresenter,
            dataType: 'html'
        });

    });

});


function searchSuccessPresenter(data, textStatus, jqXHR)
{
    $('#search-results-presenter').html(data);
}


Where search-results-presenter are the results shown in the <ul> of step 7.

10. on urls file addthe udr and view that will attend the javascript of step 9.

url(r'^search_user_add_presenter_ajax/$', 'myapp.views.search_user_add_presenter_ajax'),

11. on myapp views add myapp.views.search_user_add_presenter_ajax like:

def search_user_add_presenter_ajax(request):

    args = {}
    args.update(csrf(request))
    args['user'] = request.user
   
    # Follow create a haystack object instead a queryset
    args['all_users']  = SearchQuerySet().autocomplete(content_auto=request.POST.get('search_text',''))


    return render_to_response('search_user_add_presenter_ajax.html',args)

12. Create search_user_add_presenter_ajax.html template, this is specified in the return of step 11.

Follow is an example:

{% load static %}


{% if all_users.count > 0 %}
{% for one_user in all_users %}
<br>  {{ one_user.object.first_name }} {{ one_user.object.last_name }}
<a href = "/ticwiapp/add_presenter_now/{{ event.id }}/{{ one_user.object.id }}/registered">Add presenter </a>
{% endfor %}

{% else %}

<p>No users in database!</p>

{% endif %}



There you are!! Enjoy!

 P.D. Looks like Egyptians had invented flags



martes, 3 de diciembre de 2013

Could not get lock /var/lib/dpkg/lock



Well... I was in the middle of an installation when I pressed ctrl+c .. that broke tha installation but didn't released the apt-get install locks...

Fixing it:


So simple... 



# rm /var/lib/apt/lists/lock

# rm /var/cache/apt/archives/lock


This is more a personal note.. anyway there are more published solutions:


http://askubuntu.com/questions/15433/how-do-i-fix-a-could-not-get-lock-var-lib-dpkg-lock-problem

P.S. Do you like to see the red flag?

jueves, 21 de noviembre de 2013

phpmyadmin on ubuntu connecting to mysql by phyton


Just follow these links and few more steps:

Then enable design view, this is really useful
http://debian.sreenadh.in/2008/11/28/how-to-enable-designer-in-phpmyadmin/


Now you can setup python for apache2:

http://www.howtoforge.com/embedding-python-in-apache2-with-mod_python-debian-etch



don't forget to install python-mysqldb

apt-get install python-mysqldb



restart apache:

/etc/init.d/apache2 restart

Now let's try a small db connection:

agonzalez@kozlex:~/django-dev$ cat /var/www/test4.py
#!/usr/bin/python

import MySQLdb

# enable debugging
import cgitb
cgitb.enable()

print "Content-Type: text/plain;charset=utf-8"
print

print "Hello World!"

# connect
mydb = MySQLdb.connect(host="127.0.0.1", user="root", passwd="root",
db="tdb")

cursor = mydb.cursor()

# execute SQL select statement
cursor.execute("SELECT * FROM test")

# get the number of rows in the resultset
numrows = int(cursor.rowcount)

# get and display one row at a time.
for x in range(0,numrows):
    row = cursor.fetchone()
    print (row[0], "-->", row[1])


def index(req):
  return row[1];

agonzalez@kozlex:~/django-dev$



That should work although the prints are not shown!

P.D.  Libya flag is the only country flag with single color and no design.

Read an ISO content on ubuntu

Has been a while since I don't add something here.. I've been working with PXE to overwrite an MBR and I found a small tip that I share now...


To install PXE is needed to install some files from alternate ubuntu, what I did is to get the iso, mount it and find what I need.


So..

To read an iso content on ubuntu:

# sudo mkdir /mnt/iso
# sudo mount -o loop -t iso9660 ubuntu-12.04.3-alternate-amd64.iso /mnt/iso


agonzalez@kozlex:/mnt/iso$ ls /mnt/iso/
boot  cdromupgrade  dists  doc  EFI  install  isolinux  md5sum.txt  pics  pool  preseed  README.diskdefines  ubuntu
agonzalez@kozlex:/mnt/iso$

Annnnd... there it is... I found what I need..

agonzalez@kozlex:/mnt/iso$ find . -name  pxelinux.0
./install/netboot/pxelinux.0
./install/netboot/ubuntu-installer/amd64/pxelinux.0
agonzalez@kozlex:/mnt/iso$



P.D. The vatican is also a country and its flag and is one of the two sqare flags in the world.

domingo, 1 de septiembre de 2013

Uninstall MySql on a Mac OS X

Today I tried to install mysql for mac and I Installed it for MAc OS X 10.7 when I have installed 10.6 version..

Well there is a bug cause the installed didn't warn me and I faced the bug described in:
http://bugs.mysql.com/67133

To fix this I followed some steps from:

http://community.jaspersoft.com/wiki/uninstall-mysql-mac-os-x

This is a copy of previous link solution:

Table of Contents [hide]

Summary

To completely uninstall MySql OS X it is neccessary to remove numerous files.

Symptom

You unable to install an older version of MySql even though you thought you have removed everything.

Resolution

To uninstall MySQL and completely remove it (including all databases) from your Mac do the following:
  • Open a terminal window
  • Use mysqldump to backup your databases to text files!
  • Stop the database server
  • sudo rm /usr/local/mysql
  • sudo rm -rf /usr/local/mysql*
  • sudo rm -rf /Library/StartupItems/MySQLCOM
  • sudo rm -rf /Library/PreferencePanes/My*
  • edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
  • rm -rf ~/Library/PreferencePanes/My*
  • sudo rm -rf /Library/Receipts/mysql*
  • sudo rm -rf /Library/Receipts/MySQL*
  • sudo rm -rf /private/var/db/receipts/*mysql*
The last three lines are particularly important as otherwise, you can't install an older version of MySQL even though you think that you've completely deleted the newer version!

Might be also helpful: http://tomkeur.net/39/how-to-remove-mysql-completely-mac-os-x-leopard.html


Enjoy!
P.S. No flags today.. it's Sunday!