Stanford University e-learning Courses

Stanford University is one of the world’s leading research and teaching institutions.

Actually they are erogating free online courses for several disciplines.

The following list report courses that are most interesting for me.

 If you’re interested in other courses, follow the link of one course, then look at other available courses.

Cryptography, Dan Boneh

http://www.crypto-class.org/

Class starts February, 2012

 

Human-Computer Interaction Scott Klemmer

http://www.hci-class.org

Class starts January 30, 2012

 

Design and Analysis of Algorithms I, Tim Roughgarden

http://www.algo-class.org

Class starts February 2012

 

Technology Entrepreneurship, Chuck Eesley

http://www.venture-class.org

Class starts February 2012

 

 

References

 

 

 

myBatis Java

This article introduces mybatis java (iBatis 3 for java) and summarizes its configurationand usage. The article also give suggestions and  conclusions on mybatis usage.

Introduction

The iBATIS Data Mapper (born in 2002) is a framework that  introduces SQL Mapping approach to persistence layer development. The iBATIS name and code was donated to the Apache Software Foundation, that hosts project development for many years.

In 2010 the core development team of iBATIS has decided to continue development under new home: Google Code; and with a new name: mybatis .

Actually both the Java and .NET project teams have forked the software to Google Code ( mybatis Java and mybatis .NET ). The new version of the project added support to metadata annotations.

 

Configuration

building SqlSessionFactory from XML is quite simple:

String resource = "org/mybatis/example/Configuration.xml";
Reader reader = Resources.getResourceAsReader(resource);
sqlMapper = new SqlSessionFactoryBuilder().build(reader);

The configuration file contains settings for the core of the MyBatis system

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
	<environments default="development">
		<environment id="development">
			<transactionManager type="JDBC" />
			<dataSource type="POOLED">
				<property name="driver" value="${driver}" />
				<property name="url" value="${url}" />
				<property name="username" value="${username}" />
				<property name="password" value="${password}" />
			</dataSource>
		</environment>
	</environments>
	<mappers>
		<mapper resource="org/mybatis/example/BlogMapper.xml" />
	</mappers>
</configuration>

note:

  • ${parameterName} : indicate a parameter, usually taken via propery file ..
  • mapper: imply the existence of the BlogMapper.xml file

Generator

There is a generator for MyBatis artifacts, available as standalone JAR, Ant task, Maven plugin or Eclipse plugin. See description on code.google.com/p/mybatis/wiki/Generator, where you can get the JAR, and the Update Site for the Eclipse plugin.

Java XSL Transform

Questa porzione di codice mostra come eseguire una trasformazione XSL con Java

private static final String ERR_XSL_CONFIGURATION = "Error during XSL Transform configuration.";
private static final String ERR_XSL_TRANSFORM = "Error during XSL Transform execution.";

/** XSL Transform with input, output and parameters. */
@SuppressWarnings("unchecked")
public static void transform(Source xml, Source xsl, Result out, HashMap< String, ? > params){

    // factory init
    TransformerFactory factory = TransformerFactory.newInstance();

    // Transformer object init
    Transformer t;
    try {
        t = factory.newTransformer(xsl);
    } catch (TransformerConfigurationException e) {
        // if any XSL error
        throw new RuntimeException( ERR_XSL_CONFIGURATION, e );
    }

    // insert parameters (if any)
    if( params != null && params.size() > 0 ){
        Iterator< ? > i = params.entrySet().iterator();
        Entry< String, ? > me ;
        while(i.hasNext()){
            me = (Entry< String, ? >) i.next();
            t.setParameter(me.getKey(), me.getValue());
        }
    }

    // Transformation execution
    try {
        t.transform(xml, out);
    } catch (TransformerException e) {
        // if any Transformation error
        throw new RuntimeException( ERR_XSL_TRANSFORM, e );
    }
}

 

Java Directory Backup

Questa porzione di codice esegue il backup del contenuto di una directory. Si può utilizzare per salvare il contenuto prima di scrivere altri file al suo interno.

File saveDir = new File(SAVE_DIR_PATH);
//
if( saveDir.exists() && saveDir.listFiles().length>0){
  File parent = saveDir.getParentFile();
  String name = saveDir.getName();
  int i=0;
  File bkDir;
  do{
    bkDir = new File(parent, String.format(name + "_%04d", i++));
  }
  while(bkDir.exists() && i<9999);
  // sposta la dir corrente
  System.out.println("Backup - dir: " + saveDir + " to " + bkDir.getName());
  if( !saveDir.renameTo(bkDir) ){
    throw new RuntimeException("Impossible to rename dir: " + saveDir);
  }
  // crea nuova dir
  saveDir.mkdirs();
}
// qui posso scrivere all'interno della directory

JSP and JSTL

The JSP Standard Taglibrary (JSTL) encapsulates as simple tags, several core functionalities common to many JSP applications. For example it contains tags for store / display variables, make iterations, XML manipulation, Input / Output, and so on.

This post explain how to setup a page with JSTL and make some examples for common tags.

Install JSTL

To use a tag library you need to import jar libraries containing the implementation and define tags that invoke functions inside the library.

You can find jstl-1.2.jar on the web or from this local archive.

Test JSTL

Since the jat we’ve copied contains both libraries and TLD definitions, we can start to use JSTL tags. To use them, first we need reference JSTL with a declaration at top of JSP. In the shippet below we reference the jstl/core library, whose tags are available under the prefix “c:” .

<!-- declare usage of common -->
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

Then we could put some JSTL tags inside the page.

<h1>Test JSTL</h1>
<!-- import an xml file in a variable, then prints out to page -->
<c:import url="test.xml" var="xml"/>
1. <c:out value="${xml}"/><br/>
2. <c:out value="${xml}" escapeXml="false"/><br/>

In the snippet above we used

  • c:import to read a file on the server, and store content inside a varuable
  • c:out to output the content of a variable to the page (you could escape xml)

See the screenshoot

To make some further test with the jstl/core we insert another two snippet, for loops. The first show a simple loop that build a table

<table border="1">
<tr>
		<th>i:</th>
		<c:forEach var="i" begin="1" end="10" step="1">
			<td><c:out value="${i}"/></td>
		</c:forEach>
	</tr>
</table>

The second list page parameters. Take care that param is an implicit Map object.

<ul>
	<c:forEach var="pageParameters" items="${param}">
		<li><c:out value="${pageParameters.key}"/> =
			<c:out value="${pageParameters.value}"/></li>
	</c:forEach>
</ul>

The result, obvious, are a table and a list. But instead to watch the picture,  you can build yourself.

Enjoy.

References

 

 

 

PL / SQL

Some PL/SQL snippets of code

Backup and recovery of a table

First create a backup copy of your table

backup
create table MY_TABLE_BACK
AS
select * from MY_TABLE

After your stuff, recovery the original table

insert into MY_TABLE
select * from MY_TABLE_BACK
delete all rows
delete from MY_TABLE_BACK

Interactive input with &

select *
from orders
where id = &ID

before executing the query will appear a Dialog asking for variable

Find keys referencing your table

-- find foreign keys
select table_name from user_constraints
where r_constraint_name in
  (select constraint_name
     from user_constraints
     where constraint_type in ('P','U')
     and table_name = upper('&tableOfInterest')
  )

Group and count

Group by and count limit to ten rows

select *
  from (select count(*), t.id_order
          from order_cart t
         group by m.id_order
         order by count(*) desc)
 where rownum < 10

 Rename Columns

alter table MY_TABLE_NAME
rename column OLD_NAME to NEW_NAME

List column names

SELECT column_name
FROM user_tab_cols
WHERE table_name = 'MY_TABLE_NAME'

 

List available tables in a schema

The following script list data for available tables in specified schema, and order rows by table name.

SELECT *
FROM all_tables
WHERE owner = upper('&SCHEMA_NAME')
ORDER BY table_name

Since there is the parameter &SCHEMA_NAME, before executing the query will appear a dialog in which you can insert the name of schema.

References:

http://stackoverflow.com/questions/926437/is-there-a-way-to-view-relationships-in-oracle-sql-developer

http://viralpatel.net/blogs/2009/08/fast-data-copy-with-create-table-select-from-in-plsql.html

 

XSL to XHTML

This article explain how to use XSL Transformation to build an XHTML document.

XSL Transform for build XHTML

Assume we want transform following XML document

<?xml version="1.0" encoding="UTF-8"?>
<books>
    <book isbn="9781849511742" title="WordPress 3.0 jQuery" pdate="24/09/2010"/>
    <book isbn="9781849511407" title="WordPress Top Plugins" pdate="21/09/2010"/>
    <book isbn="9781847196569" title="WordPress 2.7 Complete" pdate="02/06/2009"/>
    <book isbn="9781849510080" title="WordPress 2.8 Theme Design" pdate="30/11/2009"/>
    <book isbn="9781847197382" title="WordPress 2.7 Cookbook" pdate="15/07/2009"/>
    <book isbn="9781847193599" title="WordPress Plugin Development: Beginner's Guide" pdate="16/02/2009"/>
    <book isbn="9781847198822" title="WordPress and Flash 10x Cookbook" pdate="19/04/2010"/>
    <book isbn="9781849512367" title="Joomla! 1.5 Cookbook" pdate="26/10/2010"/>
    <book isbn="9781849511803" title="Joomla! 1.5 Top Extensions Cookbook" pdate="18/10/2010"/>
    <book isbn="9781849512220" title="Building job sites with Joomla!" pdate="21/09/2010"/>
    <book isbn="9781849511704" title="Joomla! 1.5 Site Blueprints" pdate="26/05/2010"/>
    <book isbn="9781847199904" title="Joomla! 1.5: Beginner's Guide" pdate="05/03/2010"/>
    <book isbn="9781847195166" title="Joomla! 1.5x Customization: Make Your Site Adapt to Your Needs" pdate="24/08/2009"/>
</books>

An XSL Transform take on XML input and will produce output in several  formats. To produce XHTML output we must define the correct output format at the top of the document.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:output method="xml" version="1.0" encoding="UTF-8"
        doctype-public="-//W3C//DTD XHTML 1.1//EN"
        doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
        indent="yes"/>

    <xsl:template match="/">
        <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
                <title>Books</title>
            </head>
            <body>
                <h1>Books</h1>
                <table>
                    <tr>
                        <th>isbn</th>
                        <th>title</th>
                        <th>publish date</th>
                    </tr>
                    <xsl:for-each select="books/book">
                        <tr>
                            <td><xsl:value-of select="@isbn"/></td>
                            <td><xsl:value-of select="@title"/></td>
                            <td><xsl:value-of select="@pdate"/></td>
                        </tr>
                    </xsl:for-each>
                </table>
            </body>
        </html>
    </xsl:template>

</xsl:stylesheet>

The transform is quite simple, and here, there is an image showing the output result.

You can download source code

References

 

WordPress per il business

Questo articolo introduce WordPress per gli utenti business,

Web-log-ging

A prima vista il l blogging sembra un esercizio di ‘personal publishing’. La maggior parte dei blog, infatti, assomigliano a diari personali, senza esplicite esigenze di business. Ciò nonostante molti ‘personal bloggers’ hanno trovato il modo di monetizzare la propria attività. Attualmente c’è una categoria, in crescita, di ‘professional bloggers’, le cui entrate dipendono per la maggior parte dai proventi dell’attività di scrittura sui loro weblog (Blog).

Da tempo politici e giornalisti influenti si sono introdotti nella blog-o-sfera. Da allora non è passato molto tempo prima che le aziende si accorgessero dei potenziali benefici che si possono ottenere tramite un blog. Attualmente il ‘business blogging’ è un luogo comune; e sempre più utenti si aspettano di trovare un Blog nei siti visitati in rete.

In generale si può distinguere tra tre tipi di weblog: Personali, Politici e Business.

Business Weblog

La chiave del successo è l’aver una chiara visione della ‘blogging strategy’, cioè sapere quello che “vuoi fare tramite il blog”.  Chiarita la strategia, allora si possono cominciare a porre obiettivi concreti per l’attività del proprio.

il weblog può essere una forma di marketing a bassso costo – si può ottenere valore con un investimento relativamente basso.

Alcuni obiettivi plausibili per il blogging sono: aumentare le vendite; aggiungere valore a prodotti e servizi; migliorare l’immagine aziendale (raise awareness of your company?); dimostrare esperienza e conoscenza; fornire al cliente servizio e supporto; migliorare le pubbliche relazioni (media, reputazione, etc..); convogliare il traffico verso determinati siti web; caratterizzare maggiormente l’immagine aziendale.

Si possono perseguire uno o più obiettivi di quelli presentati, purchè compatibili tra loro.

Categorie di Business Weblogs

Consapevole degli obiettivi tattici, si può determinare che tipo di blog costruire:

  • Di Prodotto: aumentare le vendite ed aggiungere valore
  • Aziendale / Corporate: molti degli obiettivi esposti sopra
  • New: dimostrare esperienza, dimostrare personalità, aumentare le vendite.
  • Expert weblogs – strategic goals: raising awareness of the expert’s business activities; demonstrating knowledge and expertise and driving traffic to the expert’s other websites.

Strumenti utili:

  • contact form 7: per avere una CAPTCHA contact form
  • google XML sitemaps: aiuta i motori di ricerca per un indicizzazione migliore
  • SEO Super Super Comments: crea una nuova pagina dinamica per ogni commento
  • gain competitive edge with a well polished weblog

for who start a business blog using WordPress.

Riferimenti

JavaScript Orientato agli Oggetti

Alcuni suggerimenti e riferimenti per programmare javascript, in stile object – oriented.

Javascript Object Oriented

Esempi jQuery

Alcune porzioni di codice che mostrano come usare jQuery

// return true if the element is an input
$('#elementId').is('input');
// get the name of the tag
$('#elementId').get(0).tagName

Definizione di oggetti semplici

esempio semplice: definire un oggetto con javascript semplice [link_01]

Questo esempio mostra come definire ed usare un oggetto in javascript.  Per prima cosa di definisce l’oggetto, con una sintassi simile a quella di una funzione; poi si aggiungono un costruttore ed un metodo, attraverso la proprietà prototype.

// define Object as a function
function StringBuffer(){
  this.buffer = [];
}
// add a constructor with one string parameter
StringBuffer.prototype.append = function append(string){
  this.buffer.push(string);
  return this;
}
// add one method to the object
StringBuffer.prototype.toString = function toString(){
  return this.buffer.join('');
}

Ora si può istanziare l’oggetto ed usare i suoi dati ed i suoi metodi.

// new instance
var buf = new StringBuffer();
// use the instance
buf.append('hello');
buf.append('world');
alert(buf.toString());

Riferimenti

Gimp

Gimp è un programma gratuito per il disegno ed il fotoritocco. GIMP è uno strumento professionale, con molte funzionalità, e nulla da invidiare ai programmi professionali come Photoshop, CorelDraw, etc.

Vedi il sito ufficiale, e la documentazione ufficiale

In rete ci sono molti tutorial che spiegano come usare GIMP per fare grafica. Elenco alcuni tutorial che di mio interesse:

Tutorial

Logo 2.0 con GIMP (IT), su HTML.it

Web 2.0 Text logo (EN)

Gimp Tutorial: Logo-Design ( DE ), video su YouTube

Creare un bigliettino da visita con GIMP (IT), video su YouTube

Create a grunge business card using GIMP (EN)

Design a business card with the GIMP (EN)

40 + Excellent GIMP Tutorial for designers  (EN)