Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

« Newer Snippets
Older Snippets »
Showing 11-20 of 109 total

J2ME - Rescale Image

// description of your code here

private Image rescaleImage(Image image, int width, int height)
	{
		int sourceWidth = image.getWidth();
		int sourceHeight = image.getHeight();
	
		Image newImage = Image.createImage(width, height);
		Graphics g = newImage.getGraphics();
		
		for(int y=0; y<height; y++)
		{
			for(int x=0; x<width; x++)
			{
				g.setClip(x, y, 1, 1);
				int dx = x * sourceWidth / width;
				int dy = y * sourceHeight / height;
				g.drawImage(image, x-dx, y-dy, Graphics.LEFT | Graphics.TOP);
			}
		}
		
		return Image.createImage(newImage);
	}

PyS60 - DaemonS60

// description of your code here

import appuifw
import e32
import thread

lock = e32.Ao_lock()
lockTHR = thread.allocate_lock()

###### Sostituisci questa funzione con quello che vuoi fare eseguire
i = 0
def funzDaemon():
	global i
	while(1):
		lockTHR.acquire()
		e32.ao_sleep(1)
		open('E:\\Others\\tmp.txt', 'a').write(str(i)+"\n")
		i+=1
		lockTHR.release()
####################################################################

appuifw.app.title = u'DaemonS60'
appuifw.app.exit_key_handler = lambda:lock.signal()

print 'DaemonS60 - Start'

thread.start_new_thread(funzDaemon, ())

lock.wait()

print 'DaemonS60 - Stop'

Linux - command ls without color

// Elimina tutti i caratteri speciali che portano il colore

ls --color=never

Perl - send form POST

// Manda le informazioni per il login ad un determinato sito

use HTTP::Request::Common qw(POST);
use LWP::UserAgent;

my $user = "user";
my $pass = "pass";

my $browser = LWP::UserAgent->new();

my $responde = HTTP::Request->new(POST => "http://www.sito.com/index.php");
$responde->content_type("application/x-www-form-urlencoded");
$responde->content("user=" . $user . "&pass=" . $pass);

$browser->request($responde)->as_string

Linux - Example Crontab

// Esegue lo script ogni ora

// Minute(0-59) Hours(0-23) DayOfMonth(1-31) Month(1-12) DayOfWeek(0-6/Sun-Sat) Command
* */1 * * * script.sh

Python - Simple Example CGI

// http://localhost/cgi-bin/example.py?variable=example

import cgi

print 'Content-type: text/html\r\n'

inputValue = cgi.FieldStorage()

if(inputValue.has_key('variable')):
  print inputValue['variable'].value

Python - Exception CGI Redirect

// Reindirizza gli errori di uno script CGI in un file random nella cartella /tmp

import cgitb; cgitb.enable(display=0, logdir='/tmp')

Python - Example Simple ImageView

import pygtk; pygtk.require('2.0')
import gtk

class Image_Example(object):

	def pressButton(self, widget, data=None):
		print "Pressed"

	def delete_event(self, widget, event, data=None):
		print "delete event occured"

		return False

	def destroy(self, widget, data=None):
		gtk.main_quit()

	def __init__(self):
		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
		self.window.connect("delete_event", self.delete_event)
		self.window.connect("destroy", self.destroy)
		self.window.set_border_width(10)

		self.button = gtk.Button()
		self.button.connect("clicked", self.pressButton, None)
		self.button.connect_object("clicked", gtk.Widget.destroy, self.window)

		self.image = gtk.Image()
		self.image.set_from_file("/tmp/f27.jpg")
		self.image.show()

		self.button.add(self.image)
		self.window.add(self.button)
		self.button.show()
		self.window.show()

	def main(self):
		gtk.main()


if __name__ == '__main__':

	Image_Example().main()

Linux - random BG enligthnment

import os
import random

listBG = os.popen('eesh background list').readlines()[:-5]
elemBG = random.choice(listBG)
os.popen('eesh background use ' + elemBG[:-2])

Nokia - User Agent

// User Agent

Modello 3230
"Nokia3230/2.0 (5.0614.0) SymbianOS/7.0s Series60/2.1 Profile/MIDP-2.0
Configuration/CLDC-1.0"

Modello 6260
"Nokia6260/2.0 (3.0448.0) SymbianOS/7.0s Series60/2.1 Profile/MIDP-2.0
Configuration/CLDC-1.0"

Modello 6600
"Nokia6600/1.0 (5.27.0) SymbianOS/7.0s Series60/2.0 Profile/MIDP-2.0
Configuration/CLDC-1.0"

Modello 6620
"Nokia6620/2.0 (4.22.1) SymbianOS/7.0s Series60/2.1 Profile/MIDP-2.0
Configuration/CLDC-1.0"

Modello 6630
"Nokia6630/1.0 (5.03.08) SymbianOS/8.0 Series60/2.6 Profile/MIDP-2.0
Configuration/CLDC-1.1"

Modello 6670
"Nokia6670/2.0 (6.0540.0) SymbianOS/7.0s Series60/2.1 Profile/MIDP-2.0
Configuration/CLDC-1.0"

Modello 6680
"Nokia6680/1.0 (4.04.07) SymbianOS/8.0 Series60/2.6 Profile/MIDP-2.0
Configuration/CLDC-1.1"

Modello 6681
"Nokia6681/2.0 (5.37.01) SymbianOS/8.0 Series60/2.6 Profile/MIDP-2.0
Configuration/CLDC-1.1"

Modello 9300
"Mozilla/4.0 (compatible; MSIE 5.0; Series80/2.0 Nokia9300/05.22
Profile/MIDP-2.0 Configuration/CLDC-1.1)"

Modello 9500
"Mozilla/4.0 (compatible; MSIE 5.0; Series80/2.0 Nokia9500/4.51
Profile/MIDP-2.0 Configuration/CLDC-1.1)"
« Newer Snippets
Older Snippets »
Showing 11-20 of 109 total