`

code随记

    博客分类:
  • ruby
 
阅读更多

添加svn到Netbeans:
Netbeans => 工具=>  选项 => 其他 => 版本控制


uninitialized constant ActiveSupport::Dependencies::Mutex

解决:
sudo gem update --system 1.3.7





netbeans中字体很小解决办法:


cd /usr/local/netbeans-6.9.1/etc
sudo gedit  netbeans.conf

netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true"
=>
netbeans_default_options="-J-Xms32m -J-Xmx256m -J-XX:PermSize=32m -J-XX:MaxPermSize=160m -J-Xverify:none -J-Dapple.laf.useScreenMenuBar=true --fontsize 12 -J-Dawt.useSystemAAFontSettings=on"



gem list:


cgi_multipart_eof_fix (2.5.0)
chronic (0.2.3)
daemons (1.0.10)
fastthread (1.0.7)
ferret (0.11.6)
ffi (0.6.3)
gem_plugin (0.2.3)
hoe (2.6.1)
hpricot (0.8.2)
json_pure (1.4.3)
log4r (1.1.7)
mechanize (1.0.0)
mime-types (1.16)
mislav-will_paginate (2.3.11)
mongrel (1.1.5)
mongrel_cluster (1.0.5)
mysql (2.8.1)
nokogiri (1.4.3.1)
oauth (0.4.2)
rack (1.0.1)
rails (2.3.4)
rake (0.8.7)
rest-client (1.6.1)
rmagick (2.13.1)
rmmseg (0.1.6)
ruby-hmac (0.4.0)
ruby-oci8 (1.0.7)
ruby-ole (1.2.10.1)
rubyforge (2.0.4)
spreadsheet (0.6.4.1)
ultrasphinx (1.11)
uuidtools (2.1.1)
whenever (0.4.2)


svn相关:

svn help status
svn checkout svn://192.168.6.10/project/Source_code/trunk/src
svn delete --force config/database.old.yml  
svn revert app/views/api2/response_center.rxml  ,撤销修改
svn up  ,pull
svn st  
svn log|more
svn ci -m "msg" path  ,push
svn add file or dir


svn help st
svn add lib/tasks/pa/wz_city.rake
svn delete --force lib/tasks/pa/add_wz_city.rake
svn ci -m "m" lib/tasks/pa/
svn up


svn的配置文件
修改/root/.subversion目录下的config文件。
比如说修改svn所控制的文件类型,则可以修改config文件中的global-ignores参数,这个参数是指定了svn
版本控制忽略的文件类型,举例如下:
global-ignores = *.o *.lo *.la *.al .[0-9]* *.a *.pyc *.pyo

ignore environment.rb




表单提交:

document.forms['main'].submit();

document.getElementById('wz').submit();



soap:


If the vast majority of your consumers will be Rails developers then
 maybe using ActiveResource compliant REST services might be the way to
 go, but they will look pretty ugly to non-Rails consumers.

If you want any technology to be able to consume it, I would not use
ActiveResource, and would create XML (or JSON) that suits the data.

rails activeresource
rails webservices




SOA  webservice  CORBA  XML  (Web Services Definition Language,WSDL)

Web服务并不是实现 SOA 的惟一方式。前面刚讲的 CORBA 是另一种方式,这样就有了面向消息的中间
件(Message-Oriented Middleware)系统,比如 IBM 的 MQseries。但是为了建立体系结构模型,
您所需要的并不只是服务描述。您需要定义整个应用程序如何在服务之间执行其工作流。您尤其需要找到业务
的操作和业务中所使用的软件的操作之间的转换点。因此,SOA 应该能够将业务的商业流程与它们的技术流
程联系起来,并且映射这两者之间的关系。例如,给供应商付款的操作是商业流程,而更新您的零件数据库,
以包括进新供应的货物却是技术流程。因而,工作流还可以在 SOA 的设计中扮演重要的角色。
可复用以往的信息化软件。基于SOA的协同软件提供了应用集成功能,能够将ERP、CRM、HR等异构系统的数据集成。
soa vs web service
SOAP, WSDL, UDDI
SOA 不是Web服务
  在理解SOA和Web服务的关系上,经常发生混淆。根据2003年4月的Gartner报道,Yefim V. Natis就这个问题是这样解释的:“Web服务是技术规范,而SOA是设计原则。特别是Web服务中的WSDL,是一个SOA配套的接口定义标准:这是 Web服务和SOA的根本联系。”从本质上来说,SOA是一种架构模式,而Web服务是利用一组标准实现的服务。Web服务是实现SOA的方式之一。用 Web服务来实现SOA的好处是你可以实现一个中立平台,来获得服务,而且随着越来越多的软件商支持越来越多的Web服务规范,你会取得更好的通用性。





api authorization
digital signature
MD5(message-digest algorithm 5)

http://api.map.baidu.com/api?key=6f5ba7bc29711cc8e97cdc693bd0c896&v=1.0&services=false

s1=CGI::escape("豫".utf8_to_gbk)
=> "%D4%A5"
>> s2=CGI::escape("豫")
=> "%E8%B1%AB"

#Iconv.iconv("utf8","GB18030","")[0]
#$0 = irb|script/server|/home/simon/NetBeansProjects/haohaoApi/lib/wz/shanghai_wz.rb| /usr/bin/rake
$0:top level execution


__FILE__:current level execution
if __FILE__ == $0
end



Warning: The database defined as "test" will be erased and
re-generated from your development database when you run "rake".
Do not set this db to the same as development or production.

when test cases are run, it deletes the data before
and after the test.




源的选择:



bjtu_sources.list
选择合适的源,有时候可能对方服务器出问题,更新源也会出错
sudo apt-get update
E: 有一些索引文件不能下载,它们可能被忽略了,也可能转而使用了旧的索引文件。
rm /var/lib/apt/lists/*
cd /var/lib/apt/lists/
mkdir partial
后再 apt-get update 就没问题了。
参考: http://ubuntuforums.org/archive/index.php/t-427.html





如何获取ruby的安装路径:
require "rbconfig"
puts File.join(Config::CONFIG["bindir"], Config::CONFIG["ruby_install_name"])



crontab:


crontab log

Redhat (RHEL)/Fedora Core/Cent OS Linux.
# /etc/init.d/crond start|stop|restart|reload
# /etc/rc.d/init.d/crond start

Debian or Ubuntu Linux.
$ sudo /etc/init.d/cron start|stop|restart|reload
$ sudo service cron start


start the service at boot time so that job can run w/o problems.
Redhat (RHEL)/Fedora Core/Cent OS Linux:
# chkconfig crond on

Debian or Ubuntu Linux:
$ sudo rcconf
$ sudo update-rc.d cron defaults


man service
service --status-all
sudo service SCRIPT COMMAND [OPTIONS]
sudo service cron start

The  SCRIPT  parameter  specifies  a  System  V init script, located in
/etc/init.d/SCRIPT.  The supported values  of  COMMAND  depend  on  the
invoked  script,  service  passes  COMMAND  and  OPTIONS it to the init
script unmodified.  All scripts should support at least the  start  and
stop  commands.   As  a special case, if COMMAND is --full-restart, the
script is run twice, first with the stop command, then with  the  start
command.

/etc/init.d containing System V init scripts.




业务规则  +    业务流程  +   业务内容  =  系统



维护HTTP连接状态客户端有三种方式:

COOKIE, URL回写, HIDDEN字段,
服务器可以通过session id追踪缓存的用户数据.
COOKIE的效果最好, 但有可能被禁用, URL回写会让URL的长度和可读性很难过.
HIDDEN字段在TAPESTRY里用的最多,但需要往复的传输和生成页面.
服务器端的话,需要占用内存,方案取舍就要看自己的项目实际情况了.




obj.valid?(context = nil)
Runs all the specified validations and returns true if no errors were added otherwise false.
user.errors.on("username")



Tempfile类方法
"original_filename", "fileno", "size", "type"


nil.id, true.id , false.id






inline GETCOLORARROUND(CxImage& img, int a1, int a2, int& q, int x, int y, int xmin, int xmax, int ymin, int ymax) {
 int x1, y1;
 x1 = x + a1; y1 = y + a2;
 if (x1 >= xmin && x1 < xmax && y1 >= ymin && y1 < ymax)
 {
  RGBQUAD c = img.GetPixelColor(x1, y1);
  if (RGB2GRAY(c.rgbRed, c.rgbGreen, c.rgbBlue) != 255)
   q++;
 }
}


void C1(CxImage& img, int k)
{
 CxImage tmp(img, true, true, true);
 long xmin, ymin, xmax, ymax;
 xmin = ymin = 0;
 xmax = img.GetWidth(); ymax= img.GetHeight();
 RGBQUAD bk;
 bk.rgbBlue = 0xff;
 bk.rgbGreen = 0xff;
 bk.rgbRed = 0xff;
 bk.rgbReserved = 0xff;
 for(long y=ymin; y<ymax; y++){
  for(long x=xmin; x<xmax; x++){
    int q = 0;
    GETCOLORARROUND(img,1, 1, q, x, y, xmin, xmax, ymin, ymax);
    GETCOLORARROUND(img,1, -1, q, x, y, xmin, xmax, ymin, ymax);
    GETCOLORARROUND(img,1, 0, q, x, y, xmin, xmax, ymin, ymax);
    GETCOLORARROUND(img,0, 1, q, x, y, xmin, xmax, ymin, ymax);
    GETCOLORARROUND(img,0, -1, q, x, y, xmin, xmax, ymin, ymax);
    GETCOLORARROUND(img,-1, 1, q, x, y, xmin, xmax, ymin, ymax);
    GETCOLORARROUND(img,-1, -1, q, x, y, xmin, xmax, ymin, ymax);
    GETCOLORARROUND(img,-1, 0, q, x, y, xmin, xmax, ymin, ymax);
    if (q < k) {
     tmp.SetPixelColor(x,y,bk);
    }
  }
 }
 img.Transfer(tmp);
}

上面的C1函数就是去掉指定了k值的噪音点,但是如果用k=3调用或者k=4调用,效果都不理想
但是像这样子调用

void convert(CxImage& img)
{
 C1(img, 4);
 C1(img, 3);
 C1(img, 4);
 C1(img, 3);
}

一下子就去掉了原图周围的黑边框,杂点,和线。
对吧,实际算法太简单了,只要愿意去想,就能有意想不到的效果。



str
=> "<div id=\"fuck\">hello</div><div id=\"game\">hello</div><div id=\"ok\">hello</div><div id=\"fine\">hello</div><div id=\"fine\">world</div>"
>> str.scan(/<div\sid="fine.*?>.+?<\/div>/im)
=> ["<div id=\"fine\">hello</div>", "<div id=\"fine\">world</div>"]



sed -n '/undefined/p' log/production.log
改变文本内容:
sed -i 's/chinaafcs/chinaafc_baks/g' chinaafc_baks.sql
不改变文本内容:
sed -e 's/chinaafcs/chinaafc_baks/g' chinaafc_baks.sql



一款互联网工具的“动词化”,通常意味着它成为一个被引爆的流行—比如Digg、Google和Twitter。现在最时髦的口号变成了“Let’s Instagram the world”。

在iPhone上可以使用的图片拍摄与分享工具,已在全球100多个国家和地区散布着超过1200万的用户,先后融资700万美元,团队成立刚满一年,迄今只有6个人

“Instagram首先是一个照片拍摄和分享的工具,然后是一个社交网络。”

今年1月,Instagram就向第三方开发者开放了应用程序接口(API),允许他们围绕Instagram本身开发各种扩展应用:比如InstaRader是一款基于地理位置查看Instagram照片的工具,可以帮你找到方圆5英里内用Instagram分享的照片,并在地图上标记出来;InstARgam是一款增强现实应用(Augmented Reality),根据用户的地理位置自动从Instagram社区搜索出相关照片并推送出来。而InstaDesk可以把Instagram的体验迁移到Mac电脑的桌面上—即便你没有iPhone也能获得Instagram的体验。

我从Facebook上学到的是:一个平台可以在保护用户隐私,让用户感觉更安全和舒服的同时实现开放。

谷歌今年6月推出了Google+服务,但当时仅针对普通用户开放,而不允许商业用户擅自在Google+网站上创建页面。谷歌上周宣布,已面向全球所有企业用户开放Google+,从而使各类品牌、产品、企业及其他机构能够在Google+创建相应页面。


百度第二季度在中国搜索市场收入的份额为75.9%,但正面临另外两个可能很强大的挑战者:阿里巴巴集团旗下的电子商务搜索引擎一淘网(Etao.com)、以及新浪公司的微博(Weibo.com)。

HTML5实现地理定位。也就是获得本机IP地址,然后判断出所在位置,并且显示在Google地图上



ActionController::InvalidAuthenticityToken,    422
Exception,   500                        
RuntimeError, 500                      
ActiveRecord::RecordNotFound, 400      
ActionController::RoutingError, 400     
ActionController::UnknownController, 400
ActionController::UnknownAction, 400     


Ruby on Rails瞄准的则是另一个目标——中间级Web站点(Web sites in-between)。这些站点虽然难以大规模蔓延,每天还是有些访问量。但它们大量使用外部托管主机,如果Rails不能在这些站点上预先安装,就不会有多少戏唱。PHP不用伤这个脑筋,因为99%的网络提供商都支持它了。

数据安全:

昨天下午,记者在http://go.ipa100.com网站找到了“天涯4000万用户密码查询系统”。记者输入自己的天涯ID,立刻准确地跳出了用户名、密码和邮箱,随后拿部门同事的几个ID测试后发现,全部无误,有人惊呼赶紧改密码,也有人自我安慰“幸好银行卡密码不是这个”。
CSDN和天涯的数据库相继被黑客“攻陷”。此前网上就有消息称新浪微博、猫扑、17173、多玩网、人人网、嘟嘟牛、7k7k、178游戏网等多家网站的会员数据库均已被盗,但新浪微博和人人网都已出来辟谣。昨天,记者在登录自己的新浪微博时,第一时间收到了“你在新浪的账号密码与其他网站被盗账号密码一致,请立即更改密码”的温馨提示。



@topics = Topic.paginate :conditions=>conditions,
      :joins=>joins||"",
      :order=>"last_responsed_at desc",
      :page =>params[:page],:per_page =>20

@topics.total_entries

topic has many replies
topic.replies.paginate :include=>[:response_text],:page=>page,:per_page=>per_page,:order=>"created_at desc"



Topic.paginate :joins=>"left join taggings on topics.id=taggings.taggable_id and taggings.taggable_type='Topic'"


####car has_many pics########
@pics = Pic.paginate :conditions=>["cars.is_deleted = 0"],
:joins=>'left join cars on pics.car_id = cars.id',
:order=>"pics.id",
:page =>params[:page]||1,:per_page =>10



Promotion.count(:conditions=>["biz_base_id = ? and start_date < ? and thru_date > ? and is_deleted = 0" , 13 , Time.now.chinese_format , Time.now.chinese_format])

BizBaseSysPropTypeCount.first(:select=>"sys_prop_type_id,max(counts)")
BizBaseGoods.update_all("status=1",["biz_base_id=13"])

CarPageContentTypeMapping.delete_all(["car_wz_city_id = ?", wc.id])

User.all(:offset=>13, :limit=>2)从第13条记录开始,而不是从id=13的记录开始
User.all(:offset=>600009,:limit=>20).map &:username

数据库同步问题(保存后马上去find会出错)



def export_data
     redirect_to "/downloads/abcdef.csv"   
end



屏蔽退格键: document.onkeydown=function(){if(event.keyCode==8)return false;};

解除:document.onkeydown=null;

################################
    document.onkeydown=function(){if(event.keyCode==8)return false;};
 
    Event.observe(window, 'load', function() {
      if($('captcha')){
        Event.observe($('captcha'), 'blur', function() {
          document.onkeydown=function(){if(event.keyCode==8)return false;};
        });

        Event.observe($('captcha'), 'focus', function() {
          document.onkeydown=null;
        });

      }
    });
#################################################



    API参数规范:


    1. json格式的参数

    url = "http://chinaafc.miit.gov.cn/asopCmsSearch/searchIndex.jsp?"
    params = ""
    params += "params=#{CGI::escape("{\"goPage\":"+ curr_page +",\"orderBy\":[{\"orderBy\":\"pl\",\"reverse\":false}],\"pageSize\":"+ page_size + ",\"queryParam\":[{\"shortName\":\"allRecord\",\"value\":\"1\"}]}")}"
    params += "&callback=jsonp1324610198689&_=1324611151148"
    url + params


    2.xml格式的参数


     http://www.def.com/api.json?args=<il><i n='method_name' v='2.0'><uid>1</uid><city_id>1</city_id></i></il>


     3.经过对称加密的hash


     http://del.icio.us/api/peej/bookmarks/a211528fb5108cddaa4b0d3aeccdbdcf




h={:error=>0,:url=>"/images/abc.png"}
h.to_json        #"{\"error\":0,\"url\":\"/images/abc.png\"}"




=====================================

        hash = {

           "death"  => [4, ["death", 9] ],

           "pain"  => [5, ["pain", 7 ] ],

           "wonder"  => [1, ["wonder", 23]  ],

           "ignore"  => [2, ["ignore", 24]  ],

           "evil"  => [3, ["evil", 22]  ]

       }


      hash.sort { |a,b| a[1][0] <=> b[1][0] }.map {|e| e[0] }

=====================================


table_name.classify.constantize
Model.table_name




Search.search_goodses args

search=Ultrasphinx::Search.new({:class_names=>"BizBaseGoodsIndex",
 :query=>"\"苹果\"",              
 :page=>1,                        
 :filters=>                       
  {:status=>2,                    
   :distance=>0..6000000,         
   :is_show=>1},  
 :match_mode=>:boolean,           
 :per_page=>15,                   
 :location=>{"lat"=>31.2307, "long"=>121.473},
 :sort_mode=>"extended",                     
 :weights=>{"goods_name"=>9.0},              
 :sort_by=>"distance asc"} )

goods=search.run #正常
goods=search.run.results #出错,undefined method `total_pages' for #<Array:0xb6e47bd4>
<%= will_paginate goods, :class => 'page_num_box', :previous_label => "上一页", :next_label => "下一页" %>


nslookup 域名(不带http://)
nslookup sslk.bjjtgl.gov.cn
dig sslk.bjjtgl.gov.cn




IE和firefox

document.forms["form_name"];   // 根据name属性值
document.forms[0];        // 根据索引号
document.form_name;            // 直接根据name值获得对象


支持IE:
forms.action="/jgjww/wzcx/wzcx_yzm.jsp?flag=1";
forms.submit();

支持firefox:
document.forms.action="/jgjww/wzcx/wzcx_yzm.jsp?flag=1";
document.forms.submit();



新邮箱收件服务器地址是pop3.etouchgroup.com.cn
新邮箱发件服务器地址是smtp.etouchgroup.com.cn




ajax分页控件
日期选择

Start = [0x4E00].pack("U")
End = [0x9FA5].pack("U")
#将汉字的连续串筛选出来,返回数组
page.scan(/[\+ #{Start}-#{End}]+/)

arr.split(/\|\||\|/)

1.搜索自动完成 (Search Autocomplete)
2.快速进入标签(Go To Label)
3.添加附件提醒工具 (Forgotten Attachment Detector)
4.邮件中YouTube预览 (YouTube Previews)
5.自定义标签颜色 (Custom Label Colors)
6.假日时光 (Vacation Dates)

============================
windows:
我的电脑 => 属性 => 打开远程连接
设置administrator密码:123

ubuntu:
打开ubuntu 终端服务客户端,输入项:
计算机:188.188.1.102
协议:RDPv5
用户名:administrator
密码:123
客户端主机名:u904
=> 连接


js汉字的正则表达式:   /[\u4e00-\u9fa5]/
代码复制的时候 格式,中文符号 也会带过来,最好手动再敲一遍
alert(/^[\u4e00-\u9fa5]{1}[a-zA-Z0-9]{6}$/.test("沪A12345"))


<table>    <tbody></tbody>    <tbody></tbody>    <tbody></tbody> </table>

载入页面就加载并执行js有两种方式,1:window.onload,2:将代码直接写在script中
部分加载






################################

<%products.each do |product|%>
<a href="/supermarket/super_market/index?tab_id=2#<%=product.goods_id%>">  
<img src="<%=product.small_pic%>" alt="" />
</a>
<%end%>
#################################



###############################
<%products.each do |product|%>
<a name="<%=product.goods_id%>"></a>
<div><img src="<%=product.big_pic%>" alt="" /></div>
<%end%>


<script type="text/javascript">
  function set_bulletin_show(is_show){
    if(is_show){
      $('supermarket_bulletin').style.display = 'block'
    }else{
      $('supermarket_bulletin').style.display = 'none'
    }
  }
 
 var show = "<%=SystemConfig.supermarket_bulletin_is_show[1]%>";
 <%if params[:tab_id].to_i==2%>
   set_bulletin_show(show);
   setTab(2,1);
 <%end%>

</script>
##################################


###################################

/index.rhtml

<div id="topics">
  <img src="/images/ajax-loading.gif" />
</div>
<script type="text/javascript">
Event.observe(window, 'load', function() {
<%=remote_function(:url => {:action =>"topic_list" } )%>;
  });
 
document.observe("dom:loaded", function() {
  var container = $(document.body)
  if (container) {
    var img = new Image
    img.src = '/images/ajax-loading.gif'
    function createSpinner() {
      return new Element('img', {
        src: img.src,
        'class': 'spinner'
      })
    }
    container.observe('click', function(e) {
      var el = e.element()

      if (el.match('.pagination.ajax a')) {

<%#*el.up('.pagination.ajax').insert(createSpinner())%>
        ajax_load('seo-list');
        new Ajax.Request(el.href, {
          method: 'get'
        })
        e.stop()
      }
    })
  }
});
 
</script>



/topics/_topic_show.rhtml

<%topics.each do |t| %>
  <span><a href="<%=t.url%>"><%=t.url%></a></span>
<%end%>
<%= will_paginate  topics, :class => 'pagination ajax', :page_links => false, :previous_label => '< ', :next_label   => ' >',:params => {:action => "topic_list"}%>



rails_root/app/controllers/topics_controller.rb

class TopicsController < ApplicationController
  def topic_list
    @topics = Topic.paginate(:all, :page => args[:page]||1, :per_page => args[:per_page]||10, :order => "created_at",:conditions =>["deleted = 0"])
    render :update do |page|
      page.replace_html "topics", :partial=>'/topics/topic_show' ,:locals => { :topics => @topics }
    end
  end
end

===============================

def index
  @points = Tools.get_points(params[:MemberID])["points_left"] rescue 0
  render :text=>"<html><body><script type='text/javaScript' charset='utf-8'>parent.display_points('#{@points}');</script></body></html>" , :layout=>false
end

index:

<iframe name="point" id="point" src="http://domain1回调domain2/index"  style="display: none;">
</iframe>

<script type="text/javascript">
  function display_points(points){
    $("score").innerHTML = points;
  }
</script>

===============================

https://maps.googleapis.com/maps/api/place/search/json?
location=-33.8670522,151.1957362&radius=500&types=food&
name=harbour&sensor=false&key=YOUR_GOOGLE_API_KEY

这里后的 location ,我已经提供 lat 长值。
然后,我将有提供 radius 的500 meters.
我在寻找 Food 类别。您可能需要的任何其他业务类别。名称搜索是 harbour 。供应键 YOUR_GOOGLE_API_KEY 。
 


以下是一个请求示例,展示了在以澳大利亚悉尼的一点为中心,半径 500
米的范围内搜索名称中包含“harbour”一词且类型为“food”的“地方”。

https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=food&
name=harbour&sensor=false&key=AIzaSyAiFpFd85eMtfbvmVNEYuNds5TEF9FjIPI


提取证书的认证指纹 (MD5)
./keytool -list -keystore /home/pingan/debug.jks



===================================

 

 

js加密 => ruby解密


java加密 => ruby解密


Session hijack

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics