How to find iframe inside a div ?

Problem: I need to find an iframe inside a div and then an element inside that iframe.

It’s easy with JQuery:

<div class="container">
    <iframe frameborder="0" src="javascript:void(0)" role="listbox" aria-label="tag" title="tag">
.
.
        <div id="div-inside-iframe"></div>
.
    </iframe>
</div>
$('.container iframe').contents().find('#div-inside-iframe');

Javascript is not working on content loaded by jquery’s .get()

IE made me cry again.

Problem: When you want to load some html data into document using JQuery’s .get() .post() .ajax() functions but events like “onclick, onmouseover” don’t work exactly inside loaded content in all versions of Internet Explorer.

Solution:
1. Check carefully if loaded html is valid with any online validator.
In my case IE didn’t show errors and even notices, for some reason, so it’s always better to check html with other online tools.

2. Use jquery .live() function to bind events.

$('#foo').live('click', function() {
  alert('User clicked on "foo');
});

3. Other developers suggest also to avoid <script> tags inside loaded content.

Well, probably they are right, but it worked for me without moving those.

See “.bind()” documentation at http://api.jquery.com/bind/

Nearly the same problem was described at http://stackoverflow.com/questions/4293195/click-event-is-not-working-on-ajax-loaded-content.

Simple site pinger

This simple script pings your websites and notifies when a website is down.
It’s written in python >= 2.5 and might be usefull for administrators and programmers.
Some parts of it was found somewhere in the internet and adjusted a bit for my needs.

Required packages can be installed easily from repository ( Ubuntu example ):

sudo apt-get install python-notify

or using pip/easy_install as well

sudo pip install notify

Running this script from command line is a bit annoying so I put to run it by crontab each 30 min:

$ crontab -e
*/30 * * * * DISPLAY=:0 /usr/bin/python /home/vs/bin/pingwebsites.py

Note that you need to set DISPLAY option to make notification visible for current X session.

#!/usr/bin/env python
from threading import Thread
import subprocess
from Queue import Queue
from pynotify import *

num_threads = 4
queue = Queue()
hosts = [
    ,"mysite.com"
    ,"myanothersite.com"
]
#wraps system ping command
def pinger(i, q):
    """Pings subnet"""
    while True:
        host = q.get()
        #print "Thread %s: Pinging %s" % (i, host)
        ret = subprocess.call("ping -c 5 %s" % host,
                        shell=True,
                        stdout=open('/dev/null', 'w'),
                        stderr=subprocess.STDOUT)
        if ret == 0:
            pass
            #print "%s: is alive" % host
        else:
            init("Server checker")
            msg =  "%s: did not respond" % host
            Notification("Server checker", msg).show()
        q.task_done()
#Spawn thread pool
for i in range(num_threads):

    worker = Thread(target=pinger, args=(i, queue))
    worker.setDaemon(True)
    worker.start()
#Place work in queue
for host in hosts:
    queue.put(host)
#Wait until worker threads are done to exit
queue.join()