Archive - technology RSS Feed

generating a QRcode in Vcard format in python

You can create a QRcode using the python pygooglechart wrapper for Google chart API. Here i used the wrapper to generate the QRcode as a django app but right now I wont go into the specifics of how to create a django app, maybe will do later,

but this is the view i made for the qr app, i passed the form results to the QRChart and formatted the results in a Vcard format and its then rendered to the page.

You can see the script in action here

http://www.cacoos.com/qr/

test it using an QR android/iphone app

Now the Views….

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from django.template.loader import get_template
from django.template import Template, Context
from django.http import HttpResponse, Http404
from django.shortcuts import render_to_response
from django.core.mail import send_mail
from django.http import HttpResponseRedirect
from cacoos_com.qr.qr_form import QrForm
from pygooglechart import QRChart


def qr(request):
    if request.method == 'POST':
        qform = QrForm(request.POST)
        if qform.is_valid():
            qc = qform.cleaned_data
            chart = QRChart(300,300)
            mecard = "BEGIN:VCARD"+"\n"+"VERSION:3.0 \n"+"FN:"+qc['name']+"\n"+"TEL;type=CELL:"+qc['phone']+"\n"+"EMAIL;type=INTERNET;type=WORK;type=pref:"+qc['email']+"\n"+"URL;type=pref:"+qc['url']+"\n"
            chart.add_data(mecard)
            chart.set_ec('H', 0)
            chart.download('/usr/share/pyshared/django/contrib/admin/media/qr-hello.png')
            return render_to_response('qr_results.html', {'url': qc['url'] })
    else:
        qform = QrForm(initial={'url': 'type your url here'})
    return render_to_response('qr_form.html', {'form': qform})

You can use the following template to generate a Vcard, quite handy…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
BEGIN:VCARD
VERSION:3.0
N:Doe;John;;;
FN:John Doe
ORG:Example.com Inc.;
TITLE:Imaginary test person
EMAIL;type=INTERNET;type=WORK;type=pref:johnDoe@example.org
TEL;type=WORK;type=pref:+1 617 555 1212
TEL;type=CELL:+1 781 555 1212
TEL;type=HOME:+1 202 555 1212
TEL;type=WORK:+1 (617) 555-1234
item1.ADR;type=WORK:;;2 Example Avenue;Anytown;NY;01111;USA
item1.X-ABADR:us
item2.ADR;type=HOME;type=pref:;;3 Acacia Avenue;Newtown;MA;02222;USA
item2.X-ABADR:us
NOTE:John Doe has a long and varied history\, being documented on more police files that anyone else. Reports of his death are alas numerous.
item3.URL;type=pref:http\://www.example/com/doe
item3.X-ABLabel:_$!<HomePage>!$_
item4.URL:http\://www.example.com/Joe/foaf.df
item4.X-ABLabel:FOAF
item5.X-ABRELATEDNAMES;type=pref:Jane Doe
item5.X-ABLabel:_$!<Friend>!$_
CATEGORIES:Work,Test group
X-ABUID:5AD380FD-B2DE-4261-BA99-DE1D1DB52FBE\:ABPerson
END:VCARD
 

yum centos repository python script

Keeping a local yum repository is a good idea, you can get a list of all centos mirrors from here

http://www.centos.org/modules/tinycontent/index.php?id=30

The following python script downloads the os and updates for the releases 5.5,5,6 and 6

make sure you create the relevant directories eg:

1
2
mkdir -p /var/www/html/centos/5.5/os/x86_64
mkdir -p /var/www/html/centos/5.5/updates/x86_64
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python

import subprocess
import os

def main():
    print "download and sync centos repository.."
    rsync = "/usr/bin/rsync -avrt "
    #mirror = "rsync://mirror.cogentco.com/CentOS"
    mirror = "rsync://anorien.csc.warwick.ac.uk/CentOS"
    ver = ["5.5","5.6","6"]
    arch = ["x86_64"]
    base=["os","updates"]
    local = "/var/www/html/centos"

    for v in ver:
        for a in arch:
            for b in base:
                remote = mirror+"/"+v+"/"+b+"/"+a+"/"
                subprocess.call( rsync+" "+remote+" "+local+"/"+v+"/"+b+"/"+a+"/", shell=True)

    print "completed downloading of updates..."

main()

save the above script and make it executable..

1
chmod 755 /path/to/yum-sync.py

and finally add this script to cron to run every midnight

1
 05 * * * root /path/to/yum-sync.py
 

python calculate mouse speed in miles per hour

this is based on my previous program to find out the cursor location, this time i stored the X,Y coordinates and used the speed = distance/time formula to deduce the mouse speed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
import os
import math
import time
import datetime
from datetime import datetime
from datetime import timedelta
from Xlib import display
import pygame
from pygame.locals import *

PIXEL_MILE_RATIO = 6336000
pixels_to_miles = lambda p: p*PIXEL_MILE_RATIO

def main():
x = 0
y = 0
z = time.time()
start = datetime.now()
end = start + timedelta(minutes = 2)
while start < end:
    a1 = x
    b1 = y
    c1 = z
    #timer = int(end - time.localtime(time.time()).tm_min)
    #dt = datetime.now()
    data = display.Display().screen().root.query_pointer()._data
    x = data["root_x"]
    y = data["root_y"]
    z = time.time()
    m = start.minute
    s = start.second
    nn = start.microsecond
    #x1, y1 = pygame.mouse.get_rel()
    print "x = ", x
    print "y = ", y
    print "t = ", z
    print "M = ", m
    #print "x1 = ", x1
    #print "y1 = ", y1
    a = " X = " + str(x)
    b = " Y = " + str(y)
    c = " CPUTime = " + str(z)
    s1 = " PX = "+ str(a1)
    s2 = " PY = "+ str(b1)
    s3 = " PT = "+ str(c1)
    d = " Time = " + str(m)+":"+str(s)+":"+str(nn)
    dx = float(x) - float(a1)
    dy = float(y) - float(b1)
    dist = math.sqrt( math.pow(dx,2) + math.pow(dy,2))
    dz = (float(z) - float(c1))/3600
    speed = float(pixels_to_miles(dist)/dz)
    print "speed: ", speed
    filename = "mouselog.txt"
    file = open(filename,'a')
    file.write( "speed = "+str(speed) + d + c + a + b + s1 + s2 + s3 + "\n")
    file.close()
    start = datetime.now()

if __name__ == "__main__":
    main()

Output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
speed = 9.68733413105e+13 Time = 42:15:39331 CPUTime = 1312540935.06 X = 403 Y = 302 PX = 517 PY = 337 PT = 1312540935.03
speed = 3.1195425937e+13 Time = 42:15:56426 CPUTime = 1312540935.08 X = 370 Y = 284 PX = 403 PY = 302 PT = 1312540935.06
speed = 3.35042681035e+12 Time = 42:15:83911 CPUTime = 1312540935.11 X = 369 Y = 280 PX = 370 PY = 284 PT = 1312540935.08
speed = 1.68384671714e+13 Time = 42:15:111970 CPUTime = 1312540935.14 X = 388 Y = 271 PX = 369 PY = 280 PT = 1312540935.11
speed = 2.13257869307e+13 Time = 42:15:140457 CPUTime = 1312540935.15 X = 399 Y = 270 PX = 388 PY = 271 PT = 1312540935.14
speed = 5.35459767736e+13 Time = 42:15:160703 CPUTime = 1312540935.18 X = 464 Y = 271 PX = 399 PY = 270 PT = 1312540935.15
speed = 4.03726000597e+13 Time = 42:15:179963 CPUTime = 1312540935.21 X = 513 Y = 280 PX = 464 PY = 271 PT = 1312540935.18
speed = 4.92414847017e+13 Time = 42:15:208925 CPUTime = 1312540935.25 X = 604 Y = 323 PX = 513 PY = 280 PT = 1312540935.21
speed = 3.59206632608e+12 Time = 42:15:254745 CPUTime = 1312540935.27 X = 605 Y = 325 PX = 604 PY = 323 PT = 1312540935.25
speed = 3.93031983354e+12 Time = 42:15:268934 CPUTime = 1312540935.29 X = 603 Y = 328 PX = 605 PY = 325 PT = 1312540935.27
speed = 1.8299347528e+13 Time = 42:15:289879 CPUTime = 1312540935.31 X = 591 Y = 333 PX = 603 PY = 328 PT = 1312540935.29
speed = 1.91997708739e+13 Time = 42:15:306052 CPUTime = 1312540935.32 X = 582 Y = 335 PX = 591 PY = 333 PT = 1312540935.31
speed = 6.08661375482e+13 Time = 42:15:317059 CPUTime = 1312540935.34 X = 516 Y = 338 PX = 582 PY = 335 PT = 1312540935.32
speed = 4.21959903522e+13 Time = 42:15:341786 CPUTime = 1312540935.36 X = 481 Y = 335 PX = 516 PY = 338 PT = 1312540935.34
speed = 1.58171778767e+14 Time = 42:15:360783 CPUTime = 1312540935.38 X = 343 Y = 309 PX = 481 PY = 335 PT = 1312540935.36
speed = 4.02061707593e+13 Time = 42:15:381011 CPUTime = 1312540935.41 X = 295 Y = 293 PX = 343 PY = 309 PT = 1312540935.38

Technorati Tags:

 

STS-134 final launch in history!


 

how to fix a corrupt mysql table

recently the mysql on bacula crashed with this error message

log:2010-11-04 20:16:22lb01-dir JobId 9942: Fatal error: sql_create.c:801 Lock Filename table Query failed: LOCK TABLES Filename write, batch write, Filename as f write: ERR=Table ‘./bacula/Filename’ is marked as crashed and should be repaired

you can check the database and find out which tables are corrupt

mysqlcheck –databases bacula -p

and repair it using Continue Reading…

 

» How to Restrict Certain Users from Using Programs on Your PC (Registry Tweak Instructions)

For registry fix “Restrict Certain Users from Using Programs on Your PC,” you’ll need to:

Backup your system and its important files before editing your registry.

Now, open your registry. You can open your registry by using the Registry Editor (REGEDIT.exe), which is a program automatically included with most Windows operating systems. The Registry Editor lets you view, edit, and search data within the your system’s registry. You can launch your Registry Editor many ways, and the easiest way to is to click the “Start” button, select “Run,” and type “regedit” inthe “Open” box (click here for a sample image of Registry Editor and instructions on how to use Registry Editor).

Continue Reading…

 

FootPrinting : : Before the real fun begins

FootPrinting is an art of gathering target information. Its, just like knowing about your enemy before you try to attack. A successful attacker must harvest a wealth of information to execute a focussed and surgical attack. This enables an attacker to create a complete profile of an organization’s security posture and this is achieved by using a combination of tools and techniques.
Continue Reading…

 

Scanning Networks: a newbie guide

Scanning helps one to know what services are running on a machine. This will
show the open ports on which services are listening for connections.

First we will determine whether the target machine is alive or not. This can
be done by sending a icmp echo request packet to the server. The server would
respond with a icmp echo reply showing that it’s alive. The process to
do this on a range of hosts or ipaddresses is known as ping sweep .
Continue Reading…

 

change plesk admin port

1. first add a new domain from the control panel cp.domainname.com,
2. then edit the vhost configuration file at /var/www/vhosts/cp.domainname.com/conf/httpd.include and add the higlighted fields.
Continue Reading…

 

secure centralized log server

log archive script

#!/bin/sh

Today=`date +%Y%m%d`
fy=`date –date=’5 days ago’ +%Y`
fm=`date –date=’5 days ago’ +%m`
fd=`date –date=’5 days ago’ +%d`

echo “$Today”;
echo “$fd”;

server=`ls /var/log/HOSTS`;

for i in $server
do

mkdir -p /archive/$i/$fy/$fm/$fd
tar -zcvf /archive/$i/$fy/$fm/$fd/$fd.tar.gz /var/log/HOSTS/$i/$fy/$fm/$fd/

done

#!/bin/sh

Today=`date +%Y%m%d`
fy=`date –date=’5 days ago’ +%Y`
fm=`date –date=’5 days ago’ +%m`
fd=`date –date=’5 days ago’ +%d`

echo “$Today”;
echo “$fd”;

server=`ls /var/log/HOSTS`;

for i in $server
do

mkdir -p /archive/$i/$fy/$fm/$fd
tar -zcvf /archive/$i/$fy/$fm/$fd/$fd.tar.gz /var/log/HOSTS/$i/$fy/$fm/$fd/

done

 
Page 1 of 3123»
Theme Tweaker by Unreal