buf 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/buf +75 -0
  3. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fbfd69690977b3837cfcecdb91c8eeb56c436430
4
- data.tar.gz: 163abbe97db1df6b373234bba2bf67cb38b6d021
3
+ metadata.gz: 7abdde31e11a76b3ee1933ca4777b49dbe13b49a
4
+ data.tar.gz: c854bb81830c265ffa8a117f4c1e89ccdc3dfc0c
5
5
  SHA512:
6
- metadata.gz: 07659244e7dd5ee204bcc69a4bf0fe6558a0f94e2b3103e1a724fbe54216c001b77437067feab8ed6f3af935f389347f8b8055dcba37c18870b30dd9b450e5ca
7
- data.tar.gz: 92ee76e1b2a1251f61c59e020018fb20d482bd4e54d1fcf5af9a32836eace63932b42c191ce656721cde3bd03855fbb26c6d2adf4959c49785376696ea4a174f
6
+ metadata.gz: c729b21e5d99a7771a80d0799b83047f09bdbc9b341cdab77cc3f0eabe465345947a2bce79fcecc9af452fddc90ffc70be094e6fac5ba65918d570fcb0cef174
7
+ data.tar.gz: a9aca9c8916069aaddaaff5c51d8f2ba4055630ad3c16c6d2f4c93b05845da5af159d6d6c9e72585ae7a9f78d6928f9be9d24072b0ca2e305d5816e0a28315d3
data/bin/buf ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # rubygems
4
+ require 'rubygems'
5
+
6
+ # libs
7
+ require 'thor'
8
+ require 'fileutils'
9
+ require 'tempfile'
10
+
11
+ class Buf < Thor
12
+
13
+ def initialize(*args)
14
+ super
15
+ @buffile = "/users/rocker/buf/lib/foo.txt"
16
+ @archivefile = "/users/rocker/buf/lib/foo.txt.archive"
17
+ end
18
+
19
+ desc "wr NOTE TIME", "appends note to buffile with the expiration time appended"
20
+ def wr(note, hours)
21
+ t = Time.now + 60 * 60 * hours.to_i
22
+ File.open(@buffile, "r") do |orig|
23
+ File.unlink(@buffile)
24
+ File.open(@buffile, "w") do |new|
25
+ new.write("#{note} #{t.strftime("%Y%m%d-%H%M%S")}")
26
+ new.write("\n")
27
+ new.write(orig.read)
28
+ end
29
+ end
30
+ end
31
+
32
+ desc "cull", "moves expired notes to archive file"
33
+ def cull
34
+ now = Time.now
35
+ buf = File.open(@buffile, "r")
36
+ temp = Tempfile.new("tempbaby")
37
+
38
+ buf.each do |line|
39
+ date = (line.split)[-1]
40
+ date = Time.new(date[0..3], date[4..5], date[6..7], date[9..10], date[11..12], date[13..14])
41
+ if ((date <=> now) == -1)
42
+ # write to archive
43
+ File.open(@archivefile, "r") do |origArch|
44
+ File.unlink(@archivefile)
45
+ File.open(@archivefile, "w") do |newArch|
46
+ newArch.write(line)
47
+ newArch.write(origArch.read)
48
+ end
49
+ end
50
+ else
51
+ temp << line
52
+ end
53
+ end
54
+ temp.close
55
+ FileUtils.mv(temp.path, @buffile)
56
+ end
57
+
58
+ desc "echo", "prints unexpired notes"
59
+ def echo
60
+ cull
61
+ now = Time.now
62
+ f = File.open(@buffile, "r")
63
+ count = 1
64
+ f.each do |line|
65
+ date = (line.split)[-1]
66
+ date = Time.new(date[0..3], date[4..5], date[6..7], date[9..10], date[11..12], date[13..14])
67
+ time_string = [60, 60, 24].inject([date - now]) { |m, o| m.unshift(m.shift.divmod(o)).flatten }
68
+ time_string = time_string[0..2].join(":")
69
+ puts "#{count}. #{(line.split)[0..-2].join(" ")} #{time_string}"
70
+ count+= 1
71
+ end
72
+ end
73
+ end
74
+
75
+ Buf.start(ARGV)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Douglas Lamb
@@ -12,10 +12,12 @@ date: 2015-04-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A dead simple short-term memory aid
14
14
  email: douglaslamb@douglaslamb.com
15
- executables: []
15
+ executables:
16
+ - buf
16
17
  extensions: []
17
18
  extra_rdoc_files: []
18
19
  files:
20
+ - bin/buf
19
21
  - lib/buf.rb
20
22
  homepage: https://github.com/douglaslamb/buf
21
23
  licenses:
@@ -40,5 +42,5 @@ rubyforge_project:
40
42
  rubygems_version: 2.4.5
41
43
  signing_key:
42
44
  specification_version: 4
43
- summary: fixing problem w initial gem release. it wouldn't run after gem install
45
+ summary: still fixing problem w initial gem release. it wouldn't run after gem install
44
46
  test_files: []