Ruby 简洁案例

unit_of_time =
   case num
   when 0..60:           "second" 
   when 0..60 * 60:      "minute" 
   when 0..60 * 60 * 24: "hour" 
   else                  "day" 
   end

unit_of_time = case
  when num < 60:           "second" 
  when num < 60 * 60:      "minute" 
  when num < 60 * 60 * 24: "hour" 
  else                     "day" 
end

Ruby 简明如果

unit_of_time =
   if num < 60:              "second" 
   elsif num < 60 * 60:      "minute" 
   elsif num < 60 * 60 * 24: "hour" 
   else                      "day" 
   end

CSS 帖子标题

h2 a {
	color: #DC5E04;
	font-size: large;
	font-weight: normal;
        text-transform: uppercase;
        border-left: 1.2em solid #DC5E04;
	padding: 0 0 0 10px;
        margin: 0;
}

Ruby auto_drop_migration.rb

module AutoDropMigration
  module Migration
    # Drop all tables and indexes created by the migration
    #   class AddUser < ActiveRecord::Migration
    #     def self.up
    #       ...
    #     end
    #     
    #     def self.down
    #       drop_created_tables_and_indexes(__FILE__)
    #     end
    #     
    def drop_created_tables_and_indexes(migration)
      File.open(migration) do |fp|
        fp.readlines.reverse.each do |line|
          if line =~ /^\s+add_index\s+(.*)$/
            args = eval("parse_args(#{$1})")
            eval("remove_index #{args[0..1].join(',')}") rescue nil
          elsif line =~ /^\s+add_foreign_key\s+(.*)$/
            eval("remove_foreign_key #{$1}") rescue nil
          elsif line =~ /^\s+create_table\s+:([^,]+)(,.*)$/
            drop_table($1) rescue nil
          end
        end
      end
    end
    
    def parse_args(*s) 
      s
    end
  end
end

ActiveRecord::Migration.extend(AutoDropMigration::Migration)

SQL 如何在MySQL中删除数据库

drop databasename;

ASP 数据库连接字符串(使用DSN)

<%
	'Open the database connection
	Set objConn = Server.CreateObject("ADODB.Connection")
	objConn.Open "DSN=dsn_name;UID= ;PWD= "
%>

PHP 功能日期

// Affichage d'une chaine de la forme YYYYMMJJ
sprintf("%02d/%02d/%04d", substr($date,6,2), substr($date,4,2), substr($date,0,4));
// Chaine YYYYMMJJ representant la date 
$date_courante = date("YmdHis", time());
// Chaine YYYYMMJJ representant la date d'hier 
$date=date("Ymd", mktime(0, 0, 0, date("m") , date("d") - 1, date("Y")));

//h:m:s entre 2 dates 
$time_submitted=mktime(substr($bug["date_submitted"],11,2),substr($bug["date_submitted"],14,2),substr($bug["date_submitted"],17,2),substr($bug["date_submitted"],5,2),substr($bug["date_submitted"],8,2),substr($bug["date_submitted"],0,4));
$time_resolved=mktime(substr($bug["date_resolved"],11,2),substr($bug["date_resolved"],14,2),substr($bug["date_resolved"],17,2),substr($bug["date_resolved"],5,2),substr($bug["date_resolved"],8,2),substr($bug["date_resolved"],0,4));
$bug["time_to_resolve"]=calcul_hours($time_resolved-$time_submitted);

function calcul_hours($temps)
{
  //combien d'heures ?
  $hours = floor($temps / 3600);

  //combien de minutes ?
  $min = floor(($temps - ($hours * 3600)) / 60);
  if ($min < 10)
    $min = "0".$min;

  //combien de secondes
  $sec = $temps - ($hours * 3600) - ($min * 60);
  if ($sec < 10)
    $sec = "0".$sec;
        
  return $hours."h".$min."m".$sec."s";
}

PHP 出口d'une表MYSQL dans un fichier CSV

//**** Extraction de la table et création du fichier CSV
$FileOut = "/data/web_dev/Voila_shopping/liens_voila.csv";
$sql="SELECT * FROM liens ORDER BY mot";
$TABLiens=$myDB_select->queryAllRecord($sql);

$fpout = fopen($FileOut, "w");
if(count($TABLiens)) foreach($TABLiens as $lien) {
	fwrite($fpout,$lien[mot].";".$lien[titre].";".$lien[descriptif].";".$lien[lien]."
");
}
fclose($fpout);

PHP 重定向

header("Location: identification.php3");

PHP Affichage des变量POST

echo '<pre><br>';print_r($HTTP_POST_VARS);echo'</pre>';