mini_suffix 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +68 -0
- data/Rakefile +6 -0
- data/benchmark/bench.rb +24 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/mini_suffix.rb +21 -0
- data/lib/mini_suffix/version.rb +3 -0
- data/mini_suffix.gemspec +29 -0
- data/vendor/libpsl.so +0 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0be3c2c9d92f4a37a7691c18bb0cfcef55c1231f
|
4
|
+
data.tar.gz: 65a80e40e464a618508698c3d906d54d31c8a06d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c18c41f0b55013130fad3aae53d83d80ac14123435cb24ea444e8f5c9ebd6850384a734b395099d91dada8af5a8096e8cc4179617585eb04e4d5313fb46667bf
|
7
|
+
data.tar.gz: f02b57073cbfa0f41bb0a84dd44a97cbe0b863518003d26d876012612ea9da7502c074fd49e559840d37b60a75094b708657e4c7f911496df8817b814b867130
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Guo Xiang Tan
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# MiniSuffix
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
### Debian
|
6
|
+
`sudo apt-get install libpsl-dev`
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'mini_suffix'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install mini_suffix
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
```
|
25
|
+
require 'mini_suffix'
|
26
|
+
|
27
|
+
MiniSuffix.domain("meta.discourse.org")
|
28
|
+
# => "discourse.org"
|
29
|
+
|
30
|
+
MiniSuffix.domain("www.careers.gov.sg")
|
31
|
+
# => "careers.gov.sg"
|
32
|
+
```
|
33
|
+
|
34
|
+
##Benchmark
|
35
|
+
|
36
|
+
```
|
37
|
+
# benchmark/bench.rb
|
38
|
+
|
39
|
+
PublicSuffix.domain total allocated memsize: 6574255
|
40
|
+
PublicSuffix.domain total retained memsize: 1133266
|
41
|
+
MiniSuffix.domain total allocated memsize: 8000
|
42
|
+
MiniSuffix.domain total retained memsize: 0
|
43
|
+
|
44
|
+
Warming up --------------------------------------
|
45
|
+
PublicSuffix.domain 4.503k i/100ms
|
46
|
+
MiniSuffix.domain 77.107k i/100ms
|
47
|
+
Calculating -------------------------------------
|
48
|
+
PublicSuffix.domain 47.521k (± 2.2%) i/s - 238.659k in 5.024541s
|
49
|
+
MiniSuffix.domain 875.595k (± 3.8%) i/s - 4.395M in 5.027237s
|
50
|
+
|
51
|
+
Comparison:
|
52
|
+
MiniSuffix.domain: 875594.7 i/s
|
53
|
+
PublicSuffix.domain: 47521.2 i/s - 18.43x slower
|
54
|
+
```
|
55
|
+
|
56
|
+
## Development
|
57
|
+
|
58
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
59
|
+
|
60
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
61
|
+
|
62
|
+
## Contributing
|
63
|
+
|
64
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/discourse/mini_suffix.
|
65
|
+
|
66
|
+
## License
|
67
|
+
|
68
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/benchmark/bench.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'memory_profiler'
|
2
|
+
require 'benchmark/ips'
|
3
|
+
require 'public_suffix'
|
4
|
+
require 'mini_suffix'
|
5
|
+
|
6
|
+
public_suffix_mem = MemoryProfiler.report do
|
7
|
+
100.times { PublicSuffix.domain("www.careers.gov.sg") }
|
8
|
+
end
|
9
|
+
|
10
|
+
mini_suffix_mem = MemoryProfiler.report do
|
11
|
+
100.times { MiniSuffix.domain("www.careers.gov.sg") }
|
12
|
+
end
|
13
|
+
|
14
|
+
puts "PublicSuffix.domain total allocated memsize: #{public_suffix_mem.total_allocated_memsize}"
|
15
|
+
puts "PublicSuffix.domain total retained memsize: #{public_suffix_mem.total_retained_memsize}"
|
16
|
+
puts "MiniSuffix.domain total allocated memsize: #{mini_suffix_mem.total_allocated_memsize}"
|
17
|
+
puts "MiniSuffix.domain total retained memsize: #{mini_suffix_mem.total_retained_memsize}"
|
18
|
+
puts
|
19
|
+
|
20
|
+
Benchmark.ips do |x|
|
21
|
+
x.report('PublicSuffix.domain') { PublicSuffix.domain("www.careers.gov.sg") }
|
22
|
+
x.report('MiniSuffix.domain') { MiniSuffix.domain("www.careers.gov.sg") }
|
23
|
+
x.compare!
|
24
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mini_suffix"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/mini_suffix.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "mini_suffix/version"
|
2
|
+
require 'ffi'
|
3
|
+
|
4
|
+
module MiniSuffix
|
5
|
+
extend FFI::Library
|
6
|
+
|
7
|
+
ffi_lib File.join(File.dirname(File.expand_path('..', __FILE__)), 'vendor/libpsl.so')
|
8
|
+
attach_function :psl_builtin, [], :pointer
|
9
|
+
attach_function :psl_registrable_domain, [:pointer, :string], :string
|
10
|
+
attach_function :psl_get_version, [], :string
|
11
|
+
|
12
|
+
@@context = psl_builtin
|
13
|
+
|
14
|
+
# Extracts the shortest private suffix part of the hostname
|
15
|
+
#
|
16
|
+
# @param [String] hostname
|
17
|
+
# @return [String] private_suffix
|
18
|
+
def self.domain(hostname)
|
19
|
+
self.psl_registrable_domain(@@context, hostname)
|
20
|
+
end
|
21
|
+
end
|
data/mini_suffix.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "mini_suffix/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mini_suffix"
|
8
|
+
spec.version = MiniSuffix::VERSION
|
9
|
+
spec.authors = ["Guo Xiang Tan"]
|
10
|
+
spec.email = ["tgx@discourse.org"]
|
11
|
+
|
12
|
+
spec.summary = %q{FFI wrapper for libpsl}
|
13
|
+
spec.homepage = "https://github.com/discourse/mini_suffix"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency 'ffi', '~> 1.9'
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
end
|
data/vendor/libpsl.so
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mini_suffix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Guo Xiang Tan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ffi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- tgx@discourse.org
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- benchmark/bench.rb
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- lib/mini_suffix.rb
|
87
|
+
- lib/mini_suffix/version.rb
|
88
|
+
- mini_suffix.gemspec
|
89
|
+
- vendor/libpsl.so
|
90
|
+
homepage: https://github.com/discourse/mini_suffix
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.6.13
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: FFI wrapper for libpsl
|
114
|
+
test_files: []
|