Skip to content

Instantly share code, notes, and snippets.

@ghostandthemachine
Created October 6, 2010 15:25
Show Gist options
  • Save ghostandthemachine/613516 to your computer and use it in GitHub Desktop.
Save ghostandthemachine/613516 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
class Utilities
@@cycle = nil
def self.cycle(a,b)
@@cycle == a ? @@cycle = b : @@cycle = a
end
end
start = Time.now
class Student
attr_accessor :user_name, :password, :uid, :gid, :gcos_field, :directory, :shell, :first_name, :last_name
@@count = 0
def initialize(user_name, password, uid, gid, gcos_field, directory, shell)
@@count = defined?(@@count) ? @@count + 1 : 1
@user_name = user_name
@password = password
@uid = uid
@gid = gid
@gcos_field = gcos_field
@directory = directory
@shell = shell
end
def self.count
@@count
end
end
class String
def alternate_case
# alternate upper and lower case characters
count = 0
out = ''
self.scan(/./m) do |b|
if count == 0
out << b.upcase && count = 1
else
out << b.downcase && count = 0
end
end
out
end
end
require 'set'
class_names = Set.new
pass_map = {}
class_map = {}
students = []
group_lines = File.readlines("/etc/group")
passwd_lines = File.readlines("/etc/passwd")
group_lines.each do |elem|
lines = elem.split(' ')
lines.each do |line|
crn = line[1,6]
if(crn.eql? "c79363")
trimmed_line = line.slice(14, line.length - 18) #trim the fat off the beginning and end of the line
trimmed_line.split(':') #split to get just the user names
names = trimmed_line.split(',') #split those names apart
names.each do |name|
class_names.add(name)
end
end
end
end
pass_lines = passwd_lines[0].split(',')
pass_lines.each do |elem|
student_info = elem.split(':')
unless(student_info[0].nil?)
t_name = student_info[0].split('"')
tkey = student_info[0]
key = tkey.split('"')
key_string = key[1]
val = "I".slice(0) # value of I character
if(class_names.member?(key_string))
student = Student.new(key_string, student_info[1], student_info[2], student_info[3], student_info[4].split(' '), student_info[5], student_info[6])
students.push(student)
@@first = student.gcos_field[0]
@@last = student.gcos_field[student.gcos_field.length - 1]
if(@@last.downcase.slice(0) > val)
@@first = @@first.alternate_case
@@last = @@last.alternate_case
end
if(@@last.slice(0) < val)
@@first = @@first.upcase
@@last = @@last.upcase
end
def student.first_name
@@first
end
def student.last_name
@@last
end
def student.last_name
student.gcos_field[student.gcos_field.length - 1]
end
end
end
end
#puts "<table>"
#students.each do |student|
#puts "<tr><td>#{student.user_name}</td><td>#{student.password}</td>....<td>#{student.shell}</td></tr>
#{}</table>"
#end
#puts "</table>"
finish = Time.now
ellapsed = (finish.to_f - start.to_f).to_s
#this is just trying to get html to do anything at all
print "HTTP/1.0 200 OK\r\n"
print "Content-type: text/html\r\n\r\n"
print "<html><body>#{ellapsed}</body></html>\r\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment