buf 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/buf.rb +71 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 241fe8ae2beacfd8939c211802b7edf0e2dc7538
|
4
|
+
data.tar.gz: c880890696b39ca55dc74af21269266ef4e6382a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8f14bf878c6388183eb3236a56c9f56bacb0f5965f8c17f935fc9f9bb7434448add5fbbc3a10bcbc2a340ca2be2134beef6a880cb9b42ec101bd9dd4f20dc13c
|
7
|
+
data.tar.gz: 0dfb429521d14236c61a62a0cd0662aec6c647a90f7867d3b62cdab4ee9dbad9e28d22023a55881951b9781eedc0f311083b1f21c6b97a7db13eeb8aaab8f66d
|
data/lib/buf.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'tempfile'
|
6
|
+
|
7
|
+
class Buf < Thor
|
8
|
+
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
@buffile = "/users/rocker/buf/lib/foo.txt"
|
12
|
+
@archivefile = "/users/rocker/buf/lib/foo.txt.archive"
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "wr NOTE TIME", "appends note to buffile with the expiration time appended"
|
16
|
+
def wr(note, hours)
|
17
|
+
t = Time.now + 60 * 60 * hours.to_i
|
18
|
+
File.open(@buffile, "r") do |orig|
|
19
|
+
File.unlink(@buffile)
|
20
|
+
File.open(@buffile, "w") do |new|
|
21
|
+
new.write("#{note} #{t.strftime("%Y%m%d-%H%M%S")}")
|
22
|
+
new.write("\n")
|
23
|
+
new.write(orig.read)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "cull", "moves expired notes to archive file"
|
29
|
+
def cull
|
30
|
+
now = Time.now
|
31
|
+
buf = File.open(@buffile, "r")
|
32
|
+
temp = Tempfile.new("tempbaby")
|
33
|
+
|
34
|
+
buf.each do |line|
|
35
|
+
date = (line.split)[-1]
|
36
|
+
date = Time.new(date[0..3], date[4..5], date[6..7], date[9..10], date[11..12], date[13..14])
|
37
|
+
if ((date <=> now) == -1)
|
38
|
+
# write to archive
|
39
|
+
File.open(@archivefile, "r") do |origArch|
|
40
|
+
File.unlink(@archivefile)
|
41
|
+
File.open(@archivefile, "w") do |newArch|
|
42
|
+
newArch.write(line)
|
43
|
+
newArch.write(origArch.read)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
else
|
47
|
+
temp << line
|
48
|
+
end
|
49
|
+
end
|
50
|
+
temp.close
|
51
|
+
FileUtils.mv(temp.path, @buffile)
|
52
|
+
end
|
53
|
+
|
54
|
+
desc "echo", "prints unexpired notes"
|
55
|
+
def echo
|
56
|
+
cull
|
57
|
+
now = Time.now
|
58
|
+
f = File.open(@buffile, "r")
|
59
|
+
count = 1
|
60
|
+
f.each do |line|
|
61
|
+
date = (line.split)[-1]
|
62
|
+
date = Time.new(date[0..3], date[4..5], date[6..7], date[9..10], date[11..12], date[13..14])
|
63
|
+
time_string = [60, 60, 24].inject([date - now]) { |m, o| m.unshift(m.shift.divmod(o)).flatten }
|
64
|
+
time_string = time_string[0..2].join(":")
|
65
|
+
puts "#{count}. #{(line.split)[0..-2].join(" ")} #{time_string}"
|
66
|
+
count+= 1
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
Buf.start(ARGV)
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: buf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Douglas Lamb
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-26 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A dead simple short-term memory aid
|
14
|
+
email: douglaslamb@douglaslamb.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/buf.rb
|
20
|
+
homepage: https://github.com/douglaslamb/buf
|
21
|
+
licenses:
|
22
|
+
- none
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.4.5
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: initial gem release
|
44
|
+
test_files: []
|