epitools 0.5.100 → 0.5.103

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9ab55bd4da24b0248446b9a5ce73720500595a5
4
- data.tar.gz: 21216bbed7ed7d2d62ee5f0e4f8c3ee55bbf1a41
3
+ metadata.gz: 37053f6a5bb1b1406914ce14114703107679b60f
4
+ data.tar.gz: 7a309d8da2d15f2f73021680cb0de08846089db3
5
5
  SHA512:
6
- metadata.gz: c1309e3223556495583e860b4c94389f6307b0cd5e8932a4af9e1eddb8dc7c3659b6884262d2076e559f9cbe466a97d7a0e1c21a85136be9f936af894a67d00c
7
- data.tar.gz: 65f74192fa9eac491bf4e3a7a1be548fecb406190e76e250f2821215a6f1759bbfc46061deeba2c34249338d4ba608696667a8594ab089a695dcff1b9e42af14
6
+ metadata.gz: 6008b6abf95ac50f0ce55974b0378a3a03eee78f94d9a71967b75b482b1bdd9b99993d702dbb432c55da127fdafcb12b42e30a674d734d8baa610116254f69e6
7
+ data.tar.gz: b0ba59178f118c8d857fe7d853ba47d224c74806ac5be870e6d7203cabcc5a588615e0913d7a7e703b0a9748875e7f003a28b7438ba02ac9eab6b08323e907ea
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.100
1
+ 0.5.103
@@ -207,3 +207,26 @@ def which(*bins)
207
207
  end
208
208
  nil
209
209
  end
210
+
211
+
212
+ #
213
+ # Executes notify-send to create a desktop notification on the user's desktop
214
+ #
215
+ # Note: the 'icon' argument is the path to an image file
216
+ #
217
+ def notify_send(title, body=nil, icon: nil, time: 5)
218
+ $stderr.puts "* #{title}"
219
+ $stderr.puts " |_ #{body}" if body
220
+
221
+ time_in_ms = time * 1000
222
+
223
+ cmd = ["notify-send"]
224
+ cmd << "--expire-time=#{time_in_ms}"
225
+ cmd << "--app-name=#{Process.argv0}"
226
+ cmd << "--icon=#{icon}" if icon
227
+ cmd << CGI.escapeHTML(title)
228
+ cmd << CGI.escapeHTML(body) if body
229
+
230
+ fork { system *cmd }
231
+ end
232
+
@@ -374,7 +374,7 @@ module Enumerable
374
374
  end
375
375
 
376
376
  #
377
- # Reverse zip (aligns the ends of two arrays, and zipping them from the right-hand side)
377
+ # Reverse zip (aligns the ends of two arrays, and zips them from right to left)
378
378
  #
379
379
  # eg:
380
380
  # >> [5,39].rzip([:hours, :mins, :secs])
@@ -98,10 +98,32 @@ class File
98
98
  data
99
99
  end
100
100
 
101
+ #
102
+ # Scan through the file until `string` is found, and set the IO's +pos+ to the first character of the matched string.
103
+ #
104
+ def seek_to(string, blocksize=512)
105
+ raise "Error: blocksize must be at least as large as the string" if string.size < blocksize
106
+
107
+ loop do
108
+ data = read(blocksize)
109
+
110
+ if index = data.index(string)
111
+ seek(-(data.size - index), IO::SEEK_CUR)
112
+ break
113
+ elsif eof?
114
+ break
115
+ else
116
+ seek(-(string.size - 1), IO::SEEK_CUR)
117
+ end
118
+ end
119
+ end
120
+
101
121
  #
102
122
  # Scan backwards in the file until `string` is found, and set the IO's +pos+ to the first character after the matched string.
103
- #
123
+ #
104
124
  def seek_backwards_to(string, blocksize=512, rindex_end=-1)
125
+ raise "Error: blocksize must be at least as large as the string" if string.size < blocksize
126
+
105
127
  loop do
106
128
  data = reverse_read(blocksize)
107
129
 
@@ -110,8 +132,11 @@ class File
110
132
  break
111
133
  elsif pos == 0
112
134
  break
135
+ else
136
+ seek(string.size - 1, IO::SEEK_CUR)
113
137
  end
114
138
  end
115
139
  end
140
+ alias_method :reverse_seek_to, :seek_backwards_to
116
141
 
117
142
  end
@@ -262,33 +262,38 @@ end
262
262
 
263
263
  ####################################################################
264
264
 
265
- class << ARGV
266
- def paths_R
267
- the_expander = proc do |paths|
268
- paths.map { |path| path.dir? ? the_expander.(path.ls_R) : path }
269
- end
270
-
271
- the_expander.(paths)
272
- end
273
- alias_method :recursive_paths, :paths_R
274
-
275
- def paths
276
- map(&:to_Path)
277
- end
278
-
279
- def opts
280
- partition { |arg| arg[/^--?\w{1,2}/].nil? }
281
- end
282
-
283
- def args
284
- self - opts
285
- end
286
-
287
- def regexes
288
- map { |arg| /#{Regexp.escape arg}/i }
289
- end
290
-
291
- end
265
+ # class << ARGV
266
+
267
+ # def opts
268
+ # @opts, @args ||= partition { |arg| arg[/^--?\w{1,2}/].nil? }
269
+ # end
270
+
271
+ # def args
272
+ # @args ? @args : opts && @args
273
+ # end
274
+
275
+ # def paths
276
+ # map(&:to_Path)
277
+ # end
278
+
279
+ # def paths_R
280
+ # recursive_proc = proc do |paths|
281
+ # paths.map { |path| path.dir? ? the_expander.(path.ls_R) : path }
282
+ # end
283
+
284
+ # recursive_proc.(paths)
285
+ # end
286
+ # alias_method :recursive_paths, :paths_R
287
+
288
+ # def regexes(escaped: true, case_sensitive: false)
289
+ # if case_sensitive
290
+ # map { |arg| /#{escaped ? Regexp.escape(arg) : arg}/ } # NO 'i'
291
+ # else
292
+ # map { |arg| /#{escaped ? Regexp.escape(arg) : arg}/i }
293
+ # end
294
+ # end
295
+
296
+ # end
292
297
 
293
298
  ####################################################################
294
299
 
@@ -125,14 +125,13 @@ class Path
125
125
  def initialize(newpath, hints={})
126
126
  send("path=", newpath, hints)
127
127
 
128
- # p hints
129
- if hints[:unlink_when_garbage_collected]
130
- backup_path = path.dup
131
- puts "unlinking #{backup_path} after gc!"
132
- ObjectSpace.define_finalizer self do |object_id|
133
- File.unlink backup_path
134
- end
135
- end
128
+ # if hints[:unlink_when_garbage_collected]
129
+ # backup_path = path.dup
130
+ # puts "unlinking #{backup_path} after gc!"
131
+ # ObjectSpace.define_finalizer self do |object_id|
132
+ # File.unlink backup_path
133
+ # end
134
+ # end
136
135
  end
137
136
 
138
137
  def initialize_copy(other)
@@ -43,4 +43,9 @@ describe Object do
43
43
  -> { geoip("8.8.4.4", nil, nil) }.should raise_error(RuntimeError)
44
44
  end
45
45
 
46
+
47
+ it "notifies" do
48
+ notify_send("butt", "hello i am a butt\nbuttbuttbutt")
49
+ end
50
+
46
51
  end
@@ -1022,6 +1022,24 @@ end
1022
1022
 
1023
1023
  describe File do
1024
1024
 
1025
+ it "seeks_to" do
1026
+ tmp = Path.tmp
1027
+ tmp << "012345hello7890"
1028
+ f = open(tmp)
1029
+
1030
+ f.seek_to("hell", 4)
1031
+
1032
+ f.pos.should == 6
1033
+ f.read(4).should == "hell"
1034
+
1035
+ f.seek(-1, IO::SEEK_END)
1036
+
1037
+ f.seek_backwards_to("hell", 5)
1038
+
1039
+ f.pos.should == 10
1040
+ f.read(4).should == "o789"
1041
+ end
1042
+
1025
1043
  it "reverse_eaches" do
1026
1044
  tmp = Path.tmp
1027
1045
  tmp << "hi\nthere\neveryone!\n"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.100
4
+ version: 0.5.103
5
5
  platform: ruby
6
6
  authors:
7
7
  - epitron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-23 00:00:00.000000000 Z
11
+ date: 2017-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec