Ruby DayRange

class DayRange SHORT_NAMES = %w[Mon Tue Wed Thu Fri Sat Sun].freeze LONG_NAMES = %w[ Monday Tuesday Wednesday Thursday Friday Saturday Sunday ].freeze def initialize(*days) @days = days.map do |d| ds = d.to_s.downcase.capitalize SHORT_NAMES.index(ds) || LONG_NAMES.index(ds) || d - 1 end rescue raise(ArgumentError, "Unrecognized number format.") unless @days.all? { |d| d.between?(0, 6) } raise ArgumentError, "Days must be between 1 and 7." end raise ArgumentError, "Duplicate days given." unless @days == @days.uniq end def to_s(names = SHORT_NAMES) raise ArgumentError, "Please pass seven day names." unless names.size == 7 @days.inject(Array.new) do |groups, day| if groups.empty? or groups.last.last.succ != day groups << [day] else groups.last << day groups end end.map { |g| g.size > 2 ? "#{g.first}-#{g.last}" : g.join(", ") }. join(", ").gsub(/\d/) { |i| names[i.to_i] } end end

PHP 切换可见性

<script>
var status=1;
function changeObjectVisibility(objectId, newVisibility) {
    // first get a reference to the cross-browser style object 
    // and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
}

function getStyleObject(objectId) {
  // checkW3C DOM, then MSIE 4, then NN 4.
  //
  if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId).style;
   }
   else if (document.all && document.all(objectId)) {  
	return document.all(objectId).style;
   } 
   else if (document.layers && document.layers[objectId]) { 
	return document.layers[objectId];
   } else {
	return false;
   }
}

function toggle() {

	if (status==1) {
		status=0;		
		changeObjectVisibility('container','visible');
	} else {
		status = 1;
		changeObjectVisibility('container','hidden');
	}
}
</script>

PHP strMiddleReduceWordSensitive

function strMiddleReduceWordSensitive ($string, $max = 50, $rep = '[...]') {
   $strlen = strlen($string);

   if ($strlen <= $max)
       return $string;

   $lengthtokeep = $max - strlen($rep);
   $start = 0;
   $end = 0;

   if (($lengthtokeep % 2) == 0) {
       $start = $lengthtokeep / 2;
       $end = $start;
   } else {
       $start = intval($lengthtokeep / 2);
       $end = $start + 1;
   }

   $i = $start;
   $tmp_string = $string;
   while ($i < $strlen) {
       if ($tmp_string[$i] == ' ') {
           $tmp_string = substr($tmp_string, 0, $i) . $rep;
           $return = $tmp_string;
       }
       $i++;
   }

   $i = $end;
   $tmp_string = strrev ($string);
   while ($i < $strlen) {
       if ($tmp_string[$i] == ' ') {
           $tmp_string = substr($tmp_string, 0, $i);
           $return .= strrev ($tmp_string);
       }
       $i++;
   }
   return $return;
   return substr($string, 0, $start) . $rep . substr($string, - $end);
}

Bash 如何设置进程的nice值(优先级执行)

#new process
nice -n PRIORITYNUMBER PROCESSNAME

#existing process
renice PRIORITYNUMBER PID_PROCESS

JavaScript 随机数函数

function mran(ma,mi)
{return(Math.round(Math.random()*(ma-mi))+mi)}

JavaScript Cameron Adams的getBrowserWidth()

// getBrowserWidth() by Cameron Adams
// http://www.themaninblue.com/experiment/ResolutionLayout/
function getBrowserWidth ( ) {
    if ( window.innerWidth ) { return window.innerWidth; }
    else if ( document.documentElement && document.documentElement.clientWidth != 0 ) { return document.documentElement.clientWidth; }
    else if ( document.body ) { return document.body.clientWidth; }
    return 0;
}

JavaScript Paul Sowdon的setStyleSheet()

// setStyleSheet() by Paul Sowdon
// http://www.alistapart.com/articles/alternate/
function setStyleSheet ( title ) {
    var i, a, main;
    for ( i = 0; ( a = document.getElementsByTagName("link")[i] ); i++ ) {
        if ( a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") ) {
        a.disabled = true;
        if ( a.getAttribute("title") == title ) a.disaled = false;
        }
    }
}

Ruby 我的irbrc

#require 'rubygems'
#require 'wirble'
#Wirble.init
#Wirble.colorize

IRB.conf[:AUTO_INDENT] = true
IRB.conf[:USE_READLINE] = true
IRB.conf[:LOAD_MODULES] = []  unless IRB.conf.key?(:LOAD_MODULES)
unless IRB.conf[:LOAD_MODULES].include?('irb/completion')
  IRB.conf[:LOAD_MODULES] << 'irb/completion'
end

HISTFILE = "~/.irb_history"
MAXHISTSIZE = 100

begin
  if defined? Readline::HISTORY
    histfile = File::expand_path( HISTFILE )
    if File::exists?( histfile )
      lines = IO::readlines( histfile ).collect {|line| line.chomp}
      puts "Read %d saved history commands from %s." %
        [ lines.nitems, histfile ] if $DEBUG || $VERBOSE
      Readline::HISTORY.push( *lines )
    else
      puts "History file '%s' was empty or non-existant." %
        histfile if $DEBUG || $VERBOSE
    end

    Kernel::at_exit {
      lines = Readline::HISTORY.to_a.reverse.uniq.reverse
      lines = lines[ -MAXHISTSIZE, MAXHISTSIZE ] if lines.nitems > MAXHISTSIZE
      $stderr.puts "Saving %d history lines to %s." %
        [ lines.length, histfile ] if $VERBOSE || $DEBUG
      File::open( histfile, File::WRONLY|File::CREAT|File::TRUNC ) {|ofh|
	lines.each {|line| ofh.puts line }
      }
    }
  end
end

puts '.irbc completed'

Other trac-admin命令行initenv示例

sudo trac-admin /Library/WebServer/trac/BIO_001_002 initenv BIO_001_002 sqlite:db/trac.db /Users/ctldev/repository/BIO_001_002 /sw/share/trac/templates

Other 在Mac OS X上重新启动apache


sudo apachectl restart