Tableau permettant de convertir un code hexadecimal de la forme #000000 vers le code decimal rouge, vers et bleu
1 <form method="POST" action="converter.php">
2
3 <?php
4
5 if (isset ($_POST['hexa']) )
6
7 {
8 $k=0;
9
10 $hexa=$_POST['hexa'];
11 if ($hexa[0]=='#')
12 {
13 $k=1;
14 }
15 $r=hexanum(substr($hexa,0+$k,2));
16 $v=hexanum(substr($hexa,2+$k,2));
17 $b=hexanum(substr($hexa,4+$k,2));
18
19 }
20
21
22
23 function hexanum($toto)
24 {
25 $ko=false;
26 $hexa=$toto;
27 $i=strlen($hexa);
28 $j=0;
29 $c=substr($hexa,i-1,1);
30 $store=0;
31 while ($i>0)
32 {
33 switch ($c)
34 {
35 case 'A' :
36 $store=$store+pow(16,$j)*10;
37 break;
38
39 case 'B' :
40 $store=$store+pow(16,$j)*11;
41 break;
42
43 case 'C' :
44 $store=$store+pow(16,$j)*12;
45 break;
46
47 case 'D' :
48 $store=$store+pow(16,$j)*13;
49 break;
50
51 case 'E' :
52 $store=$store+pow(16,$j)*14;
53 break;
54
55 case 'F' :
56 $store=$store+pow(16,$j)*15;
57 break;
58
59 default:
60 //echo gettype($c+0);
61 //if (gettype($c)=="integer")
62 // {$store=$store+pow(16,$j)*$c;echo "bon";}
63 // else
64 // {$ko=true;echo "pas bon";}
65 $store=$store+pow(16,$j)*$c;
66 break;
67 }
68 $i=$i-1;
69 $c=substr($hexa,$i-1,1);
70 $j=$j+1;
71 }
72 //if ($ko==true)
73 //{$store="pas bon2";}
74 return $store;
75 }
76
77 ?>
78
79 <table>
80
81 <tr>
82 <td><b>Conversion de codes de couleurs</b></td>
83 </tr>
84 <tr>
85 <td>R : </td>
86 <td><input type="text" name="r" tabindex="1" VALUE="<?php echo $r; ?>" /></td>
87 </tr>
88 <tr>
89 <td>V : </td>
90 <td><input type="text" name="v" tabindex="1" VALUE="<?php echo $v; ?>" /></td>
91 <td><input type="submit" name="calcul" value="Convertir hexa --> decimal"/></td>
92 <td><input type="text" name="hexa" tabindex="1" VALUE="<?php echo $hexa; ?>" /></td>
93 </tr>
94 <tr>
95 <td>B : </td>
96 <td><input type="text" name="b" tabindex="1" VALUE="<?php echo $b; ?>" /></td>
97 </tr>
98 </table>
99
100 </form>
Tested on linux, FreeBSD, MacOS X, and solaris with gcc and suncc
1 /**
2 DO WHAT THE FUCK YOU WANT TO, BUT IT'S NOT MY FAULT PUBLIC LICENSE
3 Version 1, November 2007
4
5 Copyright (C) 2004 Sam Hocevar
6 14 rue de Plaisance, 75014 Paris, France
7 Everyone is permitted to copy and distribute verbatim or modified
8 copies of this license document, and changing it is allowed as long
9 as the name is changed.
10
11 DO WHAT THE FUCK YOU WANT TO, BUT IT'S NOT MY FAULT PUBLIC LICENSE
12 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
13
14 0. You just DO WHAT THE FUCK YOU WANT TO, BUT IT'S NOT MY FAULT.
15 **/
16
17 #include <stdlib.h>
18 #include <stdio.h>
19 #include <sys/utsname.h>
20
21 int main(void)
22 {
23 struct utsname uname_s;
24
25 if (uname(&uname_s) >= 0) {
26 printf("Sysname\t: %s\nNodename: %s\nRelease\t: %s\nVersion\t: %s\nMachine\t: %s\n",
27 uname_s.sysname,
28 uname_s.nodename,
29 uname_s.release,
30 uname_s.version,
31 uname_s.version);
32 #ifdef _GNU_SOURCE
33 printf("Domain\t: %s\n", uname_s.domainname);
34 #endif
35 printf("\n");
36 return EXIT_SUCCESS;
37 }
38
39 return EXIT_FAILURE;
40 }
This snippet show how to embed in a makrdown content with safe html. It don't use the plugin possibility of markdownd to be more easyly integrated in your code.
1 # -*- coding: utf-8 -*-
2 from pygments import highlight, lexers, formatters
3 from markdown import markdown
4 import re
5
6
7 lexers_aliases = ['aconf', 'apache', 'apacheconf', 'bash', 'bat', 'bbcode', 'befunge', 'bf', 'boo', 'brainfuck', 'c', 'c#',
8 'c++', 'cfg', 'cpp', 'csharp', 'css', 'css+django', 'css+erb', 'css+genshi', 'css+genshitext', 'css+jinja',
9 'css+mako', 'css+myghty', 'css+php', 'css+ruby', 'css+smarty', 'd', 'delphi', 'diff', 'django', 'dylan', 'erb',
10 'genshi', 'genshitext', 'groff', 'haskell', 'html', 'html+django', 'html+erb', 'html+genshi', 'html+jinja',
11 'html+kid', 'html+mako', 'html+myghty', 'html+php', 'html+ruby', 'html+smarty', 'ini', 'irb', 'irc', 'java',
12 'javascript', 'javascript+django', 'javascript+erb', 'javascript+genshi', 'javascript+genshitext', 'javascript+jinja',
13 'javascript+mako', 'javascript+myghty', 'javascript+php', 'javascript+ruby', 'javascript+smarty', 'jinja', 'js',
14 'js+django', 'js+erb', 'js+genshi', 'js+genshitext', 'js+jinja', 'js+mako', 'js+myghty', 'js+php', 'js+ruby',
15 'js+smarty', 'jsp', 'kid', 'latex', 'lua', 'make', 'makefile', 'mako', 'man', 'mf', 'minid', 'moin', 'mupad',
16 'myghty', 'nroff', 'obj-c', 'objc', 'objective-c', 'objectivec', 'objectpascal', 'ocaml', 'pas', 'pascal', 'perl',
17 'php', 'php3', 'php4', 'php5', 'pl', 'py', 'pycon', 'pytb', 'python', 'raw', 'rb', 'rbcon', 'redcode', 'rest',
18 'restructuredtext', 'rhtml', 'rst', 'ruby', 'scheme', 'sh', 'smarty', 'sources.list', 'sourceslist', 'sql', 'tex',
19 'text', 'trac-wiki', 'vb.net', 'vbnet', 'vim', 'xml', 'xml+django', 'xml+erb', 'xml+genshi', 'xml+jinja', 'xml+kid',
20 'xml+mako', 'xml+myghty', 'xml+php', 'xml+ruby', 'xml+smarty']
21
22 """
23 We cache lexer aliases to speed parsing. To update them, get lexers_aliases like this :
24 tlexers=lexers.get_all_lexers()
25 alexers=[]
26 for l in tlexers:
27 for a in l[1]:
28 alexers.append(a)
29
30 alexers.sort()
31 print alexers
32 """
33
34 content=u"""
35 test embeded code + *markdown*
36
37 {{{
38 def save(self):
39 if not self.id:
40 self.created = datetime.now()
41 self.updated = datetime.now()
42 self.content_hilighted = self.hilight()
43 if self.description:
44 self.description_html = markdown(self.description, safe_mode=True)
45
46 super(Snippet, self).save()
47 }}}
48
49
50 {{{#!python
51 def hilight(content):
52 code = re_code.findall(content)
53 for c in code:
54 print c
55 }}}
56
57 <script type="text/javascript" charset="utf-8">
58 updateTagContent()
59 </script>
60
61
62 {{{#!c
63 static int
64 isAlphanum(int c)
65 {
66 return ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') ||
67 (c >= 'A' && c <= 'Z') || c == '_' || c == '$' || c == '\\' ||
68 c > 126);
69 }
70
71 }}}
72
73 test
74 """
75
76 CODE_TAG_START = "{{{"
77 CODE_TAG_END = "}}}"
78
79 re_code = re.compile('%s(?P<code>.*?)%s' % (re.escape(CODE_TAG_START), re.escape(CODE_TAG_END)), re.DOTALL)
80
81 in_tag=False
82 hilighted=""
83 lexer=None
84 for p in re_code.split(content):
85 if p:
86 if in_tag:
87 code_str=p
88 lang=""
89
90 if p.startswith("#!"):
91 c=""
92 i=0
93 while (c!=" " and c !="\n") and i<len(code_str):
94 lang+=c
95 c=code_str[i]
96 i+=1
97 if len(lang)>2:
98 lang=lang[2:]
99 print lang
100
101 if lang in lexers_aliases:
102 lexer=lexers.get_lexer_by_name(lang)
103 else:
104 try:
105 lexer = lexers.guess_lexer(code_str)
106 except:
107 lexer = lexers.get_lexer_by_name('text')
108
109 print lexer
110 hilighted+= "<div class=\"hilight\">%s</div>" % highlight(p,lexer,
111 formatters.HtmlFormatter(linenos='inline',
112 cssclass="source",
113 lineseparator="<br />"))
114 else:
115 hilighted+=markdown(p, safe_mode=True)
116 in_tag = not in_tag
117
118 print hilighted
Pages : 1