nerd_flirt 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b13a0334f3d8c5d830c8d4cb8ca66154ea5a911c
4
+ data.tar.gz: 01ae20101067274ab47492614f1283e7edf1e2b3
5
+ SHA512:
6
+ metadata.gz: bda2f5d732c892722fed0134b0839d28066457f485febba024b1e36bd0e376678c9357dcde503052213c29e8edd24ac8f85e70a71e30bb1e731759537464f0ee
7
+ data.tar.gz: 63c644f8ecc230d3b8691854ac9aa24866eeaba062479fd5b7157611b3142bf3c0e266cc6415a24cf8b7a67ae2a119aeb0a43e1d3e262aa419bde67f03b33c6a
@@ -0,0 +1,2 @@
1
+ SERVER_IP=your_chat_server_ip
2
+ SERVER_PORT=your_chat_server_port
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .env
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --no-profile
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nerd_flirt.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Eric Khoury
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ # NerdFlirt
2
+
3
+ A litte ruby chat gem. Having fun with sockets.
4
+
5
+ ## Installation
6
+
7
+ $ gem install nerd_flirt
8
+
9
+ ## Usage
10
+ Starting the server:
11
+ nerdflirt server <port>
12
+
13
+ Start chatting
14
+ nerflirt flirt <port>
15
+
16
+ ## Contributing
17
+
18
+ 1. Fork it ( https://github.com/[my-github-username]/nerd_flirt/fork )
19
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
20
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
21
+ 4. Push to the branch (`git push origin my-new-feature`)
22
+ 5. Create a new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |t|
5
+ t.rspec_opts = %w[--color]
6
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require "nerd_flirt/cli"
6
+
7
+ if ARGV[0] == "flirt"
8
+ host = ARGV[1]
9
+ port = ARGV[2]
10
+ CLI.run!(host, port)
11
+ elsif ARGV[0] == "server"
12
+ port = ARGV[1]
13
+ CLI.server(port)
14
+ end
@@ -0,0 +1,8 @@
1
+ require "nerd_flirt/version"
2
+ require "nerd_flirt/client"
3
+ require "nerd_flirt/server"
4
+ require "nerd_flirt/printer"
5
+ require "nerd_flirt/main"
6
+
7
+ module NerdFlirt
8
+ end
@@ -0,0 +1,22 @@
1
+ require 'thor'
2
+ require 'nerd_flirt/main.rb'
3
+ require 'nerd_flirt/server.rb'
4
+ require 'nerd_flirt/printer.rb'
5
+
6
+ class CLI < Thor
7
+
8
+ desc "server", "Starts NerdFlirt server"
9
+ def self.server(port)
10
+ puts "---------------------------------------------"
11
+ puts "• Starting NerdFlirt server on port #{port.to_s}"
12
+ NerdFlirt::Server.new(port)
13
+ end
14
+
15
+ desc "run!", "Starts NerdFlirt client"
16
+ def self.run!(host = '127.0.0.1', port = 8000)
17
+ puts "---------------------------------------------"
18
+ puts "NerdFlirt client connecting to #{host}:#{port}"
19
+ puts "---------------------------------------------"
20
+ NerdFlirt::Main.new.start
21
+ end
22
+ end
@@ -0,0 +1,64 @@
1
+ require 'socket'
2
+ class NerdFlirt::Client
3
+ attr_accessor :user
4
+
5
+ COMMANDS = %w[/exit /help]
6
+
7
+ def initialize(server, user_name)
8
+ @user = user
9
+ @server = server
10
+ @request = nil
11
+ @response = nil
12
+
13
+ @server.puts user_name
14
+
15
+ listen
16
+ send
17
+
18
+ @request.join
19
+ @response.join
20
+ end
21
+
22
+ def listen
23
+ @response = Thread.new do
24
+ loop {
25
+ msg = @server.gets.chomp
26
+ puts "#{msg}"
27
+ }
28
+ end
29
+ end
30
+
31
+ def send
32
+ @request = Thread.new do
33
+ loop {
34
+ print "> ".colorize(:magenta)
35
+ input = $stdin.gets.chomp
36
+
37
+ command = false
38
+ if COMMANDS.include?(input)
39
+ self.public_send(input)
40
+ command = true
41
+ end
42
+
43
+ @server.puts input unless command
44
+ }
45
+ end
46
+ end
47
+
48
+ def exit
49
+ puts "bye!"
50
+ exit
51
+ end
52
+
53
+ def help
54
+ # show help text
55
+ end
56
+
57
+ def server=(server)
58
+ @server = server
59
+ end
60
+
61
+ def server
62
+ @server
63
+ end
64
+ end
@@ -0,0 +1,98 @@
1
+ require 'nerd_flirt/user.rb'
2
+ require 'nerd_flirt/client.rb'
3
+
4
+ class NerdFlirt::Main
5
+ attr_accessor :user
6
+
7
+ def start
8
+ welcome
9
+ view_menu
10
+
11
+ if new_user?
12
+ new_user_prompt
13
+ end
14
+
15
+ find_match
16
+ input?
17
+ end
18
+
19
+ def welcome
20
+ system "clear" unless system "cls"
21
+ printer.banner
22
+ sleep 2
23
+ end
24
+
25
+ def new_user?
26
+ # check json file for user
27
+ true
28
+ end
29
+
30
+ def new_user_prompt
31
+ printer.four_breaks
32
+ printer.text "You will need to enter 4 lines of information for your nerd flirt: your gender, age, name and a opening question.", nil, true
33
+ puts "\n"
34
+ sleep 3
35
+ printer.line
36
+ printer.four_breaks
37
+
38
+ puts "Gender (m/f):"
39
+ print '> '
40
+ gender = $stdin.gets.chomp
41
+
42
+ puts "Name:"
43
+ print '> '
44
+ name = $stdin.gets.chomp
45
+
46
+ puts "Age:"
47
+ print '> '
48
+ age = $stdin.gets.chomp
49
+
50
+ puts "Now enter the first question you would like to ask your flirt."
51
+ print '> '
52
+ question = $stdin.gets.chomp
53
+
54
+ self.user = NerdFlirt::User.new name: name, gender: gender, age: age
55
+
56
+ printer.text "Smooth. Ok let's see what we got here, #{user.name}", :magenta
57
+ printer.loading_dots
58
+ puts "\n"
59
+ end
60
+
61
+ def find_match
62
+ printer.line
63
+ puts "\n"
64
+ print "\n"
65
+
66
+ server = TCPSocket.open('127.0.0.1', 8000) # ENV['SERVER_IP'], ENV['SERVER_PORT']
67
+ NerdFlirt::Client.new(server, user.name)
68
+
69
+ puts "\n"
70
+ printer.line
71
+
72
+ view_menu
73
+
74
+ puts "\n"
75
+ printer.line
76
+
77
+ puts "\n\n\n\n"
78
+ end
79
+
80
+ def view_menu
81
+ puts "\n"
82
+ puts 'Menu:'.colorize :magenta
83
+ printer.text '/new = find new flirt'
84
+ print "\n"
85
+ printer.text '/exit = quit application'
86
+ end
87
+
88
+ def input?
89
+ print '> '.colorize :yellow
90
+ input = $stdin.gets.chomp()
91
+
92
+ input?
93
+ end
94
+
95
+ def printer
96
+ @printer ||= NerdFlirt::Printer
97
+ end
98
+ end
@@ -0,0 +1,59 @@
1
+ require 'terminfo'
2
+ require 'colorize'
3
+
4
+ class NerdFlirt::Printer
5
+ def self.line
6
+ terminal_width.times do
7
+ print '-'.colorize(:light_blue)
8
+ sleep 0.01
9
+ end
10
+ end
11
+
12
+ def self.text(str, color = :white, center = false)
13
+ if center
14
+ ((terminal_width / 2) - (str.length / 2)).times { print ' '}
15
+ end
16
+
17
+ str.split.each do |word|
18
+ word.split("").each do |char|
19
+ print char.colorize( color )
20
+ sleep(0.01)
21
+ end
22
+ print " "
23
+ end
24
+ end
25
+
26
+ def self.banner
27
+ line
28
+ print "\n"
29
+
30
+ text("Welcome to Nerd♥Flirt", :magenta, true)
31
+ system 'say -v Vicki "Welcome, to nerd flirt."'
32
+
33
+ print "\n"
34
+ tag_line
35
+ #system 'say -v Vicki "sudo, find love"'
36
+
37
+ print "\n"
38
+ line
39
+ end
40
+
41
+ def self.four_breaks
42
+ print "\n\n\n\n"
43
+ end
44
+
45
+ def self.loading_dots
46
+ 10.times do |n|
47
+ print '.'
48
+ sleep 0.4
49
+ end
50
+ end
51
+
52
+ def self.tag_line
53
+ text "$ sudo find love", :white, true
54
+ end
55
+
56
+ def self.terminal_width
57
+ TermInfo.screen_size[1]
58
+ end
59
+ end
@@ -0,0 +1,59 @@
1
+ require 'socket'
2
+
3
+ class NerdFlirt::Server
4
+
5
+ def initialize(port)
6
+ @server = TCPServer.open(port || 8000)
7
+ @connections = {}
8
+ @rooms = {}
9
+ @clients = {}
10
+ @connections[:server] = @server
11
+ @connections[:rooms] = @rooms
12
+ @connections[:clients] = @clients
13
+
14
+ run
15
+ listen_user_messages
16
+ end
17
+
18
+ def run
19
+ loop {
20
+ Thread.start(@server.accept) do |client|
21
+ nick_name = client.gets.chomp.to_sym
22
+ @connections[:clients].each do |other_name, other_client|
23
+ if nick_name == other_name || client == other_client
24
+ client.puts "This username is currently taken."
25
+ client.puts "Please, try again!"
26
+ Thread.kill self
27
+ end
28
+ end
29
+
30
+ puts "#{nick_name} #{client}"
31
+ @connections[:clients][nick_name] = client
32
+ client.puts "You are connected, thank you for joining."
33
+ client.print '> '.colorize(:yellow)
34
+
35
+ listen_user_messages(nick_name, client)
36
+ end
37
+ }.join
38
+ end
39
+
40
+ def listen_user_messages(username, client)
41
+ loop {
42
+ msg = client.gets.chomp
43
+
44
+ if msg.split('/')[0] == 'delete'
45
+ clients.delete(msg.split('/')[1])
46
+ end
47
+
48
+ @connections[:clients].each do |other_name, other_client|
49
+ unless other_name == username
50
+ other_client.puts "#{username.to_s}: #{msg}"
51
+ end
52
+ end
53
+ }
54
+ end
55
+
56
+ def clients
57
+ @connections[:clients] ||= {}
58
+ end
59
+ end
@@ -0,0 +1,10 @@
1
+ require 'nerd_flirt.rb'
2
+
3
+ class NerdFlirt::User
4
+ attr_accessor :name, :age
5
+
6
+ def initialize(options)
7
+ @name = options[:name]
8
+ @age = options[:age]
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module NerdFlirt
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ system 'export COLUMNS'
5
+ require 'nerd_flirt/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "nerd_flirt"
9
+ spec.version = NerdFlirt::VERSION
10
+ spec.authors = ["Eric Khoury"]
11
+ spec.email = ["khoury@live.se"]
12
+ spec.summary = "Where sudo finds love."
13
+ spec.description = ""
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec", "~> 3.1"
25
+ spec.add_dependency 'ruby-terminfo', '~> 0.1.1'
26
+ spec.add_dependency "colorize"
27
+ spec.add_dependency "thor"
28
+ end
@@ -0,0 +1,10 @@
1
+ require 'nerd_flirt/client'
2
+
3
+ describe NerdFlirt::Client do
4
+ let(:client) { NerdFlirt::Client.new(name: "eric") }
5
+ subject { client }
6
+
7
+ it "has a user" do
8
+ expect(client.name).to eq("eric")
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ RSpec.configure do |config|
2
+ config.filter_run :focus
3
+ config.run_all_when_everything_filtered = true
4
+
5
+ config.expect_with :rspec do |expectations|
6
+ expectations.syntax = :expect
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nerd_flirt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Eric Khoury
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ruby-terminfo
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: colorize
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: thor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: ''
98
+ email:
99
+ - khoury@live.se
100
+ executables:
101
+ - nerdflirt
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".env.example"
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/nerdflirt
113
+ - lib/nerd_flirt.rb
114
+ - lib/nerd_flirt/cli.rb
115
+ - lib/nerd_flirt/client.rb
116
+ - lib/nerd_flirt/main.rb
117
+ - lib/nerd_flirt/printer.rb
118
+ - lib/nerd_flirt/server.rb
119
+ - lib/nerd_flirt/user.rb
120
+ - lib/nerd_flirt/version.rb
121
+ - nerd_flirt.gemspec
122
+ - spec/nerd_flirt_spec.rb
123
+ - spec/spec_helper.rb
124
+ homepage: ''
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.2.2
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Where sudo finds love.
148
+ test_files:
149
+ - spec/nerd_flirt_spec.rb
150
+ - spec/spec_helper.rb