infod 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/infod.rb +2 -3
  2. data/infod/Es.rb +31 -67
  3. data/infod/{W/source.rb → Es/code.rb} +6 -10
  4. data/infod/Es/css.rb +21 -0
  5. data/infod/{W → Es}/csv.rb +0 -0
  6. data/infod/Es/du.rb +16 -0
  7. data/infod/{W → Es}/feed.rb +13 -11
  8. data/infod/Es/filter.rb +75 -0
  9. data/infod/Es/find.rb +20 -0
  10. data/infod/Es/fs.rb +145 -136
  11. data/infod/Es/glob.rb +22 -0
  12. data/infod/Es/grep.rb +61 -0
  13. data/infod/Es/groonga.rb +47 -56
  14. data/infod/Es/html.rb +271 -0
  15. data/infod/Es/image.rb +114 -0
  16. data/infod/Es/in.rb +68 -0
  17. data/infod/Es/index.rb +183 -0
  18. data/infod/{W → Es}/json.rb +28 -4
  19. data/infod/Es/kv.rb +60 -0
  20. data/infod/Es/ls.rb +58 -0
  21. data/infod/Es/mail.rb +87 -0
  22. data/infod/Es/man.rb +112 -0
  23. data/infod/Es/mime.rb +59 -0
  24. data/infod/Es/out.rb +52 -0
  25. data/infod/{W/page.rb → Es/pager.rb} +7 -3
  26. data/infod/Es/pdf.rb +19 -0
  27. data/infod/Es/rdf.rb +35 -0
  28. data/infod/Es/schema.rb +99 -0
  29. data/infod/Es/search.rb +24 -0
  30. data/infod/Es/sh.rb +21 -0
  31. data/infod/{W → Es}/text.rb +26 -14
  32. data/infod/H.rb +15 -29
  33. data/infod/H/audio.rb +19 -0
  34. data/infod/H/blog.rb +15 -0
  35. data/infod/{W → H}/cal.rb +2 -31
  36. data/infod/H/edit.rb +88 -0
  37. data/infod/{W/examine/examine.rb → H/facets.rb} +17 -17
  38. data/infod/{W → H}/forum.rb +1 -0
  39. data/infod/{W/examine/sw.rb → H/hf.rb} +12 -12
  40. data/infod/H/histogram.rb +78 -0
  41. data/infod/H/mail.rb +92 -0
  42. data/infod/{W/chat.rb → H/microblog.rb} +21 -16
  43. data/infod/H/threads.rb +77 -0
  44. data/infod/H/time.rb +131 -0
  45. data/infod/H/who.rb +30 -0
  46. data/infod/{W → H}/wiki.rb +0 -0
  47. data/infod/K.rb +28 -60
  48. data/infod/N.rb +151 -74
  49. data/infod/Rb.rb +3 -3
  50. data/infod/Th.rb +27 -101
  51. data/infod/Th/404.rb +29 -36
  52. data/infod/Th/500.rb +36 -5
  53. data/infod/Th/GET.rb +48 -118
  54. data/infod/Th/POST.rb +31 -11
  55. data/infod/Th/perf.rb +37 -0
  56. data/infod/Th/util.rb +89 -0
  57. data/infod/Y.rb +24 -7
  58. data/infod/infod.rb +2 -3
  59. metadata +92 -64
  60. data/infod/Es/redis.rb +0 -3
  61. data/infod/Es/sqlite.rb +0 -3
  62. data/infod/Th/local.rb +0 -22
  63. data/infod/W.rb +0 -34
  64. data/infod/W/audio.rb +0 -56
  65. data/infod/W/blog.rb +0 -3
  66. data/infod/W/color.rb +0 -28
  67. data/infod/W/core.rb +0 -77
  68. data/infod/W/css.rb +0 -24
  69. data/infod/W/du.rb +0 -35
  70. data/infod/W/edit.rb +0 -8
  71. data/infod/W/examine/exhibit.rb +0 -34
  72. data/infod/W/examine/hist.rb +0 -55
  73. data/infod/W/examine/history.rb +0 -19
  74. data/infod/W/examine/normal.rb +0 -31
  75. data/infod/W/examine/protovis.rb +0 -30
  76. data/infod/W/examine/time/graph.rb +0 -86
  77. data/infod/W/examine/time/line.rb +0 -24
  78. data/infod/W/find.rb +0 -24
  79. data/infod/W/grep.rb +0 -27
  80. data/infod/W/html.rb +0 -143
  81. data/infod/W/image.rb +0 -61
  82. data/infod/W/kv.rb +0 -66
  83. data/infod/W/ls.rb +0 -50
  84. data/infod/W/mail.rb +0 -248
  85. data/infod/W/pdf.rb +0 -16
  86. data/infod/W/post.rb +0 -9
  87. data/infod/W/rdf.rb +0 -32
  88. data/infod/W/schema.rb +0 -172
  89. data/infod/W/search.rb +0 -33
  90. data/infod/W/shell.rb +0 -30
  91. data/infod/W/table.rb +0 -87
  92. data/infod/W/tree.rb +0 -26
  93. data/infod/W/vfs.rb +0 -175
data/infod/W.rb DELETED
@@ -1,34 +0,0 @@
1
- %w{
2
- core
3
- vfs
4
- audio
5
- cal
6
- chat
7
- color
8
- css
9
- csv
10
- du
11
- edit
12
- examine/examine
13
- feed
14
- find
15
- grep
16
- html
17
- image
18
- json
19
- kv
20
- ls
21
- mail
22
- page
23
- post
24
- pdf
25
- rdf
26
- schema
27
- search
28
- shell
29
- source
30
- table
31
- text
32
- tree
33
- wiki
34
- }.each{|r|require_relative 'W/'+r}
data/infod/W/audio.rb DELETED
@@ -1,56 +0,0 @@
1
- #watch __FILE__
2
- class E
3
-
4
- F["?"]||={}; F["?"].update({'af'=>{'graph' => 'audioFind','view' => 'audioplayer'},
5
- 'a'=>{'set' => 'audio','view' => 'audioplayer'},
6
- 'v'=>{'set' => 'video','view' => 'audioplayer','video'=>true}})
7
-
8
- def audioNodes;take.select &:audioNode end;def audioNode;true if ext.match /(aif|wav|flac|mp3|m4a|aac|ogg)/i end
9
- def videoNodes;take.select &:videoNode end;def videoNode;true if ext.match /(avi|flv|mkv|mpg|mp4|wmv)/i end
10
-
11
- fn 'set/audio',->d,e,m{d.audioNodes}
12
- fn 'set/video',->d,e,m{d.videoNodes}
13
-
14
- fn 'graph/audioFind',->e,q,m{
15
- t=q['day'] && q['day'].match(/^\d+$/) && '-ctime -'+q['day']
16
- s=q['size'] && q['size'].match(/^\d+$/) && '-size +'+q['size']+'M'
17
- r=(q['find'] ? '.*'+q['find'].gsub(/[^a-zA-Z0-9\.\ ]+/,'.*') : '') + '.*.\(aif\|flac\|m4a\|mp3\|aac\|ogg\|wav\)'
18
- `find #{e.sh} #{t} #{s} -iregex "#{r}"`.lines.map{|p|p.pathToURI.do{|a|m[a.uri]=a}}}
19
-
20
- fn 'view/audioplayer/item',->m,e{
21
- {_: :a,class: :entry, href: '#'+m.uri.gsub('%','%25').gsub('#','%23'),
22
- c: m.E.bare+" \n"}}
23
-
24
- fn 'view/audioplayer/base',->d,e,c=nil{
25
- [{_: :span, id: :jump,c: 'Ⴢ   '},{_: :span, id: :rand,r: :true,c: :r},
26
- (H.once e,:mu,(H.js '/js/mu')),(H.js '/js/audio'),H.css('/css/audio'),H.css('/css/table'),
27
- {_: e.q.has_key?('video') ? :video : :audio, id: :player, controls: true},
28
- {id: :data},
29
- {id: :playlist,
30
- c: {:class => :playlistItems,c: c.()}}]}
31
-
32
- fn 'view/audioplayer',->d,e{i=F['view/audioplayer/item']
33
- Fn 'view/audioplayer/base',d,e,->{
34
- d.group_by{|u,r|
35
- u.split('/')[0..-2].join '/'}.map{|b,g|
36
- [{_: :a, class: :directory, href: b, c: ['<br>',b,'<br>']},"\n",
37
- g.map{|r|i.(r[1],e)},"\n"]}}}
38
-
39
- def audioScan
40
- a('.png').e ||
41
- (e = ext; d = sh
42
- un = e.match /^(aif|wav)$/i # compressed?
43
- a = un ? d : d+'.wav' # analyze
44
- (case e
45
- when 'flac'
46
- `flac -d #{d} -o #{a}`
47
- when 'mp3'
48
- `lame --decode #{d} #{a}`
49
- when 'ogg'
50
- `oggdec #{d} -o #{a}`
51
- end) unless un
52
- `waveformgen #{a} #{d}.png -l`
53
- `sndfile-spectrogram --no-border #{a} 1280 800 #{d}.spec.png`
54
- `rm #{a}` unless un) end
55
-
56
- end
data/infod/W/blog.rb DELETED
@@ -1,3 +0,0 @@
1
- class E
2
-
3
- end
data/infod/W/color.rb DELETED
@@ -1,28 +0,0 @@
1
- #watch __FILE__
2
- class E
3
-
4
- def E.c; '#%06x' % rand(16777216)end
5
-
6
- fn 'view/color',->d,e{
7
-
8
- n = (e.q['n']||42).to_i.max 255
9
-
10
- hsv2rgb=->h,s,v{
11
- i = h.floor
12
- f = h - i
13
- p = v * (1 - s)
14
- q = v * (1 - (s * f))
15
- t = v * (1 - (s * (1 - f)))
16
- r,g,b=[[v,t,p],
17
- [q,v,p],
18
- [p,v,t],
19
- [p,q,v],
20
- [t,p,v],
21
- [v,p,q]][i].map{|q|q*255.0}}
22
-
23
- [H.css('/css/color'),
24
- {style: 'display:table;width:100%',
25
- c: [(1..10).map{|s| {class: :row, c: (0..n-1).map{|h| {class: :c,style: 'background-color:#%02x%02x%02x' % hsv2rgb.(h/(n/6.0),s/10.0,1.0)}}}},
26
- (1..10).to_a.reverse.map{|v| {class: :row, c: (0..n-1).map{|h| {class: :c,style: 'background-color:#%02x%02x%02x' % hsv2rgb.(h/(n/6.0),1.0,v/10.0)}}}}]}]}
27
-
28
- end
data/infod/W/core.rb DELETED
@@ -1,77 +0,0 @@
1
-
2
- class Hash
3
- def graph g
4
- g.merge!({uri=>self})
5
- end
6
- %w{graphFromFile q}.map{|m|alias_method m,:graph}
7
- def mergeGraph g
8
- g.values.each do |r|
9
- r.triples do |s,p,o|
10
- self[s] = {'uri' => s} unless self[s].class == Hash
11
- self[s][p] ||= []
12
- self[s][p].push o unless self[s][p].member? o
13
- end
14
- end
15
- self
16
- end
17
- def attr p;map{|_,r|r[p].do{|o|return o}}; nil end
18
- # Hash -> tripleStream
19
- def triples
20
- s = uri
21
- map{|p,o|
22
- o.class == Array ? o.each{|o| yield s,p,o} : yield(s,p,o) unless p=='uri'}
23
- end
24
- end
25
-
26
- class E
27
-
28
- # fromStream :: Graph -> tripleStream -> Graph
29
- def fromStream m,*i
30
- send(*i) do |s,p,o|
31
- m[s] = {'uri' => s} unless m[s].class == Hash
32
- m[s][p] ||= []
33
- m[s][p].push o unless m[s][p].member? o
34
- end; m
35
- end
36
-
37
- # tripleStream transformer stack
38
- fn 'graph/|',->e,_,m{e.fromStream m, *_['|'].split(/,/)}
39
-
40
- def E.graphFromStream s
41
- fn 'graph/'+s.to_s,->e,_,m{e.fromStream m, s}
42
- end
43
-
44
- # placeholder to circumvent empty-graph 404
45
- fn 'graph/_',->d,_,m{ m[d.uri] = {} }
46
-
47
- # to_h :: -> Hash
48
- def to_h
49
- {'uri'=>uri}
50
- end
51
-
52
- def triplrMIMEdispatch &b;mime.do{|mime|
53
- yield uri,E::Type,(E MIMEtype+mime)
54
- (MIMEsource[mime]||
55
- MIMEsource[mime.split(/\//)[0]]).do{|s|
56
- send *s,&b }}
57
- end
58
-
59
- def graphFromFile g={}
60
- g.mergeGraph r(true) if ext=='e' # JSON -> graph
61
- [:triplrInode, # filesystem data
62
- :triplrMIMEdispatch].# format-specific tripleStream
63
- each{|i| fromStream g,i } # tripleStream -> Graph
64
- g
65
- end
66
-
67
- def graph g={}
68
- docs.map{|d|d.graphFromFile g} # tripleStream -> graph
69
- g
70
- end
71
-
72
- # render :: MIME, Graph, env -> String
73
- def render mime, d, e
74
- E[Render+mime].y d,e
75
- end
76
-
77
- end
data/infod/W/css.rb DELETED
@@ -1,24 +0,0 @@
1
- class E
2
-
3
- def nokogiri; require 'nokogiri'; Nokogiri::HTML.parse read end
4
-
5
- def triplrCSSselect
6
- glob.select(&:f).do{|f|(f.empty? ? [self] : f).map{|r|r.nokogiri.do{|c|c.css(sel).map{|e|
7
- yield r.uri+'#css:'+sel,Content,e.to_s
8
- }}}} end
9
-
10
- fn 'graph/css',->d,e,m{
11
- d.fromStream m,:triplrCSSselect,e['selector']}
12
-
13
- MIMEsource['text/css'] ||= [:triplrSourceCode]
14
-
15
- end
16
-
17
- class H
18
-
19
- def H.css a,inline=false
20
- p=a+'.css'
21
- inline ? {_: :style, c: p.E.r} :
22
- {_: :link, href: p, rel: :stylesheet, type: E::MIME[:css]} end
23
-
24
- end
data/infod/W/du.rb DELETED
@@ -1,35 +0,0 @@
1
- #watch __FILE__
2
- class E
3
-
4
- F["?"]||={}
5
- F["?"].update({'du'=>{
6
- 'graph' => 'du',
7
- 'view' => 'protovis',
8
- 'protovis.data' => 'protovis/du',
9
- 'protovis.view' => 'starburst'
10
- }})
11
-
12
- fn 'graph/du',->e,_,m{
13
- `du -a #{e.sh}`.lines.to_a[0..-2].map{|p|
14
- begin
15
- s,p = p.split /\t/ # size, path
16
- p = p.pathToURI # path -> URI
17
- m[p.uri]={'uri'=>p.uri,'size'=>s.to_i}
18
- rescue
19
- nil
20
- end
21
- }
22
- m}
23
-
24
- fn 'protovis/du',->e,c{
25
- m={} # model
26
- e.map{|u,r| # each resource
27
- s = u.sub(/http:..[^\/]+./,'').split '/' # split path
28
- p = m # pointer
29
- s[0..-2].map{|s| # each path segment
30
- p[s] = {} if !p[s] || p[s].class != Hash # create branch
31
- p = p[s]} # advance pointer down tree
32
- p[s[-1]]||=r['size']} # append size to leaf
33
- m}
34
-
35
- end
data/infod/W/edit.rb DELETED
@@ -1,8 +0,0 @@
1
- #watch __FILE__
2
- class E
3
-
4
- fn 'view/edit',->d,env{
5
- {_: :form, name: :editor, c: 'edit'}
6
- }
7
-
8
- end
@@ -1,34 +0,0 @@
1
- class E
2
- fn Render+'application/json+exhibit',->d,e{
3
- fields=e.q['f'].do{|f|f.split /,/}
4
- {items: d.values.map{|r|
5
- r.keys.-(['uri']).map{|k|
6
- f=k.frag.do{|f|(f.gsub /\W/,'').downcase} # alphanumeric id restriction
7
- if !fields || (fields.member? f)
8
- r[f]=r[k][0].to_s # rename fieldnames, unwrap value
9
- r.delete k unless f==k # cleanup unless id same as before
10
- else
11
- r.delete k
12
- end}
13
- r[:label]=r.delete 'uri' # requires label only
14
- r
15
- }}.to_json}
16
-
17
- fn 'head/exhibit',->d,e{
18
- '<link href="'+e['REQUEST_PATH']+e.q.merge({'format' => 'application/json+exhibit'}).qs+'" type="application/json" rel="exhibit/data" />
19
- <script src="http://api.simile-widgets.org/exhibit/2.2.0/exhibit-api.js?autoCreate=false" type="text/javascript"></script>
20
- <script>SimileAjax.jQuery(document).ready(function(){var fDone=function(){
21
- window.exhibit = Exhibit.create()
22
- window.exhibit.configureFromDOM()
23
- database.getAllProperties().map(function(f){
24
- if (!f.match(/^(label|content)$/)){
25
- var a=document.createElement("div")
26
- document.getElementById("sidebar").appendChild(a)
27
- var x=Exhibit.ListFacet.create({"expression": "."+f},a,exhibit.getUIContext())
28
- exhibit.setComponent("facet-"+f, x)}})}
29
- window.database = Exhibit.Database.create()
30
- window.database.loadDataLinks(fDone)})</script>'}
31
-
32
- fn 'view/exhibit',->d,e{'<table width="100%"><tr valign="top"><td width="25%" id=sidebar></td><td><div ex:role="view"></div></td></tr></table>'}
33
-
34
- end
@@ -1,55 +0,0 @@
1
- #watch __FILE__
2
- class E
3
-
4
- # histogram
5
- # ?view=h&a=dc:date
6
- fn 'view/h',->d,e{
7
- a=e.q['a'].do{|e|e.expand} # a : attribute to chart
8
- !a && 'attribute required' || (
9
- n=e.q['bins']&&e.q['bins'].to_f.max(999.0).min(2)||42.0 # n : number of bins
10
- v=F['view/'+(e&&e.q['hv']||'tab')] # hv : bin template
11
- (Fn 'u/hist',d,a,n).do{|h| # construct histogram bins
12
- [H.css('/css/hist'),H.js('/js/hist'),(Fn 'view/hist',h),
13
- h.map{|b,r|{style: 'display:none',
14
- :class => 's'+b.to_s.sub(/\./,'_'),
15
- c: v.(r,e)}}]})}
16
-
17
- # hist :: Graph, property, numBins -> {bin -> Graph}
18
- fn 'u/hist',->m,p,nb=32.0{
19
- h={}; bw=0; max=0; min=0
20
- m.map{|u,r|
21
- r[p]
22
- }.flatten.do{|v|
23
- v=v.compact.map{|v|v.to_time.to_f}# values
24
- bw = (v.max - v.min) / nb.min(1)} # bin width
25
- m.map{|u,r|
26
- r[p].do{|v|v.each{|v|
27
- b=(v.to_time.to_f/bw).floor*bw # bin selector
28
- h[b] ||= {}
29
- h[b][u]=r}}} # append
30
- h} # histogram
31
-
32
- # histTable :: hist -> htmlTable
33
- fn 'view/hist',->h{
34
- scale = 255 / h.map{|b,r|r.keys.size}.max.to_f
35
- b=h.keys.sort
36
- span=(b.size / 8).min 1
37
- i=-1
38
- '<table cellspacing=0 style="width:100%;max-width:100%"><tr class=histLegend>'+
39
- H(b.select{|b|
40
- i = i + 1
41
- i % span == 0
42
- }.map{|b|
43
- {_: :td,
44
- :class => :histLegendPt,
45
- colspan: span,
46
- c: {_: :span, :class => :histLabel, c: b > 1 ? b.to_i : b}}})+
47
- '</tr><tr class=hist>'+
48
- H(b.map{|b|{_: :td, title:b.to_s.sub(/\./,'_'),style: 'background-color:#'+
49
- ('%02x' % (255-(h[b].do{|p|
50
- p.keys.size * scale
51
- }||0))).do{|x|
52
- 'ff'+x+x}}})+
53
- '</tr></table>'}
54
-
55
- end
@@ -1,19 +0,0 @@
1
- class E
2
-
3
- def triplrMozHist
4
- c = @r.q['c'].match(/[0-9]+/) ? @r.q['c'] : '18'
5
- q = @r.q['match'].do{|m|m.match(/[a-zA-Z\-_\.\/]+/) && "and p.url like '#{@r.q.has_key?('full')?'':'%'}#{m}%'"}
6
- t = @r.q['t'].do{|t| "and h.visit_date < #{Time.parse(t).to_f*1e6}"}
7
-
8
- `sqlite3 -separator "\t" #{sh} "select p.url, r.url, h.visit_date, hr.visit_date from moz_places as p,moz_places as r, moz_historyvisits as h, moz_historyvisits as hr where p.id = h.place_id and r.id = hr.place_id and hr.id = h.from_visit #{q} #{t} order by h.visit_date desc limit #{c}"`.lines.to_a.map{|i|i.split "\t"}.do{|l|
9
-
10
- yield 'prev','url',@r['REQUEST_PATH']
11
- yield 'prev','t',Time.at(l[-1][2].to_f/1e6).iso8601
12
-
13
- l.map{|i|
14
- yield i[0], Date, Time.at(i[2].to_f/1e6)
15
- yield i[1], Date, Time.at(i[3].to_f/1e6)
16
- yield i[0],'referer',i[1].E }
17
-
18
- } end
19
- end
@@ -1,31 +0,0 @@
1
- #watch __FILE__
2
- class E
3
- fn 'filter/map',->o,m,_{
4
- o.except('filter','graph','view').map{|p,n|
5
- p=p.expand
6
- n=n.expand
7
- p!=n &&
8
- m.values.map{|r|
9
- r[p].do{|o|
10
- r[n]=o
11
- r.delete p }}}}
12
-
13
- fn 'view/map',->d,e{
14
- [H.js('/js/normal'),(H.once e,:mu,(H.js '/js/mu')),
15
- '<style>.b {display:inline-block;font-weight:bold;padding-right:.8em;text-align:right;min-width:12em}
16
- .exerpt {display:inline-block;max-height:1em;overflow:hidden;max-width:44em;font-size: .9em} </style>',
17
- {_: :form, c:
18
- [d.values.map(&:keys).flatten.uniq.-(['uri']).do{|ps|
19
- ps.map{|p|
20
- [{class: :b, c: p},{_: :select, name: p, c:
21
- (ps + [Date,Creator,Content,Title]).map{|q|
22
- {_: :option, c: q}.
23
- update(p==q ? {selected: :selected}:{})}},
24
- {class: :exerpt, c: d.values.map{|r|r[p]}.flatten.uniq.html},
25
- '<br>']}},
26
- {_: :input, type: :hidden, name: :view, value: :tab},
27
- {_: :input, type: :hidden, name: :filter, value: :map},
28
- {_: :input, type: :submit}
29
- ]}]}
30
-
31
- end
@@ -1,30 +0,0 @@
1
- #watch __FILE__
2
- class E
3
-
4
- F["?"]||={}
5
- F["?"].update({'arc'=>{
6
- 'view' => 'protovis',
7
- 'protovis.data' => 'protovis/net',
8
- 'protovis.view' => 'arc'
9
- }})
10
-
11
- fn 'protovis/net',->d,e{
12
- i=-1
13
- x={} # uri -> index
14
- a=[] # arcs
15
- d.values.each{|r|
16
- r.triples{|s,p,o|
17
- o.respond_to?(:uri) &&
18
- o.uri.do{|o|
19
- x[s]||=i+=1
20
- x[o]||=i+=1
21
- a.push({source: x[s], target: x[o], value: 3})}}}
22
- {nodes: x.map{|u,_|{nodeName: d[u][Title]||u.label, group: 0}},
23
- links: a}}
24
-
25
- fn 'view/protovis',->d,e{
26
- [H.js('/js/protovis/protovis-r3.2'),{id: :fig},
27
- {_: :script,type: 'text/javascript+protovis',
28
- c: ['var d='+(Fn e.q['protovis.data'],d,e).to_json,
29
- E['http://'+e['SERVER_NAME']+'/js/protovis/'+e.q['protovis.view']+'.js'].r].cr}]}
30
- end