C'est une méthode simple pour transformer les liens en boutons. Cette méthode n'a rien d'original mais elle permet d'obtenir le même affichage sous IE et mozilla. Sans vrai bidouille au niveau du CSS. Attention au texte dans le bouton, il peut dépasser d'un navigateur à l'autre. L'astuce vient de l'encapsulation de la ligne de boutons dans un "div" de hauteur fixe.
1 Partie HTML :
2 <div id="Menu1Ligine">
3 <div class="ElementMenu">
4 <a href="First.html">One</a>
5 </div>
6 <div class="ElementMenu">
7 <a href="Second.html">Two</a>
8 </div>
9 </div>
10
11 Partie CSS :
12 .ElementMenu a {
13 float : left;
14 padding : 3px;
15 min-width: 120px;
16 width: 120px;
17 height: 18px;
18 text-align: center;
19 text-decoration: none;
20 border:1px solid #FCC212;
21 margin : 3px;
22 color: #000000;
23 }
24
25 .ElementMenu a:hover {
26 background-color:#EEA60D;
27 border:1px solid #FCC212;
28 color: #FFFFFF;
29 }
30
31 .ElementMenu a:active {
32 background-color:#EEA60D;
33 border:1px solid #FCC212;
34 color: #FFFFFF;
35 }
36
37 #Menu1Ligine {
38 display : block;
39 margin : 0px;
40 height : 25px;
41 padding-top : 95px;
42 }
Coordonnées de la souris
1 /**
2 * Coordonnées de la souris
3 */
4
5 if( document.captureEvents && Event.MOUSEMOVE ) {
6 //remove this part if you do not need Netscape 4 to work
7 document.captureEvents( Event.MOUSEMOVE );
8 document.captureEvents( Event.MOUSEOVER );
9 }
10 document.onmousemove = mouseCoord;
11
12 var calque;
13 var mousePosX = 0;
14 var mousePosY = 0;
15
16 function mouseCoord(e) {
17 if( !e ) {
18 if( window.event ) {
19 //Internet Explorer
20 e = window.event;
21 } else {
22 //total failure, we have no way of referencing the event
23 return;
24 }
25 }
26 if( typeof( e.pageX ) == 'number' ) {
27 //most browsers
28 var xcoord = e.pageX;
29 var ycoord = e.pageY;
30 } else if( typeof( e.clientX ) == 'number' ) {
31 //Internet Explorer and older browsers
32 //other browsers provide this, but follow the pageX/Y branch
33 var xcoord = e.clientX;
34 var ycoord = e.clientY;
35 var badOldBrowser = ( window.navigator.userAgent.indexOf( 'Opera' ) + 1 ) ||
36 ( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) ||
37 ( navigator.vendor == 'KDE' )
38 if( !badOldBrowser ) {
39 if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
40 //IE 4, 5 & 6 (in non-standards compliant mode)
41 xcoord += document.body.scrollLeft;
42 ycoord += document.body.scrollTop;
43 } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
44 //IE 6 (in standards compliant mode)
45 xcoord += document.documentElement.scrollLeft;
46 ycoord += document.documentElement.scrollTop;
47 }
48 }
49 } else {
50 //total failure, we have no way of obtaining the mouse coordinates
51 return;
52 }
53 mousePosX = xcoord;
54 mousePosY = ycoord;
55 }
text server listing on TCP 8080, evaluate input and send result usage:run server in one terminal, and "nc localhost 8080" in another Python script without any space nor tab, for digit: only use 0 and 1 Victor Stinner - 2007/10/02 - source code under GNU GPLv3 license
1 l=lambda(i):lambda(l):i.__getattribute__(\
2 O(l));i=lambda(i):l(__import__(O(i)));j=(\
3 ord,''.join);o=lambda(l):i('speniy')(l);O\
4 =lambda(I):j[1](chr((j[0](l)-i)%0x100)for\
5 (i,l)in(enumerate(I)));k=i('_`dxmqzpvhi')\
6 ;k=(k('rbpji'),k('ewco'),k('ljuw'),l(o(''\
7 'speniy')(o('AGaLRJZ'),o('SPENcXZYMJW')))\
8 );I=i('iuguxtus{')('tbmh{mosm');i=l([k[-1\
9 ](i[0])(*i[1:])for(i)in(('sfvvshqvx}',o(\
10 'SPNbWTIRM]'),o('SPaUIZYLIMN]'),1,),('bj'\
11 'pg',('',010*1010),),('ljuwis',1),('adeh'\
12 'ty',))][-1][0]);k=k[:-1];i=(i('rfey'),i(\
13 'sfpg'));k[-1](i[1]("%s\n"%k[1](j[-1](I(\
14 lambda(I):j[0](I)^10,(i[0](1)for(k)in(k[0\
15 ](101)))))))for(O)in(k[0](1010)))
Comment envoyer un mail au format html en python. Pratique pour de gros envois de mail.
1 import smtplib
2 import MimeWriter
3 import mimetools
4 import StringIO
5
6 def sendHtmlMail(to,frommail,text,html):
7 encoding = "base64"
8 charset = "iso-8859-15"
9
10 #déclaration des buffers
11 out = StringIO.StringIO()
12 htmlin = StringIO.StringIO(html)
13 txtin = StringIO.StringIO(html)
14
15 #déclaration et initialisation du writer
16 writer = MimeWriter.MimeWriter(out)
17 writer.addheader("Subject", text)
18 writer.addheader("MIME-Version", "1.0")
19 writer.addheader("From", frommail)
20 writer.addheader("To", to)
21 writer.startmultipartbody("alternative")
22 writer.flushheaders()
23
24 #ajout de la partie text
25 textPart = writer.nextpart()
26 textPart.addheader("Content-Transfer-Encoding", encoding)
27 pout = textPart.startbody("text/plain", [("charset", charset)])
28 mimetools.encode(txtin, pout, encoding)
29 txtin.close()
30
31 #On ajoute la partie html
32 htmlPart = writer.nextpart()
33 htmlPart.addheader("Content-Transfer-Encoding", encoding)
34 pout = htmlPart.startbody("text/html", [("charset", charset)])
35 mimetools.encode(htmlin, pout, encoding)
36 htmlin.close()
37
38 #on clot le mail
39 writer.lastpart()
40 mail = out.getvalue()
41 out.close()
42 smtp = smtplib.SMTP("localhost")
43 #smtp.connect()
44 smtp.sendmail(frommail, [to], mail)
45 smtp.close()
Code en C permettant l'accès a une base de donnée MySQL C code wich permit MySQL access
1 /*********************************************************
2 **Attention il est impératif de compiler ce code avec l'option de compilation -lmysqlclient
3 **********************************************************/
4
5 #include <stdio.h>
6 #include <errno.h>
7 #include <stdlib.h>
8 #include <iostream.h>
9 #include <fstream>
10 #include <mysql/mysql.h>
11 #include <sys/types.h>
12 #include <sys/wait.h>
13
14 #define MY_SERVER_HOST "localhost"
15 #define MY_SERVER_PORT 0
16 #define MY_ACCOUNT "root"
17 #define MY_PASS "test"
18 #define MY_DB_NAME "itest"
19 #define MY_TABLE_NAME "test_tbl"
20 #define MY_UX_SOCK NULL
21 #define MY_CLIENT_FLAG 0
22
23 void main()
24 {
25 MYSQL *mysql;
26 MYSQL_RES *res;
27 MYSQL_ROW row;
28 MYSQL_ROW rowchamps;
29 const char *query;
30 string qutmp;
31
32 int t,f,tt,ff;
33
34 mysql=mysql_init(NULL);
35
36 if (!mysql_real_connect(mysql,MY_SERVER_HOST,MY_ACCOUNT,MY_PASS,bd,MY_SERVER_PORT,MY_UX_SOCK,MY_CLIENT_FLAG)) {
37 printf( "Erreur de connexion : %s\n",mysql_error(mysql));
38 }
39 else {
40 qutmp = "SHOW FULL COLUMNS FROM TABLE ";
41 query = qutmp.c_str();
42 t=mysql_real_query(mysql, query, (unsigned int) strlen(query));
43 if((res=mysql_use_result(mysql))) {
44 f=mysql_num_fields(res);
45 while((row=mysql_fetch_row(res))) {
46 for(f=0;f<t;f++){
47 cout<<row[f]<<endl;
48 }
49 }
50 mysql_free_result(res);
51 }
52 }
53 mysql_close(mysql);
54 }
backtrace() peut-être utilisé un peut partout pour trouver ce qui ne va pas dans son code. Très utile lorsque l'on travaille en orienté objet.
1 <?php
2 // print_r avec joli formatage
3 function xdump($v) { echo '<pre>'; print_r($v); echo '</pre>'; }
4
5 // Même chose mais avec var_dump
6 function xvdump($v) { echo '<pre>'; var_dump($v); echo '</pre>'; }
7
8 // affiche un backtrace et meurt
9 function backtrace($err='') {
10 echo '<div id="err">';
11 if ($err != '') echo "<strong>Erreur : $err</strong><br/>\n";
12 echo "<strong>Traceback </strong>:<pre>";
13 foreach( debug_backtrace() as $v ) xdump( $v );
14 echo "</pre></div>";
15 die;
16 }
17 ?>
-- Nécessite le programme links
1 #!/bin/bash
2
3 links -dump http://www.whatismyip.com/automation/n09230945.asp | sed -e 's/ //g'
Pages : 1