NSArray / NSMutableArray ã®ã¡ã¢ãªç®¡ç
é åã®ã¡ã¢ãªã¯ã¡ããã¨ç®¡çããã¦ããç¥ãããã£ããã§ç¢ºèªãã¦ããµã³ãã«ä½ã£ã¦ç¢ºããã¦ã¿ã¾ãã.
åãã£ããã¨ã¯ä»¥ä¸ã®ã«ã¼ã«ã§ã.
- åæå : initXXXXã®ã¡ã½ããã§æå®ããããªãã¸ã§ã¯ãã¯å ¨ã¦retainããã. arrayXXXã¯autorelease.
- 追å : 追å ããããªãã¸ã§ã¯ããretainããã.
- åé¤ : 追å ããããªãã¸ã§ã¯ããreleaseããã.
- é åèªä½ãdealloc : å å ãã¦ãããªãã¸ã§ã¯ãå ¨ã¦ãreleaseããã.
æ¤è¨¼ã³ã¼ã
NSObject *objA = [[NSObject alloc] init]; NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:objA, nil]; NSLog(@"after init array; array retainCount:%d expect 1", [array retainCount]); NSLog(@"after init array; objA retainCount:%d expect 2", [objA retainCount]); NSObject *objB = [[NSObject alloc] init]; NSLog(@"after init objB; objB retainCount:%d expect 1", [objB retainCount]); [array addObject:objB]; NSLog(@"after add objB; objB retainCount:%d expect 2", [objB retainCount]); [array removeObject:objB]; NSLog(@"after remove objB; objB retainCount:%d expect 1", [objB retainCount]); NSObject *objC = [[NSObject alloc] init]; [array addObject:objC]; NSLog(@"after add objC; objC retainCount:%d expect 2", [objC retainCount]); [array release]; NSLog(@"after release array; objA retainCount:%d expect 1", [objA retainCount]); NSLog(@"after release array; objC retainCount:%d expect 1", [objC retainCount]); NSObject *objD = [[NSObject alloc] init]; NSArray *array2 = [[NSArray alloc] initWithObjects:objD, nil]; NSLog(@"after init array2; objD retainCount:%d expect 2", [objD retainCount]); [array2 release]; NSLog(@"after release array2; objD retainCount:%d expect 1", [objD retainCount]);
çµæ
after init array; array retainCount:1 expect 1 after init array; objA retainCount:2 expect 2 after init objB; objB retainCount:1 expect 1 after add objB; objB retainCount:2 expect 2 after remove objB; objB retainCount:1 expect 1 after add objC; objC retainCount:2 expect 2 after release array; objA retainCount:1 expect 1 after release array; objC retainCount:1 expect 1 after init array2; objD retainCount:2 expect 2 after release array2; objD retainCount:1 expect 1
çµæãäºæ³éãã®åãã§ãã.
Safariã®ä½ç½®ã«é¢ããããããã£ã¾ã¨ã
æè¿ãSafariä¸ã§Javascriptãçµããã¨ãå¤ãæã£ã¦ããã®ã§ã³ã¬ãæ©ã«ææ¡ãããã¦ããªãä½ç½®é¢é£ã®ããããã£ãã¾ã¨ãã¦ã¿ããã¨ã«ãã¾ãã.
ã¯ããã«
- åä½ã¯å ¨ã¦pxã§çµ±ä¸
- éåã®ããããã£ã¯DOM(æ¨æºã§ã¯ãªã)é¢é£ã®ããããã£
- ç·åã®ããããã£ã¯CSSé¢é£ã®ããããã£
CSSé¢é£ã®ããããã£ã«ã¯åä½ãå«ã¾ãã¾ããpxã§çµ±ä¸ãã¦ããã®ã§è¡¨è¨ä¸çç¥ãã¦ãã¾ã.
DOMé¢é£ã®ããããã£ã¯document.getElementById('id')çã§åå¾ãããªãã¸ã§ã¯ãã®ããããã£ã§ã.
CSSé¢é£ã®å¤ã®åå¾ã¯document.defaultView.getComputedStyle(elem,null)ã§åå¾ãããªãã¸ã§ã¯ãã®ããããã£ã使ãã¨å®éã«è¡¨ç¤ºããã¦ããå¤ãåå¾ã§ãã¾ã.ããããã£åã«ã¯ãã£ã¡ã«ã±ã¼ã¹(LCC)ã§åç §ã§ãã¾ã.
border,margin,paddingé¢é£
ä¾ãã°divè¦ç´ ã ã¨ãã¦ä»¥ä¸ã®ããã«è¦ããã¨ã·ã³ãã«ï¼
- borderãå«ããé·ããoffsetXxxã§åå¾(Width/Height)
- borderãå«ããªãé·ããclientXxxåã¯scrollXxxã§åå¾(Width/Height)
- ä¸ä¸å·¦å³ã®borderã¯clientXxxã§åå¾(Top/Right/Bottom/Left)
ã¹ã¯ãã¼ã«æã®å¤
ç´ä¸ã®åè¦ç´ ã«ãã£ã¦ãæåãéãã¾ã.
ã©ããã¦+4ã¨ã0ã¨ãã«ãªã£ã¦ããã®ãããã¥ã¡ã³ããè¦ã¤ããã¾ããã§ããããäºå®è¨ç®æ¹æ³ãéãããã§ã.試ããã®ã¯imgã¨divã ãã§ãããä»ã«ãåæ§ã®äºè±¡ãããã¨ãããã¾ã.
ã¹ã¯ãã¼ã«ãã¼ãç¡ãå ´åã¯scrollWidth/scrollHeightã¯ãããããclientWidth/clientHeightã¨åãããªãã¾ã.
è¦ç´ ã®ä½ç½®
ãã®ä¾ã ã¨divè¦ç´ ã®ï¼ã¤éãã¦ãã¾ã.
ä¾ã®offsetTopã®ç®åºæ¹æ³ã¯ä»¥ä¸ã®ããã«ãªãã¾ãã
offsetTop = å¤å´è¦ç´ (pading-top) + ä¸éè¦ç´ (margin-top + border-top + padding-top) + å å´è¦ç´ (margin-top)
25 = 5 + 5 + 5 + 5 + 5
è¦ç´ ã®borderã®å¤å´ããpositionãstatic以å¤ã®è¦ªè¦ç´ ã®borderã®å
å´ã¨ã®ç¸å¯¾è·é¢ãoffsetTop/offsetLeftã§åå¾ã§ãã¾ã.
åºæºã¨ãªã親è¦ç´ ã¯offsetParentã§åå¾ã§ãã¾ã.
å ã«htmlè¦ç´ ã¨ãbodyè¦ç´ ã¯position:staticã§ã.
Sinatra 㧠content_for ã使ã.
æè¿ãSinatraã使ãåºãã¾ãã. åãæ軽ã§ã.
ã·ã³ãã«ã ããã£ã¦Railsã«ããæ©è½ã欲ããã¨ããè¯ãããã¾ã.
Railsã®content_for
ç¥ããªã人ã¯ã°ã°ã£ã¦ãã ãã. ã§ãã¾ã¼ãæ¦è¦ãããã¯èª¬æãã¾ã.
RailsãSinatraããã³ãã¬ã¼ããå¤æ ã¨å æ ã§åãããã¨ãã§ãã¾ã. ã§ãå æ ããå¤æ ã«å¤ã渡ãããã¨ããããã¾ãããããªã¨ãã«å½¹ç«ã¤ã®ãcontent_forã§ã.
(ä¾)ã¿ã¤ãã«ãå¤ãã¦ã¿ã
å¤æ ã®ãã³ãã¬ã¼ããlayout.rbã
<html> <head><title><%= yield :title %></title></head> <body> <%= yield %> </body> </html>
å
æ ã®ãã³ãã¬ã¼ããindex.rbã
<% content_for :title, 'ãã»ã»ã»' %> ãã«ãã¯ã®ã¹ããã«ã¼è²·ã£ããã©å¼µãå ´æããªã.
å®è¡çµæ
<html> <head><title>ãã»ã»ã»</title></head> <body> ãã«ãã¯ã®ã¹ããã«ã¼è²·ã£ããã©å¼µãå ´æããªã. </body> </html>
ãããªæãã®æ©è½ã§ã.
Sinatra ã§ã®å®ç¾æ¹æ³
ã§ã¯æ¬é¡ãSinatraã§ã¯content_forãããã¾ãã.
æ軽ãªæ¹æ³ã¨ãã¦ã¯sinatraã®ãã©ã°ã¤ã³sinatra-content-forãããã¾ã.
ã§ãä»åã¯ãã©ã°ã¤ã³ã使ããã«ãã£ã¦ã¿ã¾ãã.
以ä¸ã®ã³ã¼ããapp.rbã¨ãsinatraã®å®è£ ãã¡ã¤ã«ããåç §ãããªããè²¼ä»ãã¦ãã ãã. ããã ãã§content_forã使ãã¾ã.
module Sinatra module Helpers def content_for(name, content=nil, &block) @content_for_param ||= {} content ||= block if content.nil? if @content_for_param.include?(name) @content_for_param[name].join else nil end else content = content.call if content.is_a? Proc content = content.dup if content.is_a? String @content_for_param[name] ||= [] @content_for_param[name] << content nil end end end module Templates def render_with_content_for(engine, data, options={}, locals={}, &block) if block_given? interrupt_block = Proc.new { |name| if name.nil? block.call else content_for name end } render_without_content_for engine, data, options, locals, &interrupt_block else render_without_content_for engine, data, options, locals end end alias_method :render_without_content_for, :render alias_method :render, :render_with_content_for end end
ã£ã§ä½¿ãæ¹ã§ããRailsã®content_forã¨å ¨ãåãã£ã¦ããã§ã¯ãªãã§ã. blockã使ã£ã表è¨ãerbã®ããªã³ã³ãã¤ã«ãæå¾ éãã«æã£ã¦ãªãã£ãã®ã§ã¡ãã£ã¨å·¥å¤«ããå¿ è¦ãããã¾ã.
æ¬æ¥ãªã以ä¸ã®ããã«æ¸ããã¨æã£ãã®ã§ãã
<% content_for(:title) do %> FooBar <% end %>
ããªã³ã³ãã¤ã«ãè¦ã¦ã¿ãã¨ä»¥ä¸ã®ãããªæãã§å æ ã®æååã¨ãã¦è¿½å ããã¡ãã£ã¦ã¾ãorz
content_for(:title) do ; @_out_buf.concat "FooBar"; end;
ããã§å·¥å¤«ãã¦ãããã¨.以ä¸ã®æ¸ãæ¹ã§åé¿ã§ãã¾ãã.
<% content_for(:title){ "FooBar" } %>
ã¡ãªã¿ã«ä»¥ä¸ã®ããã«ãæ¸ãã¾ã.
<% content_for(:title, "FooBar") %>
ããã«åãååã§æ°åã³ã¼ã«ããã¨çµåãããããã«ãã¾ããã
<% content_for(:title, "FooBar") %> <% content_for(:title, "Boo") %> => FooBarBoo
[Life] IMO for iPhone ã¾ã¨ã Wiki ã®æ¤ç´¢èªåãªã³ã¯bookmarklet
iPhoneä¸ã§ç¢ºèªããã¨ããã¡ã³ãã¯ãµã¤ã®ã§bookmarkletåãã¦ã¿ã¾ãã.
githubã«ä¸ããã®ã§ãèªç±ã«ã©ãã.
bookmarkletç»é²æ¹æ³
- http://gist.github.com/472351 ãéã
- auto_search_link.bookmarklet.jsã®rawãã¯ãªãã¯ãã¦ãã¡ã¤ã«ã表示ãã¾ã.
- å ¨é¸æãã¦ã½ã¼ã¹ãã³ãã¼
- ããã¯ãã¼ã¯ãã. ååã¯ãAutoSearchLinkãã¨ãã«ãã.
- ã¨ãããããä¿åããã¿ã³ã§å®äºãã.
- ããã¯ãã¼ã¯ãããç·¨éããã¿ã³ãæ¼ã
- å ã»ã©ä¿åãããAutoSearchLinkããç·¨éãã.
- URLãå ¥ããå ´æã«ã³ãã¼ããã½ã¼ã¹ãè²¼ä»ãã¦å®äºãã.
使ãæ¹
IMO for iPhoneまとめ Wiki* ã®é©å½ãªãã¼ã¸ã§ããã¯ãã¼ã¯ã®ãAutoSearchLinkããéãã¨èªåçã«æ¤ç´¢ãªã³ã¯ãå¼µããã¾ã.
ãªã³ã¯ãéªéãªå ´åã¯ããªãã¼ãããã°ç¡ãæãã¾ã.
ã³ãã³ãã©ã¤ã³ã§HTTPã¬ã¹ãã³ã¹ã確èªãã
HTTPã®ã¬ã¹ãã³ã¹ãããæ å ±ãæå¾ éãã確èªããéã«ä½¿ã£ãã®ã§ã¡ã¢
wgetã®å ´å
wget --server-response --spider [URL] ã¾ã㯠wget -S --spider [URL]
å®è¡ããã¨ããã¡ã¤ã«ããã¦ã³ãã¼ãããã«ã¬ã¹ãã³ã¹æ å ±ã表示ããã¾ã.
$ wget --server-response --spider http://127.0.0.1:4567/offline/cache.manifest ã¹ãã¤ãã¼ã¢ã¼ããæå¹ã§ãããªã¢ã¼ããã¡ã¤ã«ãåå¨ãã¦ãã確èªãã¾ãã --2010-07-07 17:57:28-- http://127.0.0.1:4567/offline/cache.manifest 127.0.0.1:4567 ã«æ¥ç¶ãã¦ãã¾ã... æ¥ç¶ãã¾ããã HTTP ã«ããæ¥ç¶è¦æ±ãéä¿¡ãã¾ãããå¿çãå¾ ã£ã¦ãã¾ã... HTTP/1.1 200 OK Last-Modified: Wed, 07 Jul 2010 08:43:02 GMT Connection: Keep-Alive Content-Type: text/cache-manifest Date: Wed, 07 Jul 2010 08:57:28 GMT Server: WEBrick/1.3.1 (Ruby/1.8.7/2010-01-10) Content-Length: 61 é·ã: 61 [text/cache-manifest] ãªã¢ã¼ããã¡ã¤ã«ãåå¨ãã¾ãã
curlã®å ´å
curl --verbose [URL] ã¾ã㯠curl -v [URL]
å®è¡ããã¨ã以ä¸ã®æ
å ±ãç»é¢ã«ã§ã¾ã.
wgetããåããããããã!
$ curl --verbose http://127.0.0.1:4567/offline/cache.manifest * About to connect() to 127.0.0.1 port 4567 (#0) * Trying 127.0.0.1... connected * Connected to 127.0.0.1 (127.0.0.1) port 4567 (#0) > GET /offline/cache.manifest HTTP/1.1 > User-Agent: curl/7.20.0 (i386-apple-darwin10.3.0) libcurl/7.20.0 OpenSSL/0.9.8n zlib/1.2.5 libidn/1.18 > Host: 127.0.0.1:4567 > Accept: */* > < HTTP/1.1 200 OK < Last-Modified: Wed, 07 Jul 2010 08:43:02 GMT < Connection: Keep-Alive < Content-Type: text/cache-manifest < Date: Wed, 07 Jul 2010 09:00:14 GMT < Server: WEBrick/1.3.1 (Ruby/1.8.7/2010-01-10) < Content-Length: 61 < CACHE MANIFEST stylesheets/msafari.css offline/editor.html * Connection #0 to host 127.0.0.1 left intact * Closing connection #0
[Javascript]jQueryã§äºåº¦æ¼ãé²æ¢å¯¾çã®ãã©ã°ã¤ã³
ãããªã«é£ãããªãã®ã§èªåã§æ¸ãã¦ã¿ã.
Gistã«å
¬éãã¦ããã®ã§ãèªç±ã«ã©ãã.
jquery.singleclick.js · GitHub
(function($) { var lockKey = 'clickLockedId'; $.fn.releaseClickLocked = function(){ var tid = this.data(lockKey); if(tid!==undefined){ clearTimeout(tid); } $(this).removeData(lockKey); }; $.fn.singleClick = function(handler, timeout) { timeout = timeout===undefined ? 3000:timeout; $(this).click(function(evt){ var self = $(this); if(self.data(lockKey)!==undefined){ return false; } var tid = setTimeout(function(){ self.releaseClickLocked(); },timeout); self.data(lockKey, tid); return handler.apply(this,[evt]); }); }; })(jQuery);
使ãæ¹
以ä¸ã¯ãªã³ã¯ãã¯ãªãã¯ãã¾ãã£ãæã®æåãã³ã¡ã³ãã§èª¬æãã¦ãã¾ã.
// 3ç§éã«ï¼åº¦ã ãã³ã¼ã«ããã¾ã. $('a.sample1').singleClick(function(evt){ alert('foo'); }); // 1ç§éã«ï¼åº¦ã ãã³ã¼ã«ããã¾ã. $('a.sample2').singleClick(function(evt){ alert('foo'); }, 1000); // releaseClickLockedã¯ã¿ã¤ã ã¢ã¦ããå¾ ããã«ããã¯ã解é¤ãã¾ã. $('a.sample3').singleClick(function(evt){ var self = $(this); setTimeout(function(){ self.releaseClickLocked(); },1000); });
[Ruby] Railsã®ã¨ã©ã¼ç®¡çãã¼ã«ã®Hoptoadã使ã£ã¦ã¿ã
Railsã®ã¨ã©ã¼ç®¡çãã©ã¯ã«åºæ¥ããããã®ã§è©¦ãã«è¨å®ãã¦ã¿ã¾ãã.
ãã®æã®ãã¼ã«ã¯è¦ã¦ã¦æ¥½ããã®ã§. è¦ã«ãªããããã¨ã©ã¼å¯¾å¿ãæ°åè¯ãåºæ¥ãã.
å°å ¥æ¹æ³ãããã£ããã¨çãã¾ã¨ãã¦ã¿ã¾ãã.
Hoptoadã¨ã¯
Hoptoadã®ä»çµã¿ã¯ãRailsã®ä¾å¤çããã£ãããããHoptoadã®ãµã¤ãã«éç¥ãã¦è¦ããããã¦ããã.
ãã©ã°ã¤ã³ã¨ãã¦ç¨æããã¦ããã®ã§å°å ¥ã¯çµæ§ç°¡å.
ã¢ã«ã¦ã³ãç»é²
試ãã¦ã¿ãã ããªã®ã§è¿·ããã¿ãã§ä½¿ãããã©ã³ã§ï¼ã¨è¦ã¦ã¿ãã¨
ãTry Hoptoad FREE for 30 daysãï¼ã試ã30æ¥ç¡æ!ï¼
ãªãã¦åºã¦ã¦ç¡æãã©ã³ãç¡ãã®ãï¼ã¨åéããã¾ãã.
ãã¼ã¼ãè¦ãã¨ä¸ã®æ¹ã«
ãEgg Plan for Freeã(ã¨ãã°ãã©ã³ã¯ç¡æã§ãã)
ã¨å°ããç®ç«ããã«æ¸ãã¦ããã
ãã¨ã¯é©å½ã«å ¥åé ç®ãåãã¦ãã£ã¦ãCreate Accountã
ããã¸ã§ã¯ãç»é²ã¨Railsã®è¨å®
ãã°ã¤ã³ãã¦ããã¸ã§ã¯ãã追å ããã¨ãRailsã¸ã®ã»ããã¢ããæ¹æ³ããããã¦ãã¾ã.
1. Remove your existing Exception Notifier from your ApplicationController(ExceptionNotifiableã使ã£ã¦ãå ´åã¯æ¶ãã¦ã):
class ApplicationController < ActionController::Base <del>include ExceptionNotifiable</del>
2. Add the hoptoad_notifier gem to config/environment.rb(config/environment.rbãã«ãgemãhoptoad_notifierã追å ):
config.gem 'hoptoad_notifier
3. Install the gem(rakeã³ãã³ãã§ã¤ã³ã¹ãã¼ã«):
rake gems:install
4. Unpack the gem(gemãã¢ã³ããã¯ãvendor/plugins以ä¸ã«é ç½®ãããã ããªã®ã§ãããªãã¦ãOK):
rake gems:unpack GEM=hoptoad_notifier
5. Configure the notifier(è¨å®ãã¡ã¤ã«ã®çæ):
script/generate hoptoad --api-key apikey123apikey123apikey123apikey123
6. Look for the exception to appear in your errors list(ä¾å¤ã¯Hoptoadã®ã¨ã©ã¼ãªã¹ããè¦ããã¨è¡¨ç¤ºããããã¼).
æºåãããã§å®äºãã¾ãã. ãã¨ã¯å®éã«éç¥ããããã°Hoptoadã«ã¨ã©ã¼ãªã¹ãã表示ããã¾ã.
ã¨ã©ã¼ãè¦ããããã¹ã
ããã¸ã§ã¯ãã«ã¼ãã§ä»¥ä¸ã®ã³ãã³ããå®è¡
rake hoptoad:test
$ rake hoptoad:test (in /Users/satoruk/Developments/foo) ** [Hoptoad] Notifier 2.3.0 ready to catch errors Configuration: http_open_timeout: 2 proxy_host: nil notifier_url: "http://hoptoadapp.com" port: 80 proxy_user: nil http_read_timeout: 5 api_key: "apikey123apikey123apikey123apikey123" notifier_version: "2.3.0" ignore: ["ActiveRecord::RecordNotFound", "ActionController::Rou development_environments: [] params_filters: ["password", "password_confirmation"] proxy_pass: nil ignore_by_filters: [] secure: false framework: "Rails: 2.3.8" project_root: "/Users/satoruk/Developments/foo" backtrace_filters: [#<Proc:0x00000001017033c8@/opt/local/lib/ruby/gems/1.8 proxy_port: nil ignore_user_agent: [] protocol: "http" host: "hoptoadapp.com" development_lookup: true notifier_name: "Hoptoad Notifier" environment_name: "development" Setting up the Controller. Processing request. Raising 'HoptoadTestingException' to simulate application failure. Sending request to http://hoptoadapp.com/notifier_api/v2/notices/: XMLã®ã³ã¼ããããã㨠** [Hoptoad] Success: Net::HTTPOK ** [Hoptoad] Environment Info: [Ruby: 1.8.7] [Rails: 2.3.8] [Env: development] ** [Hoptoad] Response from Hoptoad: <?xml version="1.0" encoding="UTF-8"?> <notice> <error-id type="integer">1986027</error-id> <url>http://bar.hoptoadapp.com/errors/0000000/notices/00000000</url> <id type="integer">000000</id> </notice> Rendered layouts/_head (2.6ms) Rendered layouts/_groval_header (1.5ms) Rendered layouts/_copyright (0.8ms) Rendered layouts/_footer (7.6ms)
ã£ã§Hoptoadä¸ã§è¦ã¦ã¿ãã¨ã¨ã©ã¼ãã§ã¦ã¾ãã¨.
åã¨ã©ã¼ã¯Unresolvedã¨Resolvedã®ã¹ãã¼ã¿ã¹ãå¤ããããã®ã§ã¨ã©ã¼ã調ã¹çµãã£ããResolvedã«ãã¦ãæãã§ã.
ããã£ãã¨ãã
ãã®ã¾ãã®ã¨ã³ããªã¼ã®エラー処理ã§rescue_action_in_publicãä¸æ¸ããã¦ãã®ã§ãHoptoadãåãã¾ããã§ãã. ã³ã¼ããèªãã¨Hoptoadã¯rescue_action_in_publicãå©ç¨ãã¦ããã®ã§ã以ä¸ã®ãããªåé¿çãå¿ è¦ã§ã.
def rescue_action_in_public(exception) #:doc: unless hoptoad_ignore_user_agent? HoptoadNotifier.notify_or_ignore(exception, hoptoad_request_data) end # ï¼ # ï¼ # ï¼ end
Hoptoadãã¾ã¨ãã«åãã¦ãªãã£ãã¨ãããrake hoptoad:testãã®çµæã«ä»¥ä¸ã®ãããªå 容ãããã¾ã.ã
Raising 'HoptoadTestingException' to simulate application failure.