Bootstrap modal and Ajax content

June 8, 2012

<script type="text/javascript">
    $(function() {
      $('[data-toggle="modal"]').click(function(e) {
        var href = $(this).attr('href');
        if (href.indexOf('#') == 0) {
        } else {
        $.get(href, function(data) {
          $('<div class="modal">' + data + '</div>').modal();

<a href="/beta/detail/{{ result.host_id }}" data-toggle="modal">{{ result.host_name }}</a>

<div class="modal-header">
  <a class="close" data-dismiss="modal" >×</a>
  <h3>{{ result.host_name }}</h3>
<div class="modal-body">
  {{ result.host_name }}

Graylog2 web interface timeouts

April 2, 2012
To make graylog2-web respond to HTTP queries you have to increase the initial 256MB heap size. In my case I set it to 4GB.

Edit /opt/elasticsearch-0.19.0/config/elasticsearch.yml and uncomment:

# ElasticSearch performs poorly when JVM starts swapping: you should ensure that
# it _never_ swaps.
# Set this property to true to lock the memory:
bootstrap.mlockall: true
Set necessary shell variable by editing /opt/elasticsearch-0.19.0/bin/elasticsearch:

Finally, edit /opt/elasticsearch-0.19.0/bin/service/elasticsearch.conf and modify these variables:

Now restart ES and enjoy it.

root     32286 32284  8 17:06 ?        00:01:31 java -Delasticsearch-service -Des-foreground=yes
-Des.path.home=/opt/elasticsearch-0.19.0 -Djline.enabled=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC
-XX:+CMSParallelRemarkEnabled -XX:SurvivorRatio=8 -XX:MaxTenuringThreshold=1
-XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly
-XX:+HeapDumpOnOutOfMemoryError -Xms4096m -Xmx4096m -

celery, redis, django-celery

March 16, 2012
If you're like me, spent several hours figuring out why celeryd wasn't updating the djcelery_taskstate table and the Django admin page was showing zero tasks, look no further 'cause I have good news! Solution is to run celerycam:

./ celerycam
[2012-03-16 16:18:31,687: INFO/MainProcess] -> evcam: Taking snapshots with djcelery.snapshot.Camera (every 1.0 secs.)
And finally, the moment of truth.

Basics of AppleScript

January 3, 2012
Say, you have some NFS share you would like to mount after typing a predefined password. Here's a little GUI program to demonstrate the basics of AppleScript.

set question to display dialog "" buttons {"Mount", "Unmount", "Cancel"} with title "Ready?" default button 3
set answer to button returned of question

if answer is equal to "Mount" then
	tell application "Finder"
		set Input to display dialog "" default answer "" buttons {"OK", "Cancel"} default button 1 with hidden answer
	end tell
	if text returned of Input as string is "qwerty" then
		do shell script "sudo mkdir /Network/nas/personal"
		do shell script "sudo mount -t nfs -o vers=3,resvport /Network/nas/personal"
		tell application "Finder"
			open folder "Macintosh HD:Network:nas:personal"
		end tell
	end if
end if

if answer is equal to "Unmount" then
	do shell script "sudo umount -f /Network/nas/personal"
	do shell script "sudo rmdir /Network/nas/personal"
end if

if answer is equal to "Cancel" then
end if

Passing HTTP headers

December 21, 2011
Passing HTTP headers using urllib2 is a straightforward thing.

def logIn(self):
  req = urllib2.Request(self.login_url)
  req.add_header('Host', '')
  req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; rv:6.0) Gecko/20100101 Firefox/6.0')
  req.add_header('Accept-Language', 'en-us,en')
You can also put everything in a dictionary:

headers = {
  'User-Agent':'Mozilla/5.0 (Windows NT 6.1; rv:6.0) Gecko/20100101 Firefox/6.0',
  'Content-Type': 'application/x-www-form-urlencoded'
And then just execute your query:

req = urllib2.Request(self.login_url, form_data, headers)
log_in = urllib2.urlopen(req).read()