Skip to content

Instantly share code, notes, and snippets.

View karlosmid's full-sized avatar

Karlo Smid karlosmid

View GitHub Profile
@karlosmid
karlosmid / email_exchange.rb
Created February 8, 2014 14:48
Connect to Microsoft Exchange specific folder using viewpoint gem. You can use owsap proxy if needed.
require 'viewpoint'
class EmailExchange
attr_accessor :folder_name
def initialize username, password, ews_endpoint, exchange_folder_name, proxy
if not (proxy.nil? or proxy.empty?)
Viewpoint::EWS::EWS.set_trust_ca './owasp_zap_root_ca.pem'
end
Viewpoint::EWS::EWS.endpoint = ews_endpoint
Viewpoint::EWS::EWS.set_auth username,password
@karlosmid
karlosmid / gist:a0d4923cd0cb34cbd795
Last active August 29, 2015 14:03
Tentamen git workflow

Note: please use git manual to get to know what each git command is actually doing. Divide feature on which you are working in short working deliverables. That means when you are done with your implementation and unit testing, you can merge to master branch and delete your small feature branch.

Clone repository (repository will be called repo furthermore in this wiki.)

mkdir ~/repos
cd repos
git clone git_repository
cd git_repository

@karlosmid
karlosmid / email_pop3.rb
Last active August 29, 2015 14:05
Check email using pop3 protocol.
require 'net/pop'
include Helpers
class EmailPop
attr_accessor :pop
def initialize
end
def create
self.pop = Net::POP3.new app['pop3.server'], app['pop3.port']
self.pop.enable_ssl
@karlosmid
karlosmid / us_week_number.rb
Last active August 29, 2015 14:08
US week number implementation in IronRuby
def us_week_number us_date
date_time_formatinfo_in_dot_net = System::Globalization::DateTimeFormatInfo.new
date_time_formatinfo_in_dot_net.CalendarWeekRule = System::Globalization::CalendarWeekRule.FirstFullWeek
my_calendar = date_time_formatinfo_in_dot_net.Calendar
us_date_dot_net_instance = System::DateTime.parse(us_date.strftime('%Y/%m/%d'))
my_calendar.GetWeekOfYear(us_date_dot_net_instance,date_time_formatinfo_in_dot_net.CalendarWeekRule,date_time_formatinfo_in_dot_net.FirstDayOfWeek)
end
@karlosmid
karlosmid / us_week_number_spec.rb
Last active August 29, 2015 14:08
specification file for us week number
describe "us week number" do
it { expect(us_week_number(Date.parse('20110101'))).to eq 52 }
it { expect(us_week_number(Date.parse('20100101'))).to eq 52 }
it { expect(us_week_number(Date.parse('20091231'))).to eq 52 }
it { expect(us_week_number(Date.parse('20110102'))).to eq 1 }
it { expect(us_week_number(Date.parse('20110102'))).not_to eq Date.parse('20110102').cweek }
end
Failure/Error: from_date = Date.strptime(row['RollingPeriodStart'].to_s.split(' ')[0],'%m/%d/%Y')
TypeError:
can't dup NilClass
# C:/IronRuby1.1/Lib/ruby/1.9.1/date/format.rb:575:in `dup'
# C:/IronRuby1.1/Lib/ruby/1.9.1/date/format.rb:575:in `_strptime'
# C:/IronRuby1.1/Lib/ruby/1.9.1/date.rb:1045:in `strptime'
@karlosmid
karlosmid / wrong_recordset_logic.rb
Created January 18, 2015 20:29
wrong recordset logic
actual.each_with_index { |record,index|
expect(expected[index]).to eq(record)
}
@karlosmid
karlosmid / ok_recordset_logic.rb
Created January 18, 2015 20:32
proper recordset logic
expected.each_with_index { |record,index|
expect(record).to eq(actual[index])
}
@karlosmid
karlosmid / us_week_number.rb
Created January 31, 2015 17:23
us week number in pure ruby
def us_week_number us_date
week = Time.local(us_date.year,us_date.month,us_date.day).strftime("%U").to_i
if week == 0
Time.local(us_date.year - 1,12,31).strftime("%U").to_i
else
week
end
end
@karlosmid
karlosmid / cucumber_embed_screenshot_base64.rb
Created February 13, 2015 12:39
How to embed screenshot in Cucumber report across various environments
After do |scenario|
if scenario.failed?
encoded_img = @browser.screenshot.base64
embed("data:image/png;base64,#{encoded_img}",'image/png')
end
@browser.close
Cucumber.wants_to_quit = true if scenario.failed?
end