Twelve Dozen

Just another WordPress weblog

Archive for the ‘Uncategorized’ Category

Form Date Picker – jQuery

I wanted to find a better solution to inputting dates on a form than expecting users to manually input dates.
I searched for AJAX date pickers and there were a number of options, although a lot of them were calendars and not specific date pickers. I’d heard a lot about jQuery so I decided to give that a go.
http://docs.jquery.com/UI/Datepicker

It was very easy to install. Download jQuery. Add the js files to the header of my page. Add the css class to the form input tag.
In MySQL I was using Date as the field type so I need to adjust the format of the form field to match the date input i.e. 2009-09-01
Reading the jQuery documents this was fairly simple:
$(’.datepicker’).datepicker({ dateFormat: ‘yy-mm-dd’ });

Thinking about it now I could probably use a fairly simple dropdown option for year – month – day, but it’s fun to learn to use jQuery.

  • 0 Comments
  • Filed under: Uncategorized
  • Problem: Copying the result from a formula field as a numeric value and not the formula. For example if your calculating the combined total of 2 fields and you then want to copy that result for use elsewhere. If you simply use copy and paste what you actually copy is the formula that you’ve used to get the result.
    Solution: Use copy paste-special the results onto another worksheet. In the paste-special options there should be lots of values and tick boxes. If you untick the option for ‘formula’ when you paste it should just be the result without the formula.

  • 0 Comments
  • Filed under: Uncategorized
  • CVS to MySQL

    To upload data from Excel into a MySQL database the easiest option to export the data as a CSV file. Make sure the columns of data match the fileds in the database, minus the id field, if you have one, as this will be automated.
    Your csv line have to be something like this “Rei”,”New Tokyo 6″,”11234″, or like mine it may be “Rei”,”New Tokyo 6″,11234. Only the text fields enclosed with quotes.
    I used PHP MyAdmin, so choose the import tab. Select the CSV file to import. Choose CSV and update the options like so:
    fields terminated by ‘,’
    enclosed by ‘”‘
    lines terminated by ‘\n’

    That should work. If you’re using the command line to manage MySQL try:
    load data local infile ‘uniq.csv’ into table tblUniq
    fields terminated by ‘,’
    enclosed by ‘”‘
    lines terminated by ‘\n’
    (uniqName, uniqCity, uniqComments)

    Explanation here:
    http://www.tech-recipes.com/rx/2345/import_csv_file_directly_into_mysql/

  • 0 Comments
  • Filed under: Uncategorized
  • Upgrading Python

    I’ve been having problems with an old version of Python on my server. I searched online for a solution but found very little help upgrading Python. There was some suggestions to use virtualenv to have a sandbox Python environment. This was to use different versions of Python at the same time so an upgrade wouldn’t break anything using the older version. I couldn’t get virtualenv to install properly.

    In the end I decided to bite the bullet and upgrade version 2.3 to 2.5 using the following instructions.

    So far all is good on my server, nothing is broken.

    From the book – Gray Hat Python, 1st Edition

    To install Python 2.5 for Linux, you will be downloading and compiling from source. This gives you full control over the installation while preserving the existing Python installation that is present on a Red Hat–based system. The installation assumes that you will be executing all of the following commands as the root user.

    The first step is to download and unzip the Python 2.5 source code. In a command-line terminal session, enter the following:

    # cd /usr/local/
    # wget http://python.org/ftp/python/2.5.1/Python-2.5.1.tgz
    # tar -zxvf Python-2.5.1.tgz
    # mv Python-2.5.1 Python25
    # cd Python25

    You have now downloaded and unzipped the source code into /usr/local/Python25. The next step is to compile the source code and make sure the Python interpreter works:

    # ./configure --prefix=/usr/local/Python25
    # make && make install
    # pwd
    /usr/local/Python25
    # python
    Python 2.5.1 (r251:54863, Mar 14 2012, 07:39:18)
    [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] on Linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>>

    You are now inside the Python interactive shell, which provides full access to the Python interpreter and any included libraries. A quick test will show that it’s correctly interpreting commands:

    >>> print "Hello World!"
    Hello World!
    >>> exit()
    #

    Excellent! Everything is working the way you need it to. To ensure that your user environment knows where to find the Python interpreter automatically, you must edit the /root/.bashrc file. I personally use nano to do all of my text editing, but feel free to use whatever editor you are comfortable with. Open the /root/.bashrc file, and at the bottom of the file add the following line:

    export PATH=/usr/local/Python25/:$PATH
    
    

    Installing virtualenv

    Yeah you will need to install easy_install be able to install it
    and do a

    sudo python ez_setup.py

    then
    easy_install virtualenv
    virtualenv virtualenvironment –python=python2.5 –no-site-packages
    This will create a sandbox of python2.5 where virtualenvironment is a folder where your sandbox environment resides
    then to activate it type
    source virtualenvironment/bin/activate
    you should see the shell prompt with new info showing that you are in the new python environment
    to be sure type
    which python
    to deactivate type
    deactivate
    The jobs a good un.
  • 0 Comments
  • Filed under: Uncategorized
  • Server Monitoring

    I recently sent out a request to a tech list for suggestions for ways to monitor my web server. Here’s the results.

    Hi,
    I’ve just found out about a new monitoring idea someone at work is looking into using twitter. They have created an account for system updates then set up other accounts to follow this and send out sms messages.

    The script uses curl and is a one liner:
    #!/bin/bash
    curl –basic –user username:password –data status=”$* ” http://twitter.com/statuses/update.xml -o /dev/null
    You then just call the script with the tweet as the parameters, e.g.
    # tweet.sh system down
    Gabriel
    We looked around and found this product http://www.paessler.com/

    Its very good – sends emails on any failure, can monitor stacks of ports / devices – we get it to send SMS’s for escalations outside office hours etc – Runs on Windows as a service with a web interface.
    I think there are probably cheaper options that do online monitoring but we monitor quite a lot of sites so it was better to host our own software.
    Adam // Internetware

    nagios works very well in this type of situation…in addition to
    failure reporting you can get it to run remote tasks in the case of
    failure such as ask it to restart mysqld or kick an email queue.

    To be honest, if I cant locate an issue with a server in four hours I
    usually decommission it, format and start again.

    Ross Cooney

    I’ve been running quite happily with Server Density (http://www.serverdensity.com/) which has an iPhone app which sends Push Notifications when there’s an alert triggered (you set up your own thresholds on there). It’s a lightweight Python agent which sends load/disk/network/apache data back to SD servers as frequently as you like.

    Coupled with a Pingdom account which texts me everytime the server is unreachable, you know exactly when things have fallen over. And it means if Push Notifications don’t get through (romaing/network coverage issues etc) then you can still be alerted.
    SD also has an API you can build into your own services as well. Which is nice :)

    Regards,
    Andrew Waters

  • 0 Comments
  • Filed under: Uncategorized