CSS 红色电子 - CSS

/* andreas01 - an open source xhtml/css website layout by Andreas Viklund  - http://andreasviklund.com . Free to use for any purpose as long as the proper credits are given to the original author.

		Version: 1.3 (Nov 28, 2005)

		Screen layout: */

	body{
		margin:0 auto;
		padding:0;
		font:76% Verdana,Tahoma,Arial,sans-serif;
		background:#f4f4f4 url(bg.gif) top center repeat-y;
		color:#303030;
	}

	#wrap{
		background:#ffffff;
		color:#303030;
		margin:0 auto;
		width:760px;
	}

	#header{
		clear:both;
		margin:20px 0 0 0;
		padding:0;
		height:45px;
	}

	#header h1{
		width:250px;
		margin:0 0 10px 0;
		float:left;
	}

	#header p{
		width:500px;
		float:right;
		text-align:center;
		color:#a0a0a0;
		margin:0 0 10px 0;
		font-size:0.8em;
		line-height:1.2em;
		background-color:inherit;
	}

	#frontphoto{
		margin:0 0 10px 0;
		border:0;
	}

	#avmenu{
		clear:left;
		float:left;
		width:150px;
		margin:0 0 10px 0;
		padding:0;
		font-size:0.9em;
	}

	#avmenu ul{
		list-style:none;
		width:150px;
		margin:0 0 20px 0;
		padding:0;
		font-size:1.1em;
	}

	#avmenu li{
		margin-bottom:4px;
	}

	#avmenu li a{
		font-weight:bold;
		height:20px;
		text-decoration:none;
		color:#505050;
		display:block;
		padding:6px 0 0 10px;
		background:#f4f4f4;
		border-left:4px solid #cccccc;
	}

	#avmenu li a:hover{
		background:#eaeaea;
		color:#286ea0;
		border-left:4px solid #286ea0;
	}

	.announce{
		margin:10px 0 10px 0;
		padding:10px;
		width:130px;
		color:#505050;
		background-color:#f4f4f4;
		line-height:1.3em;
	}

	#extras{
		float:right;
		width:120px;
		margin:0 0 10px 0;
		padding:0;
		font-size:0.9em;
		line-height:1.5em;
	}

	#extras p{
		margin:0 0 1.5em 0;
	}

	#content{
		margin:0 130px 20px 160px;
		border-left:1px solid #f0f0f0;
		border-right:1px solid #f0f0f0;
		padding:0 10px 0 10px;
		line-height:1.6em;
		text-align:left;
	}

	#content h2{
		font-size:1.5em;
		margin:0 0 0.5em 0;
	}

	#content img{
		padding:1px;
		display:inline;
		background:#cccccc;
		color:#303030;
		border:4px solid #f0f0f0;
	}
	
	 
	h3{
		font-size:1.3em;
		margin:0 0 10px 0;
	}

	a{
		text-decoration:none;
		color:#286ea0;
	}

	a:hover{
		text-decoration:underline;
		color:#286ea0;
	}

	a img{
		border:0;
	}

	#footer{
		clear:both;
		margin:0 auto;
		padding:10px 0 20px 0;
		border-top:4px solid #f0f0f0;
		width:760px;
		text-align:center;
		color:#808080;
		font-size:0.9em;
	}

	#footer a{
		color:#808080;
		text-decoration:none;
	}

	#footer a:hover{
		text-decoration:underline;
	}

	.left{
		margin:10px 10px 5px 0;
		float:left;
	}

	.right{
		margin:10px 0 5px 10px;
		float:right;
	}

	.textright{
		text-align:right;
	}

	.center{
		text-align:center;
	}

	.small{
		font-size:0.8em;
	}

	.bold{
		font-weight:bold;
	}

	.hide{
		display:none;
	}
	@font-face {
		font-family: Brush Script MT;
		font-style:  normal;
		font-weight: normal;
		src: url(http://www.idvsac.com/redelectrica/BRUSHSC1.eot);
	}
	span.rojo {color: #DE0000;
		font-family: 'Brush Script MT', serif;
		font-style: italic;
	}
	span.rojo1 {
		color: #DE0000;
		font-family: 'Brush Script MT', serif;
		font-style: italic;
		margin-left : -0.4em;
	}
	span.azul {color: #005CA1;
		font-family: 'Brush Script MT', serif;
		font-style: italic;
	}

PHP Php extraer mayor valor de un array

function mayorValor( $array ){
	$a = array_unique( $array );
	$s = 0;
	if( is_array( $a ) )
		foreach( $a as $v )
			$s = intval( $v ) > $s ? $v : $s;
	return $s;
}

$arr = array(9,3,5,6,7,8,99,9,7,8,9,4);
echo mayorValor( $arr ) #out 99

Python Obtener la ip del ordenador

socket.getaddrinfo(socket.gethostname(), None)[0][4][0]

JavaScript Argumentos opcionales enunafunción

var funcEjemplo = function(nombre){
    //Si el segundo argumento de la función contiene algo lo tenemos.
    //De lo contrario opciones es un objeto vacío.
    var opciones = arguments[1] || {};

    //Asignamos las opciones a variables normales o ponemos valores por defecto
    var saludo = opciones.saludo || "Hola";
    var mensaje = opciones.mensaje || "¿Qué tal?";

    //Hacemos algo supuestamente útil ;D
    alert(saludo + " " + nombre + ". " + mensaje);
}

funcEjemplo("Sendoa", { saludo: "Agur", mensaje: "Ondo pasa!" } );

JavaScript JavaScript重定向

<script type="text/javascript"> 
     // taken from http://evolt.org/article/list/20/416/ 
         // <![CDATA[ 
     var Splash = GetCookie('SplashSkip'); 
     var ReDirected = GetCookie('SplashReDirected'); 
  
     ReDirect('/welcome'); 
  
     function ReDirect (URL) { 
  
         SetCookie('SplashSkip','TRUE',1); 
  
         if (Splash == 'TRUE' && ReDirected != 'TRUE' ) { 
             SetCookie('SplashReDirected','TRUE'); 
             window.location=(URL); 
         } 
     } 
  
     function getCookieVal (offset) { 
       var endstr = document.cookie.indexOf (";", offset); 
       if (endstr == -1) 
         endstr = document.cookie.length; 
       return unescape(document.cookie.substring(offset, endstr)); 
     } 
  
     function GetCookie (name) { 
       var arg = name + "="; 
       var alen = arg.length; 
       var clen = document.cookie.length; 
       var i = 0; 
       while (i < clen) { 
       var j = i + alen; 
       if (document.cookie.substring(i, j) == arg) 
         return getCookieVal (j); 
       i = document.cookie.indexOf(" ", i) + 1; 
       if (i == 0) break; 
       } 
       return null; 
     } 
  
     function SetCookie(name, value, expDays, path, domain, secure) { 
         // Set cookie with name, value etc provided 
         // in function call and date from above 
         // Number of days the cookie should persist NB expDays='' or undef. => non-persistent 
         if (expDays != null ) { 
             var expires = new Date(); 
             expires.setTime(expires.getTime() + (expDays*24*60*60*1000)); 
         }    
         var curCookie = name + "=" + escape(value) + 
             ((expires) ? "; expires=" + expires.toGMTString() : "") + 
             ((path) ? "; path=" + path : "") + 
             ((domain) ? "; domain=" + domain : "") + 
             ((secure) ? "; secure" : ""); 
         document.cookie = curCookie; 
     } 
         // ]]> 
     </script>

JavaScript 重定向cookie

<script type="text/javascript">
	// adapted from http://evolt.org/article/list/20/416/
		// <![CDATA[
	var Splash = GetCookie('SplashSkip');


	ReDirect('/welcome');

	function ReDirect (URL) {

		SetCookie('SplashSkip','TRUE',1);

		if (Splash == 'TRUE') {

			window.location=(URL);
		}
	}

	function getCookieVal (offset) {
	  var endstr = document.cookie.indexOf (";", offset);
	  if (endstr == -1)
	    endstr = document.cookie.length;
	  return unescape(document.cookie.substring(offset, endstr));
	}

	function GetCookie (name) {
	  var arg = name + "=";
	  var alen = arg.length;
	  var clen = document.cookie.length;
	  var i = 0;
	  while (i < clen) {
	  var j = i + alen;
	  if (document.cookie.substring(i, j) == arg)
	    return getCookieVal (j);
	  i = document.cookie.indexOf(" ", i) + 1;
	  if (i == 0) break; 
	  }
	  return null;
	}

	function SetCookie(name, value, expDays, path, domain, secure) {
		// Set cookie with name, value etc provided
		// in function call and date from above
		// Number of days the cookie should persist NB expDays='' or undef. => non-persistent
		if (expDays != null ) {
			var expires = new Date(); 
			expires.setTime(expires.getTime() + (expDays*24*60*60*1000));
		}	
		var curCookie = name + "=" + escape(value) +
			((expires) ? "; expires=" + expires.toGMTString() : "") +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			((secure) ? "; secure" : "");
		document.cookie = curCookie;
	}
		// ]]>
	</script>

C++ 如何使用SplitterWnd

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
	if(!mSplitWnd.CreateStatic(this, 1, 2)
	||!mSplitWnd.CreateView(0, 0, RUNTIME_CLASS(CPaneC), CSize(20,0), pContext)
	||!mSplitWnd.CreateView(0, 1, RUNTIME_CLASS(CPaneD), CSize(0,0), pContext)){
		TRACE0("FAILED");
	}
//	return CFrameWnd::OnCreateClient(lpcs, pContext); 
	return TRUE;
}

Python 将序列划分为由函数值键入的字典

def partition(iterable, func):
    result = {}
    for i in iterable:
        result.setdefault(func(i), []).append(i) 
    return result

def group(seq):
    result = {}
    for item, category in seq:
        result.setdefault(category, []).append(item)
    return result 

# def is_odd(n):
#     return (n%2) == 1
# l = range(100)
# print partition(l, is_odd)
# print group( (item, is_odd(item)) for item in l)
# print group( (item, item%11) for item in l)    # no need to use lamda/def

C++ 多媒体计时器

/**
 * Multimedia Timer
 *
 * Timer Interrupttion per interval[ms]
 */

#include<windows.h> 
#include<mmsystem.h>

#pragma comment(lib, "winmm.lib")

void CALLBACK TimeProc(UINT uTimerID, UINT uMsg,
                        DWORD dwUser, DWORD dw1, DWORD dw2)
{
  /**
   * Timer Interruption
   */
}

void main()
{
    UINT uDelay = 1000;
    UINT uResolution = 1;
    DWORD dwUser = NULL;
    UINT fuEvent = TIME_PERIODIC; //You also choose TIME_ONESHOT;

    MMRESULT FTimerID;
    timeBeginPeriod(1);
    FTimerID = timeSetEvent(uDelay, uResolution, TimeProc, dwUser, fuEvent);
    if(FTimerID==NULL){
        printf("Failed to generate multimedia timer.\n");
    }

    Sleep(10000);

    timeKillEvent(FTimerID);
    timeEndPeriod(1);
}

Ruby 简单的webrick服务器

#!/usr/bin/ruby

require 'webrick'
include WEBrick

def start_webrick(config = {})
  config.update(:Port => 5001)
  server = HTTPServer.new(config)

  yield server if block_given?
  ['INT', 'TERM'].each do |signal|
    trap(signal) { server.shutdown }
  end
  
  server.start
end

start_webrick(:DocumentRoot => 'path-to-document-root',
              :ServerType => Daemon)