Skip to content

Instantly share code, notes, and snippets.

@vtypal
Last active December 27, 2015 19:09
Show Gist options
  • Save vtypal/7375445 to your computer and use it in GitHub Desktop.
Save vtypal/7375445 to your computer and use it in GitHub Desktop.
DATA stream example
#!/usr/bin/env ruby -w
require 'date'
pos = DATA.pos
cday=DateTime.now.strftime("%d")
ddata=DATA.readline.to_s
pday=ddata.split(";")[0]
if cday == pday
count = ddata.split(";")[1].to_i
count += 1
t_length = 5
def count_length(c_length)
return 1 if (c_length<10)
return 2 if (c_length<100)
return 3 if (c_length<1000)
return 4 if (c_length<10000)
return 5 if (c_length<100000)
end
puts "0"*(t_length - count_length(count)) + count.to_s
DATA.reopen(__FILE__, "a+")
DATA.truncate(pos)
DATA.seek(pos)
DATA.printf cday.to_s + ";" + count.to_s
else
puts "00001"
DATA.reopen(__FILE__, "a+")
DATA.truncate(pos)
DATA.seek(pos)
DATA.printf cday.to_s + ";" + "1"
end
#DATA.methods.sort.each do |m|
# print m, "\t"
#end
=begin
! != !~ << <=> == === =~ __id__ __send__ advise all? any? atime autoclose= autoclose? binmode binmode? bytes chars chmod chown chunk class clone close close_on_exec= close_on_exec? close_read close_write closed? codepoints collect collect_concat count ctime cycle define_singleton_method detect display drop drop_while dup each each_byte each_char each_codepoint each_cons each_entry each_line each_slice each_with_index each_with_object entries enum_for eof eof? eql? equal? extend external_encoding fcntl fdatasync fileno find find_all find_index first flat_map flock flush freeze frozen? fsync getbyte getc gets grep group_by hash include? inject inspect instance_eval instance_exec instance_of? instance_variable_defined? instance_variable_get instance_variable_set instance_variables internal_encoding ioctl is_a? isatty kind_of? lazy lineno lineno= lines lstat map max max_by member? method methods min min_by minmax minmax_by mtime nil? none? object_id one? partition path pid pos pos= print printf private_methods protected_methods public_method public_methods public_send putc puts read read_nonblock readbyte readchar readline readlines readpartial reduce reject remove_instance_variable reopen respond_to? reverse_each rewind seek select send set_encoding singleton_class singleton_methods size slice_before sort sort_by stat sync sync= sysread sysseek syswrite taint tainted? take take_while tap tell to_a to_enum to_i to_io to_path to_s truncate trust tty? ungetbyte ungetc untaint untrust untrusted? write write_nonblock zip
=end
__END__
08;24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment