Skip to content

Instantly share code, notes, and snippets.

View khajer's full-sized avatar

itsara khajer

View GitHub Profile
@khajer
khajer / gist:1064601
Created July 5, 2011 10:10
database titanium
var win = Titanium.UI.currentWindow;
win.backgroundImage = 'images/bg.png';
//database
var db = Titanium.Database.open('todolist');
db.execute('CREATE TABLE IF NOT EXISTS TODOLIST (ID INTEGER, TITLE TEXT, DETAIL TEXT, CREATEDATE DATETIME)');
var rows = db.execute('select * from todolist');
var data = [];
var cnt = 0;
@khajer
khajer / gist:1064605
Created July 5, 2011 10:14
test dojo
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.4/dijit/themes/soria/soria.css">
<style type="text/css">
body, html { font-family:helvetica,arial,sans-serif; font-size:90%; }
"""
data packet sent
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Code | Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identifier | Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@khajer
khajer / gist:1064642
Created July 5, 2011 10:43
scan port
from socket import *
if __name__ == '__main__':
target = raw_input('Enter host to scan: ')
targetIP = gethostbyname(target)
print 'Starting scan on host ', targetIP
#scan reserved ports
for i in range(20, 1025):
s = socket(AF_INET, SOCK_STREAM)
@khajer
khajer / gist:1075316
Created July 11, 2011 04:27
download file (http) to filesystem (titanium)
var url='http://www.dogameok.com/image.jpg';
var httpClient = Titanium.Network.createHTTPClient();
var filepath = "data/image.jpg";
if (httpClient.open('GET', url)){
httpClient.receive(function(data){
var file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, filepath);
var fileStream = file.open(Titanium.Filesystem.MODE_APPEND);
fileStream.write(data);
@khajer
khajer / gist:1144676
Created August 14, 2011 07:37
read local file (xml)
var f = Titanium.Filesystem.getFile(
Titanium.Filesystem.resourcesDirectory,
'data/branch.xml'
);
var fdata = f.read();
var xml = Titanium.XML.parseString(fdata.text);
@khajer
khajer / gist:1148352
Created August 16, 2011 02:53
read file from xhr and write on system
var xhr = Titanium.Network.createHTTPClient();
xhr.open("GET","http://www.yourdomain.com/test.txt");
xhr.onload = function(){
statusCode = xhr.status;
if(statusCode == 200)
{
var doc = this.responseText;
var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'test.txt');
f.write(doc);
@khajer
khajer / gist:1165939
Created August 23, 2011 17:28
read sqlite file
//feed for database
// -------
var db = Ti.Database.install('../book.sqlite','db_name');
var rows = db.execute('select * from books where download_complete = 1');
var arrBook = [];
while (rows.isValidRow()){
//rows.fieldByName('issue_name');
rows.next();
}
@khajer
khajer / gist:1166087
Created August 23, 2011 18:35
titanium database connect
var db = Titanium.Database.open('imagazine');
//db.execute('drop database imagzine'); // for clear old
//db.execute('insert into books (book_id, issue_name, cover_image, book_name, download_completed) values(1,"101","issues/0/cover.jpg","car",1)');
var rows = db.execute('select * from books where download_completed = 1');
while (rows.isValidRow()){
/*
alert(rows.fieldByName('book_id'));
@khajer
khajer / gist:1216159
Created September 14, 2011 09:11
feed xml tag
var f = Titanium.Filesystem.getFile( Titanium.Filesystem.resourcesDirectory,
'issues/0/data.xml'
);
var fdata = f.read();
var xml = Titanium.XML.parseString(fdata.text);
var imagesFile = [];