Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Korakot Chaovavanich http://korakot.stumbleupon.com

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Finding pdf paper from CiteULike

I use CiteULike (http://citeulike.org) to manage papers a lot.
Unfortunately, I don't have access to paid site. But some authors
are generous enough to put pdf on his own site, which I find
using google search.
   1  
   2  javascript:(function(){
   3  var title = document.title.substring(11);
   4  var query = '%22' + title + '%22 ' + 'filetype:pdf';
   5  var url = 'http://www.google.com/search?q=' + encodeURI(query);
   6  window.open(url);
   7  })();


It simply takes the paper title from windows title. Then it searches the title(enclosed in quotation) for pdf files of the same name.

Change Gmail encoding to display thai.

Some emails send from yahoo and hotmail will display thai incorrectly. This bookmarklet re-encode it by shifting the unicode numbers. Can be applied to some language whose encoding is in the same "shifting" order.
   1  
   2  javascript:(function(){  map=[];for(i=161;i<251;i++)map[i]=String.fromCharCode(i+3424);  function thai(s){s2='';for(var i=0;i<s.length;i++){n=s.charCodeAt(i);if(n>160&&n<251) s2+=map[n];else s2+=s.charAt(i)}return s2}   function rc_thai(el){if(el.nodeType== 3){el.data=thai(el.data);return} if(el.tagName == 'SCRIPT') return; for (var i=0; i<el.childNodes.length; i++) rc_thai(el.childNodes[i])}   for(i=0;i<4;i++){if(fi=window.frames[0].frames[i].document.getElementById('fi')) break}  rc_thai(fi); })();

The one-liner version above maybe difficult to read.
Here's a reorganized one
   1  
   2  javascript:(function(){
   3  map=[];
   4  /* create conversion table */
   5  for(i=161;i<251;i++) {
   6    map[i]=String.fromCharCode(i+3424);
   7  }
   8  
   9  function thai(s){
  10    s2='';
  11    for(var i=0;i<s.length;i++){
  12      n=s.charCodeAt(i);
  13      if(n>160&&n<251) 
  14        s2+=map[n];
  15      else 
  16        s2+=s.charAt(i)
  17    }
  18    return s2
  19  }   
  20  
  21  /* recursively convert encoding of sub-element */
  22  function rc_thai(el){
  23    if(el.nodeType== 3){
  24      el.data=thai(el.data);
  25      return
  26    } 
  27    if(el.tagName == 'SCRIPT') 
  28      return; 
  29    for (var i=0; i<el.childNodes.length; i++)
  30      rc_thai(el.childNodes[i])
  31  }   
  32  
  33  /* finding the content element in sub-sub-frame */
  34  for(i=0;i<4;i++){
  35    if(fi=window.frames[0].frames[i].document.getElementById('fi'))
  36      break
  37  }  
  38  
  39  /* change that element (and all its descendants */
  40  rc_thai(fi); 
  41  })();
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS