Agile Zone is brought to you in partnership with:
DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
  • submit to reddit
George Dinwiddie03/04/14
3447 views
0 replies

Getting so much better all the time!

Agile software development is not about productivity; it’s about working well. Yes, I think there are potential gains in productivity for most teams. Even then, the bulk of the gains are from “maximizing the work not done” rather than becoming more efficient programmers.

#!/usr/bin/env ruby
require 'koala' # gem install koala --no-ri --no-rdoc

# create a facebook app and get access token from here
# https://developers.facebook.com/tools/explorer
# select "groups", "photos" when authenticating
oauth_access_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
group_filtering_words = ['ruby']
image_path = 'image.png' #change to your image path
message = 'My Cool image.' # your message

graph = Koala::Facebook::API.new(oauth_access_token)

# getting groups of interest
groups = graph.get_connections("me", "groups").select do |group|
	group_filtering_words.any? do |word|
		group["name"].downcase.include? word
	end
end

index = 0
groups.each do |group|
	index += 1
	puts "[#{index}/#{groups.size}] Posting to group #{group["name"]}."
	graph.put_picture(
		image_path, 
		{:message => message}, 
		group['id']
	)
end
Edmund Kirwan03/03/14
3775 views
0 replies

Dependency inversion: the structure logarithm.

Old crotchety principles sometimes surprise. The dependency inversion principle has long earned respect from programmers for its prowess at smashing the rigidity and fragility of otherwise un-lubricated systems.

Alec Noller03/03/14
18819 views
2 replies

Introducing DZone's 2014 Cloud Platform Research Report

Here at DZone, we are dedicated to providing our community with the knowledge needed to understand the latest technologies and trends and make the best decisions. That’s why we are excited to announce the release of our biggest research undertaking to date: DZone’s 2014 Cloud Platform Research Report.

Nikita Salnikov...03/03/14
5304 views
0 replies

Allocating memory for the JVM: a case study

This post is about a recent performance tuning exercise. A closer look to the application revealed it consisting of several batch jobs bundled together. The troubled application was a pretty innocent-looking small JAR file. Which, to my luck also bundled the load tests.

Rob Galanakis03/03/14
4644 views
0 replies

Being amazed by software development

I am continually amazed by the state of software development. I am amazed at how broken things seem to be, and I’m amazed at what powerful tools we have to fix things.

Tribhuwan Negi03/03/14
1511 views
0 replies

Don't Get Lost in Agile Ceremonies

Create and manage continuous improvements teams and communities within organization to fuel your agile initiatives.

#!/usr/bin/env ruby
require 'cinch' # gem install cinch --no-ri --no-rdoc
require 'askwiki' # gem install askwiki --no-ri --no-rdoc

bot = Cinch::Bot.new do
  configure do |c|

    c.server = "irc.freenode.org"
    c.nick = "Ask_wikipedia"
    c.channels = ["#cinch-bots"]
    
  end

  on :message do |m|
  	if m.message.start_with? 'askwiki'
  		query = m.message.gsub('askwiki','').strip
    	m.reply Askwiki.ask(query), true
	end
  end
end

bot.start
require 'sinatra' # gem install sinatra --no-rdoc --no-ri
set :port, 3000
set :environment, :production

html = <<-EOT
<html><head><style>
#text{width:100%; font-size: 15px; padding: 5px; display: block;}
</style></head><body>
	<input id="text" placeholder="Write then press Enter."/>
	<div id="chat"></div>
	<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
	<script>
	$('#text').keypress(function(e){
		if( e.keyCode==13 ){
			$.get('/send',{text:$('#text').val()});
			$('#text').val('');
		}
	});
	last = 0;
	setInterval(function(){
		$.get('/update',{last:last},
			function(response){
				last = $('<p>').html(response).find('span').data('last');
				$('#chat').append(response);
				});
		},1000);
	</script>
</body></html>
EOT

chat = ['welcome..']
get('/') { html }
get '/send' do
	chat << "#{request.ip} : #{params['text']}"
	nil
end
get '/update' do
	updates = chat[params['last'].to_i..-1]
	last = "<span data-last=\"#{chat.size}\"></span>"
	if updates.size>0
	updates.join('</br>') + "#{last}</br>"
	else
		last
	end
end
require 'sinatra' # gem install sinatra --no-ri --no-rdoc
set :port, 3000
html = <<-EOT
<html><head><style>
#regex,#text{ width:100%; font-size:15px; display:block; margin-bottom:5px; }
#text{ height: 200px; }
span{ background:rgb(230,191,161); display:inline-block; border-radius:3px;}
</style></head><body>

	<input id="regex" placeholder="Regex"/>
	<textarea id="text" placeholder="Text"></textarea>
	<div id="result"></div>

	<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
	<script>
	$('#regex,#text').keyup(function(){
			$.get('/preview',{
				reg:$('#regex').val(),
				text:$('#text').val()
			},function(r){
				$('#result').html(r);
			});
	});
	</script>

</body></html>
EOT

get('/'){ html }
get '/preview' do 
	begin
		params['text'].gsub(/(#{params['reg']})/,'<span>\1</span>')
	rescue
		'Your regex is invalid'
	end
end
#!/usr/bin/env ruby
require 'Twitter'
# Create a read write application from : 
# https://apps.twitter.com
# authenticate it for your account
# fill in the following
config = {consumer_key:        '',  consumer_secret:     '',
          access_token:        '',  access_token_secret: ''}
me = 'Blaze Boy' # to prevent DM yourself

Thread.new do
  loop do
    begin
      
      rClient = Twitter::REST::Client.new config
      sClient = Twitter::Streaming::Client.new(config)
      sClient.user do |object|
        if object.is_a? Twitter::Streaming::Event and object.name==:follow
          user = object.source
          if user.name != me
            rClient.create_direct_message user, "Thanks for following me #{user.name} :)"
            puts "New follower : #{object.source.name}"
          end
        end
      end

    rescue
      puts 'error occurred, sleeping for 5 seconds'
      sleep 5
    end
  end
end

loop { sleep 5 }
directory = ARGV.shift || Dir.pwd
$dont_get_into = ['.','..']
$allowed = {
			'Ruby' => '.rb', 
			'Ruby HTML Templates' => '.html.erb',
			'YAML' => '.yml',
			'RDoc' => '.rdoc',
			'HTML' => '.html',
			'Javascript' => '.js',
			'CSS' => '.css',
			'Sass' => '.scss',
			'CofeeScript' => '.coffee'
			}
$analytics = {}
def analyze(dir)
	Dir.new(dir).each do |file_name|
		
		if (! $dont_get_into.include? file_name) and 
			File.directory? dir + File::SEPARATOR + file_name 
				analyze dir + File::SEPARATOR + file_name 
		end

		$allowed.each do |file, extension|
			if file_name.end_with? extension
				$analytics[file] ||= 0
				$analytics[file] += 1
				break
			end
		end

	end
end
analyze directory
puts 'No files found that matches your creteria.' if $analytics.empty?
puts $analytics.map { |k,v| "#{k} : #{v} Files"  }.join "\n"
require 'open-uri'
require 'json'

language = 'en'

print 'What do you need to know? : '
article = URI::encode gets.chomp

request_url = "http://#{language}.wikipedia.org/w/api.php?action=parse&page=#{article}&format=json&prop=text§ion=0"

open(request_url) do |file|
  content = JSON.parse(file.read())['parse']['text'].first[1]
  content_text = content.gsub(/<\/?[^>]+>/, '')
  content_text = content_text.gsub(/[[:space:]]+/, ' ')
  content_text = content_text.gsub(/&#[0-9]+;/,'')
  content_text = content_text.gsub(/\[[0-9]+\]/,'')
  puts content_text
end
require 'time'

Date_of_birth = '1988-8-31'

# Credit to : http://stackoverflow.com/questions/4136248/how-to-generate-a-human-readable-time-range-using-ruby-on-rails
# and modified a little bit
def humanize secs
  [	
  	[60, :seconds], 
  	[60, :minutes], 
  	[24, :hours], 
  	[365, :days], 
  	[100, :years]
  ].map do |count, name|
    if secs > 0
      secs, n = secs.divmod(count)
      "#{n.to_i} #{name}"
    end
  end.compact.reverse.join(' ')
end

loop do
	distance = Time.new - Time.parse(Date_of_birth)
	print humanize(distance)+"\r"
	sleep 1
end
require 'Twitter' #gem install twitter
while true
	begin
		# Create a read write application from : 
		# https://apps.twitter.com
		# authenticate it for your account
		# fill in the following
		config = {
			consumer_key:        '',
			consumer_secret:     '',
			access_token:        '',
			access_token_secret: ''
		}
		rClient = Twitter::REST::Client.new config
		sClient = Twitter::Streaming::Client.new(config)

		# topics to watch
		topics = ['#rails', '#ruby', '#coding', '#codepen']
		sClient.filter(:track => topics.join(',')) do |tweet|
			if tweet.is_a?(Twitter::Tweet)
			  puts tweet.text 
			  rClient.fav tweet
			end
		end
	rescue
		puts 'error occurred, waiting for 5 seconds'
		sleep 5
	end

end
require 'socket'
require 'base64'

Refresh = 1 # seconds to refresh image on server
screen_capture_command = 'screencapture -C -x tmp.png'
image = ''
latest = Time.now
server = TCPServer.new 3000

loop do
  Thread.start(server.accept) do |client|
	if Time.now-latest>=Refresh
		system(screen_capture_command)
		latest = Time.now
		File.open('tmp.png', 'rb') do |file| 
			image = 'data:image/png;base64,'+Base64.encode64(file.read) 
		end
	end
  	client.puts '<html><head>'+
				"<script>setTimeout(function(){document.location.reload();},#{Refresh*1000});</script>"+
				'</head><body style="padding:0px;margin:0px;">'+
				"<img src=\"#{image}\" style=\"height:100%;\"/>"+
				'</body></html>'
    client.close
  end
end
class Integer
	def to_a
		arr = []
		tmp = self
		while tmp>0
			arr << tmp%10
			tmp /= 10
		end
		arr.reverse
	end
end

# usage
print 32455.to_a
print 433456.to_a
print 345434.to_a.sort
print 344543.to_a.join '-'
class Array
	def same?
		uniq.length==1
	end
end

x = 1
y = 2
z = 2
l = 2

# old way : x==y and y==z
puts [x,y,z].same? # false
# old way : y==z and z==l
puts [y,z,l].same? # true
require 'webrick'
 
Port = 3000
Directory = Dir::pwd

WEBrick::HTTPServer.new(
	Port: Port,
	DocumentRoot: Directory
).start
require 'open-uri'
require 'json'
require 'psych'

city = 'portsaid,egypt'
request = "http://api.openweathermap.org/data/2.5/weather?q=#{city}"
response = open(request).readlines.join
print Psych.dump( JSON.parse(response) )