json-bloomfilter 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- json-bloomfilter (0.0.4)
4
+ json-bloomfilter (0.0.5)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.md CHANGED
@@ -1,10 +1,18 @@
1
- # JSON Bloomfilter
1
+ # Serialisable (JSON) Bloom Filter
2
2
 
3
- A BloomFilter implementation that is serialisable to JSON and compatible between both Ruby and Javascript. Very useful when needing to train a bloom filter in one language and using it in the other.
3
+ A bloom filter implementation that is serialisable to JSON and compatible between both Ruby and Javascript. Very useful when needing to train a bloom filter in one language and using it in the other.
4
4
 
5
- ## Usage
5
+ ## Why?
6
+
7
+ Bloom filters allow for space efficient lookups in a list, without having to store all the items in the list. This is useful for looking up tags, domain names, links, or anything else that you might want to do client side.
8
+
9
+ What this Gem allows you to do is build a bloom filter server side, add all your entries to it, and then serialise the filter to JSON. On the client side you can then load up the serialised data into the Javascript version and use the bloom filter as is.
6
10
 
7
- ### Installation
11
+ All of this while not sending the entire list to the client, which is something you might not want to do for either security or efficiency reasons.
12
+
13
+ ## Installation
14
+
15
+ ### Ruby
8
16
 
9
17
  ```shell
10
18
  gem install json-bloomfilter
@@ -18,6 +26,18 @@ gem 'json-bloomfilter'
18
26
 
19
27
  in your Gemfile
20
28
 
29
+ ### Javascript
30
+
31
+ With the gem installed run
32
+
33
+ ```
34
+ json-bloomfilter install
35
+ ```
36
+
37
+ and the `json-bloomfilter.min.js` will be copied to your local directory. If you are in a Rail project it will be copied to your `app/assets/javascripts` folder.
38
+
39
+ ## Usage
40
+
21
41
  ### Ruby
22
42
 
23
43
  ```ruby
@@ -43,23 +63,23 @@ filter2.test "doh" #=> probably false
43
63
  ### Javascript
44
64
 
45
65
  ```javascript
46
- # create a new BloomFilter and add entries
66
+ // create a new BloomFilter and add entries
47
67
  filter = new JsonBloomFilter({ size: 100 });
48
68
  filter.add("foo");
49
69
  filter.add("bar");
50
- filter.test("foo"); #=> true
51
- filter.test("bar"); #=> true
52
- filter.test("doh"); #=> probably false
70
+ filter.test("foo"); //=> true
71
+ filter.test("bar"); //=> true
72
+ filter.test("doh"); //=> probably false
53
73
 
54
- # export the filter to a hash or json
55
- filter.toJson(); #=> hash as JSON
56
- config = filter.toHash(); #=> { "size" => 100, "hashes" => 4, "seed" => 1234567890, "bits" => [...] }
74
+ // export the filter to a hash or json
75
+ filter.toJson(); //=> hash as JSON
76
+ config = filter.toHash(); //=> { "size" => 100, "hashes" => 4, "seed" => 1234567890, "bits" => [...] }
57
77
 
58
- # use the hash to generate a new BloomFilter with the same config
78
+ // use the hash to generate a new BloomFilter with the same config
59
79
  filter2 = new JsonBloomFilter(config);
60
- filter2.test("foo"); #=> true
61
- filter2.test("bar"); #=> true
62
- filter2.test("doh") #=> probably false
80
+ filter2.test("foo"); //=> true
81
+ filter2.test("bar"); //=> true
82
+ filter2.test("doh") //=> probably false
63
83
  ```
64
84
 
65
85
  ### Options
@@ -76,18 +96,19 @@ Additionally you can pass along:
76
96
 
77
97
  ## Credits
78
98
 
79
- * bitarray.rb and bitarray.coffee based on [version by Peter Cooper](https://github.com/peterc/bitarray).
80
- * bloomfilter.rb and bloomfilter.coffee inspired by [Ilya Grigorik's Redis Bloomfilter](https://github.com/igrigorik/bloomfilter-rb/blob/master/lib/bloomfilter/redis.rb)
81
- * zlib.coffee crc32 method based on the [node-crc32](https://github.com/mikepulaski/node-crc32) library and [this snippet](http://stackoverflow.com/questions/6226189/how-to-convert-a-string-to-bytearray/10132540#10132540)
99
+ * [bitarray.rb](https://github.com/cbetta/json-bloomfilter/blob/master/lib/json/bloomfilter/bitarray.rb) and [bitarray.coffee](https://github.com/cbetta/json-bloomfilter/blob/master/coffee/bitarray.coffee) based on [version by Peter Cooper](https://github.com/peterc/bitarray).
100
+ * [bloomfilter.rb](https://github.com/cbetta/json-bloomfilter/blob/master/lib/json/bloomfilter.rb) and [bloomfilter.coffee](https://github.com/cbetta/json-bloomfilter/blob/master/coffee/bloomfilter.coffee) inspired by [Ilya Grigorik's Redis Bloomfilter](https://github.com/igrigorik/bloomfilter-rb/blob/master/lib/bloomfilter/redis.rb)
101
+ * [zlib.coffee](https://github.com/cbetta/json-bloomfilter/blob/master/coffee/zlib.coffee) crc32 method based on the [node-crc32](https://github.com/mikepulaski/node-crc32) library and [this snippet](http://stackoverflow.com/questions/6226189/how-to-convert-a-string-to-bytearray/10132540#10132540)
82
102
 
83
103
  ## Release notes
84
104
 
85
- * **0.0.4** Added JS tests
86
- * **0.0.3** Added Ruby tests
87
- * **0.0.2** First implementation of both Ruby and JS filters
88
- * **0.0.1** Skeleton
105
+ * **0.0.5** Adds installer of JS file
106
+ * **0.0.4** Adds JS tests
107
+ * **0.0.3** Adds Ruby tests
108
+ * **0.0.2** Adds implementation of Ruby and JS filters
109
+ * **0.0.1** Gem skeleton
89
110
 
90
111
  ## License
91
112
 
92
- See LICENSE
113
+ See [LICENSE](https://github.com/cbetta/json-bloomfilter/blob/master/LICENSE)
93
114
 
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ def install
4
+ current_dir = File.expand_path(File.dirname(__FILE__))
5
+ filename = "json-bloomfilter.min.js"
6
+ source = "#{current_dir}/../js/#{filename}"
7
+ target_dir = Dir.pwd
8
+ rails_gems = `bundle list | grep rail`
9
+ js_dir = "#{target_dir}/app/assets/javascripts"
10
+
11
+ if !rails_gems.empty? && File.directory?(js_dir)
12
+ target = "#{js_dir}/#{filename}"
13
+ else
14
+ target = "#{target_dir}/#{filename}"
15
+ end
16
+
17
+ puts "Copying #{filename} to #{target}"
18
+ `cp #{source} #{target}`
19
+ puts "\t...done"
20
+ end
21
+
22
+ case ARGV.first
23
+ when "install"
24
+ install
25
+ else
26
+ puts "No command found"
27
+ puts "Usage: json-bloomfilter [command]"
28
+ puts "Command:"
29
+ puts "\tinstall: installs the json-bloomfilter.min.js into your current folder"
30
+ end
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.files = `git ls-files`.split("\n")
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
19
  s.require_paths = ["lib"]
19
20
 
20
21
  s.add_development_dependency 'rspec'
@@ -1,3 +1,3 @@
1
1
  class JsonBloomfilter
2
- VERSION = "0.0.4" unless defined? Trifle::VERSION
2
+ VERSION = "0.0.5" unless defined? JsonBloomfilter::VERSION
3
3
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-bloomfilter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -128,7 +128,8 @@ description: A bloomfilter implementation in both Ruby and Javascript that can b
128
128
  in one language and using it in the other.
129
129
  email:
130
130
  - cbetta@gmail.com
131
- executables: []
131
+ executables:
132
+ - json-bloomfilter
132
133
  extensions: []
133
134
  extra_rdoc_files: []
134
135
  files:
@@ -139,6 +140,7 @@ files:
139
140
  - LICENSE
140
141
  - README.md
141
142
  - Rakefile
143
+ - bin/json-bloomfilter
142
144
  - coffee/bitarray.coffee
143
145
  - coffee/bloomfilter.coffee
144
146
  - coffee/zlib.coffee
@@ -150,6 +152,7 @@ files:
150
152
  - pkg/json-bloomfilter-0.0.1.gem
151
153
  - pkg/json-bloomfilter-0.0.2.gem
152
154
  - pkg/json-bloomfilter-0.0.3.gem
155
+ - pkg/json-bloomfilter-0.0.4.gem
153
156
  - spec/javascripts/bitarray_spec.js
154
157
  - spec/javascripts/bloomfilter_spec.js
155
158
  - spec/javascripts/support/jasmine.yml
@@ -178,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
181
  version: '0'
179
182
  segments:
180
183
  - 0
181
- hash: -4107655990555845610
184
+ hash: -2817910243396386153
182
185
  requirements: []
183
186
  rubyforge_project:
184
187
  rubygems_version: 1.8.24