2011/12/22

Apache2 Server 的啟用/重啟


Apache 常用小知識

Apache 的主要設定檔是 httpd.conf ,其他的設定檔都是被 Include 進來的;
Apache 的首頁目錄以 DocumentRoot 決定,首頁檔案則以 DirectoryIndex 決定;
Apache 可以透過虛擬主機的設定以指定不同主機名稱到不同的 DocumentRoot 下;
Apache 是多執行緒的軟體,可以啟動多個程序來負責 WWW。主要的模組有 prefork 及 worker, 最大可連線的數量以 MaxClients 來決定。
若要正確的讓瀏覽器顯示網頁的編碼格式,最好在網頁上宣告語系,並將 Apache 的設定檔 httpd.conf 內的 AddDefaultCharset 設定值取消;
在 Apache 可瀏覽的目錄權限設定上 (Options 參數),最好將 Indexes拿掉;
透過 AllowOverride 與 .htaccess 可讓使用者在自己管理的目錄下制訂自己的風格;
Apache 本身提供一個 apachectl (RedHat/CentOS) / rcapache (SUSE等) 的 script 讓使用者得以快速管理其 apache 的服務;
HTTP 使用的是明碼傳送,目前 WWW 可利用 SSL 等機制來進行資料加密的傳輸。資料如果比較重要時,務必以 SSL 或者是保護目錄來保護。




Apache2 Server 的啟用/重啟

對於不同的 Linux Distributions,Apache 啟用的方式略有不同,主要有三種(apachectl, httpd, apache2):


1.
Shell>> /usr/local/apache2/bin/apachectl -k start (Red Hat)
2.
Shell>> /usr/local/apache2/bin/httpd -k start (when you don't have apachectl in Red Hat)



3.

Shell>> /etc/init.d/apache2 start (Ubuntu, Debian, SUSE)

apachetcl和httpd的路徑可能因安裝方式而有不同,請注意。但在某些情況下不用輸入路徑。
http://mepopedia.com/?page=146

2011/12/21

取得jQueryUI Tabs的當前tab panel

節選並翻譯自http://stackoverflow.com/questions/300078/jquery-ui-tabs-get-currently-selected-tab-index 雖然該帖子已經有些時日,不過我沒有發現有人提及這個方案: 如果不在Tab的事件(tab events ,http://jqueryui.com/demos/tabs/#events )中,如何取得當前tab ( "selected tab" )--當前選中的tab的下面的顯示內容的panel。我有一個簡單的方式... 


  1. var curTab = $( '.ui-tabs-panel:not(.ui-tabs-hide)' );  

你可以很容易的得到索引號index, 完全正確, 下面是其文檔中提及的方式 


  1. var $tabs = $( '#example' ).tabs();  
  2. var selected = $tabs.tabs( 'option' ,  'selected' );  // => 0  


不過你可以用我說的方式來獲取索引號index 或者其他任何當前panel的屬性.. 

  1. var curTab = $( '.ui-tabs-panel:not(.ui-tabs-hide)' ),  
  2.     curTabIndex = curTab.index(),  
  3.     curTabID = curTab.prop( "id" ),  
  4.     curTabCls = curTab.attr( "class" );  

2011/12/20

被遺忘的 toFixed()

javascript 的 toFixed(n) 可以將數字round up 到小數點後n 個位

var num = 0;

num = new Number(21);
num.toFixed(1) --> 21.0

num = new Number(21.3456);
num.toFixed(0) --> 21
num.toFixed(2) --> 21.35
num.toFixed(4) --> 21.3456

2011/12/14

java replaceAll with $

as $ is one of the symbol used in regular expression
it will fail at replpace all


solution

replace all $ to \\$
String a = "$38 Apple";
a = a.replaceAll("\\$", "\\\\\\$");

replace
String b = "testing testing REPLACE_ME testing testing";
String finalStr= start.replaceAll("REPLACE_ME", a);

2011/12/09

Ebay API SDK Add Item

從今天起,進入api開發的code階段。 這個階段預計有三部分,上傳產品,更新產品,刪除產品。每個部分都以固定價格的產品為例,其他如訂單管理,可變價格產品的管理等,需要讀者自己延伸。 因為每個人編碼習慣不同,所以編寫code的方式也不盡相同,但是為了便於大家更好的理解,這裡的例子都會盡量簡單一些。 對於不同種類的產品,參數可能會大致不相同,但基本的設置無外乎就這些。對於Variation的產品,比如一雙鞋,有43,42,44等尺寸這些產品,一定要仔細參照上邊的code是如何設置的,即便如此,也不能保證一次上傳就能成功,最好就是把返回信息$res保存起來,針對不同error,逐個解決。



class uploadProductToEbay {

 protected $_session = null;
 protected $_cs = null;
 protected $_logger = null;
 protected $_basedir = '';

    public function __construct()
    {
         require_once 'ebay/EbatNs_1_0_679/EbatNs_ServiceProxy.php';
  require_once 'ebay/EbatNs_1_0_679/EbatNs_Logger.php';
  require_once 'ebay/EbatNs_1_0_679/AddFixedPriceItemRequestType.php';
  require_once 'ebay/EbatNs_1_0_679/AddFixedPriceItemResponseType.php';

 
  $this->_basedir = Mage::getBaseDir();
  $this->_session = new EbatNs_Session(Mage::getBaseDir().'yourpath/ebay.config.php');
  $this->_cs      = new EbatNs_ServiceProxy($this->_session);
  $this->_logger  = new EbatNs_Logger();
    }
    public function addEbayProduct($product_data){//$product_data是从db里取得数据,比如产品title,只需在db里更改就可以了

                $req = new AddFixedPriceItemRequestType();
  $item = new ItemType();

  $item->SKU = $product_data['customlabel'];// 产品编号
  $item->Country = 'US';//国家
  $item->AutoPay = true;//paypal支付的话,如果你不想有损失,就老老实实设为true
  $item->Description = trim($product_data['*description']);//描述,不能有ebay规定的敏感字符
  $item->ListingDuration = $product_data['*duration'];
  $item->Title = $product_data['title'];//需少于80字符,不能有ebay规定的敏感字符
  $item->Currency = 'USD';//币种
  $item->ListingType = 'FixedPriceItem';//固定价格产品
  $item->SubTitle = $product_data['subtitle'];
  $item->StartPrice = $product_data['*startprice'];
  $item->ConditionID = $product_data['conditionid'];
  $item->Quantity = round($product_data['*quantity']) ;
  $item->Location = $product_data['*location'];//卖家邮编
 
  $item->DispatchTimeMax = $product_data['*dipatch_time_max'];//最大耗费时间
  $item->PaymentMethods = 'PayPal';//支付方式
  $item->PayPalEmailAddress = $product_data['paypal_email_address'];//paypal账号
 
  $pdts  = new PictureDetailsType();//产品图片部分
  $pdts->GalleryType = $product_data['gallery_type'];
  if(preg_match('/https/',$product_data['picurl']))
   $product_data['picurl'] = str_replace('https','http',$product_data['picurl']);
  $pdts->PictureURL = $product_data['picurl'];
  $item->PictureDetails = $pdts;
 
  $item->PrimaryCategory = new CategoryType();
  $item->PrimaryCategory->CategoryID = $product_data['category'];//分类id
  $item->Site = 'US';
 
  $sdt  = new ShippingDetailsType();
  $ssot = new ShippingServiceOptionsType();
  $issot = new InternationalShippingServiceOptionsType();
  $stt  = new SalesTaxType();
 
  $sdt->ShippingType = 'Flat';
  $sdt->PromotionalShippingDiscount = $product_data['promotional_shipping_discount'];
  $sdt->InternationalPromotionalShippingDiscount = $product_data['intl_promotional_shipping_discount'];
  $sdt->ShippingDiscountProfileID = $product_data['shipping_discount_profile_id'];
  $sdt->InternationalShippingDiscountProfileID = $product_data['intl_shipping_discount_profile_id'];
  $stt->SalesTaxState = $product_data['SalesTaxState'];
  $stt->SalesTaxPercent = $product_data['SalesTaxPercent'];
  $sdt->SalesTax = $stt;
 
  //第一种shipping设置
  $ssot->ShippingServicePriority = round($product_data['shipping1_priority']);
  $ssot->ShippingService = $product_data['shipping1_option'];
  $ssot->ShippingServiceCost = $product_data['shipping1_cost'];
  $sdt->ShippingServiceOptions[] = $ssot ;
 
  //第二种shipping设置,还可以有更多种
  $ssot2 = new ShippingServiceOptionsType();
  $ssot2->ShippingServicePriority = round($product_data['shipping2_priority']);
  $ssot2->ShippingService = $product_data['shipping2_option'];
  $ssot2->ShippingServiceCost = $product_data['shipping2_cost'];
  $sdt->ShippingServiceOptions[] = $ssot2 ;

  //第一种国际的shipping设置,主要针对美国以外的国家
  $issot->ShippingServicePriority = round($product_data['intlshipping1_priority']);
  $issot->ShippingService = $product_data['intlshipping1_option'];
  $issot->ShippingServiceCost = $product_data['intlshipping1_cost'];
  $issot->ShippingServiceAdditionalCost = $product_data['intlshipping1_addition'];
  $issot->ShipToLocation = $product_data['intlshipping1_location'];
  $sdt->InternationalShippingServiceOption[] = $issot ;
 
  //第二种国际的shipping设置,还可以有更多种
  $issot2 = new InternationalShippingServiceOptionsType();
  $issot2->ShippingServicePriority = round($product_data['intlshipping2_priority']);
  $issot2->ShippingService = $product_data['intlshipping2_option'];
  $issot2->ShippingServiceCost = $product_data['intlshipping2_cost'];
  $issot2->ShippingServiceAdditionalCost = $product_data['intlshipping2_addition'];
  $issot2->ShipToLocation = $product_data['intlshipping2_location'];
  $sdt->InternationalShippingServiceOption[] = $issot2 ;
 
  $item->ShippingDetails = $sdt;
 
  //退换货设置
  $rpt  = new ReturnPolicyType();
  $rpt->ReturnsAcceptedOption = $product_data['*return_accepted_option'];//如ReturnsAccepted 表示接受退换货
  $rpt->RefundOption = $product_data['refund_option'];//如MoneyBack 以现金方式返还
  $rpt->ReturnsWithinOption = $product_data['returns_with_option'];//如Days_30 30天内有效
  $rpt->Description = $product_data['additional_details'];//一些备注
  $rpt->ShippingCostPaidByOption = $product_data['shipping_cost_paid_by'];//如Buyer 购买者承担退货运费
  $item->ReturnPolicy = $rpt;
 
  $lcrpt = new ListingCheckoutRedirectPreferenceType();
  $lcrpt->SellerThirdPartyUsername = $product_data['seller_third_party_username'];
  $item->ListingCheckoutRedirectPreference = $lcrpt;
 
  $item->ShipToLocations = $product_data['ShipToLocations'];//如Worldwide,可送往世界各国
 

  //一些产品属性,如适合对象:男士,质地:棉  等等
  $nvlat_si = new NameValueListArrayType();
  $specific = unserialize($product_data['specific']);
  foreach ($specific as $k=>$v){
   $nvlt_si  = new NameValueListType();
   $nvlt_si->Name = $k;
   $nvlt_si->setValue($v);
   $nvlat_si->NameValueList[] = $nvlt_si;
  }
  $item->ItemSpecifics = $nvlat_si;
 
  /* *
  *
  *处理关联产品
  *
  */
  if($product_data['relationship'] == "Variation"){
 
   $vt    = new VariationsType();
   //$v     = new VariationType();
   $nvlat = new NameValueListArrayType();
   $nvlt  = new NameValueListType();
 
   $nvlt->Name = $product_data['Specification'];//如 Bracelet Length

   //$size_array如array('6.25 inches','6.50 inches','6.75 inches')
   $size_array = explode(';',$product_data['relationship_detail']);
   $i=1;
   foreach ($size_array as $size){
    $nvlt->setValue($size,$i++);
   }
   $nvlat->NameValueList = $nvlt;
   $vt->VariationSpecificsSet = $nvlat;
 
   //不同尺码的产品信息
   $relation = unserialize($product_data['relation']);
   foreach ($relation as $pd){
    $v     = new VariationType();
    $nvlat = new NameValueListArrayType();
    $nvlt  = new NameValueListType();
   
    $v->SKU = $pd['sku'];//产品编号
    $v->Quantity = $pd['qty'];//库存
    $v->StartPrice = $pd['price'];
    $nvlt->Name = $product_data['Specification'];
    $nvlt->setValue($pd['size']);//产品尺寸,颜色等属性
    $nvlat->setNameValueList($nvlt);
    $v->VariationSpecifics = $nvlat;
    $vt->Variation[] = $v;

   }
  }

  $item->Variations = $vt;
  $req->Item = $item;
  $res = $this->_cs->AddFixedPriceItem($req);//$res为返回信息,成功,失败,失败原因等


  return $res->ItemID;
    }
}

轉自http://blog.csdn.net/shangxiaoxue/article/details/6949037