Sunday, July 18, 2010

Best Blu-ray Upconversion

A real terminal in the browser and JQuery with Django Part II

While
first part focuses on HTML, javascript and CSS code, in this second part, we focus server-side-side, or the code associated with the python
Django framework. # Copyright (C) 2010 Lorenzo Sfarra (lorenzosfarra@ubuntu.com) # # This program is free software, you can Redistribute it and / or # modify it
under the terms of the GNU General Public License as published by
# the Free Software Foundation; Either
# version 2 of the License, or (at your option) any later version.
# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # from django.conf.urls.defaults import *
from django.conf import settings

MEDIA_ROOT = settings.MEDIA_ROOT
 urlpatterns = patterns ('', 
(r '^ cmd / (? P
.*)$',' terminaljs.terminal.views.cmd '),
(r' ^ media / (?
.* P) $ ',' django.views.static.serve ',
{' DOCUMENT_ROOT ': MEDIA_ROOT}),
(r'^$',' terminaljs.terminal.views.index '),
)




define so that a URL with cmd / cmd view the initial calls with a parameter "command", the command to execute. It also defines the URL with "media /" should be the initial static process, and finally define the default URL that invokes the view index.

Let us now see the code delle view, definito nel file
views.py
:



# Copyright (C) 2010 Lorenzo Sfarra (lorenzosfarra@ubuntu.com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. #
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#


from django.shortcuts import render_to_response from django.http import HttpResponse from commands import getoutput
import os.path
 # global variable 
CWD = "/home/lorenzo"

def index(request):
return render_to_response("index.html")

def is_trusted_command(command):
#TODO: check if it's a trusted command
return True

def cmd(request, command):
global CWD
if command.startswith("cd "):
new_path = command.split(" ")[1]
if not new_path.startswith("/"):
# relative path
new_path = os.path.join(CWD, new_path)
if os.path.isdir(new_path):
CWD = new_path
output = ""
else:
output = "cd: " + new_path + ": No such file or directory"
elif is_trusted_command(command):
output = getoutput("cd %s; %s" %(CWD,command))
else:
output = "Untrusted command."
return HttpResponse(output)




be emphasized, as done in the first part, the function
is_trusted_command
which must also be implemented server-side.

Obviously, everything is purely demonstrative, for those interested in improving it is all the code on Google Code

.



In

Saturday, July 17, 2010

What Happens When A Puppy Is Dewormed

A real terminal in the browser with jQuery and Django, Part I

see how to make a terminal that accepts commands and executes them actually on a real machine.
This first part focuses on HTML, Javascript and CSS code needed.
The second part will focus instead on the side of the python programming

with

Django framework.



The server side was built with the Python web framework Django
, the client side uses the JS Library

JQuery for AJAX calls. HTML is pretty simple and is in the file
templates / index.html

\u0026lt;head>
\u0026lt;title> Lorenzo Sfarra: DJSterminal \u0026lt;/ title>
<link rel="stylesheet" href="/media/css/terminal.css"/> <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> // You may specify partial version numbers, such as "1" or "1.3",
// with the same result. Doing so will automatically load the // latest version matching that partial revision pattern // (e.g. 1.3 would load 1.3.2 today and 1 would load 1.4.2). google.load("jquery", "1.4.2"); </script>
<script src="/media/js/terminal.js" type="text/javascript">/* Terminal */</script>
<script type="text/javascript"> google.setOnLoadCallback(function() {
/* Handle the enter keycode */
$("#commandline").keypress(function(event) {
                if (event.keyCode == '13') { 
event.preventDefault();
onEnterKey();
}
});
});
</script>
</head>

<body>
<div id="terminal">
<div id="terminaltop"><img src="/media/css/imgs/buttons.png" alt="buttons" align="left"/> <br/>Javascript Terminal</div>

<!-- Command line -->
<textarea id="commandline" cols="80" rows="15">lorenzo@josie:~$ </textarea>
<!-- End command line -->
\u0026lt;/ div>
\u0026lt;/ body>
\u0026lt;/ html>



In the first line we import the necessary files. In particular, we use Google

to load the JQuery library

.
In lines 20-29 we capture the Enter key to handle the input as a command line.


terminal.js
file that contains the required javascript source is located in
media / js
, and is as follows:



/ * Copyright (C) 2010 Lorenzo Sfarra (lorenzosfarra@ubuntu.com)

* This program is free software, you can Redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA.
*/
// The command line prompt var cliPrompt = "lorenzo@josie:~$ ";

// the server address where the real console exists
 var cliHost = "http://localhost:8000/"; 

function isTrustedCommand(command) {
/**
* Function to check that the given command is trusted.
* @param command the command to check
* @return boolean
*/
// TODO: check that this is a trusted command!
return true;
}

function executeCommand(text, cliPrompt, command) {
/**
* Function to execute the given command through an AJAX call
* and retrieve the result to update the textarea value.
* @param text the current textarea value
* @param cliPrompt the prompt
* @param command the command to execute
*/
// build the URL for the command
remoteCommand = cliHost + "cmd/" + command;
output = "";
// Perform the AJAX call
$.ajax({
url: remoteCommand,
type: 'GET',
dataType: 'text',
error: function(data, textStatus, errorThrown) {
// readyState == 4? Error.
if (data.readyState == 4) {
output = "Connection error.\n"
}
},
success: function(data) {
output = data + "\n";
$("#commandline").val([text, output, cliPrompt].join("\n"));
// Textarea with focus at bottom
$("#commandline").animate({ scrollTop: 99999}, 10);
}
});

}

function onEnterKey() {
/* Function called when a user press the Enter key on its keyboard. */
text = $("#commandline").val();
// Get the command
promptIndex = text.lastIndexOf(cliPrompt);
// build the command
command = text.substring(promptIndex + cliPrompt.length);
if (command == "clear") {
// simply clear the textarea value
$("#commandline").val(cliPrompt);
} else if (isTrustedCommand(command)) {
executeCommand(text, cliPrompt, command);
} else {
output = "Invalid command.";
$("#commandline").val([text,output,cliPrompt].join("\n"));
}
}




La funzione principale รจ ovviamente
executeCommand()
making the AJAX call really necessary to run the command on the server reference.


WARNING:

isTrustedCommand is a very important function (command)
which returns true if the command is "permission" to run. This is obviously necessary to protect the server. At present, the function does not perform any checks and immediately returns true.

The stylesheet
terminal.css

is located in the media / css
. Skip to


Part II

.

The style was taken as a reference model in the terminal this
"Forwarding E-mails with Postfix "
.

Thursday, July 15, 2010

Motherhood 2009 Stream




"Eighteen and forty-one"
100 * 100cm
oil and oil pastels on canvas

Prom Dress Catalogue Requests



"On top of a mountain with clouds hanging "
42 * 42cm oil on board

Tuesday, July 6, 2010

Best Bridge Camera 2010











"Demons"
20 * 15 each
oil on canvas

Friday, July 2, 2010

Good Poses For Profile Pictues




"Dew" (diptych)
20 * 30cm oil on board each

Neurgena Deep Clean Facial Cleanser




"All" 75 * 80cm

oil and watercolor on paper Table

Thursday, July 1, 2010

Chlordiazep And Acetaphetamine




"They fall the forty flowers

140 * 100cm oil on paper on wood

Monster Energy Refrigerators



" I hate you "

24 * 20cm mixed media on wood

Can Radiators Adjust Temp




"As these flowers are all dying"

100 * 70cm mixed media on paper on wood

Best Cleats For Reciever




"Back"
60 * 140cm oil
table you

Vegeta Bulma Free Doujinshi



" 11 "

variable size oil on canvas