Skip to content

Instantly share code, notes, and snippets.

View StephenOTT's full-sized avatar
:shipit:
...

Stephen Russett StephenOTT

:shipit:
...
View GitHub Profile
@StephenOTT
StephenOTT / Determine Missing Months between Two Dates - Ruby
Last active December 23, 2015 14:09
Ruby Method for getting the Dates/months (this version is designed for getting months/First day of each month, and then parse out day later) between two dates. Example: Provide Date A and Date B and get month and Year(s) between two dates. Does not return Date A and Date B, only the dates between those dates. See: https://github.com/StephenOTT/a…
def addMissingMonths (datesHash)
count = 0
datesHash.keys.each do |x|
result = []
if x != datesHash.keys.last
(x+1.month).upto(datesHash.keys[count+1]-1.month) do |a|
# result << [a.month,a.year]
result << [a.at_beginning_of_month]
end
@StephenOTT
StephenOTT / GChart Literal Object Code Gen.rb
Last active December 26, 2015 17:49
Ruby code for generating Google Chart JS Literal Objects. Comes with sample code at bottom.
require 'json'
class GenerateGDataTable
def initialize
@columnArray = []
@rowArray = []
end
@StephenOTT
StephenOTT / octokit date issue.rb
Created December 16, 2013 22:53
Code sample showing GitHub API issue with the Code Commits Octokit.rb Octokit.commits() returned date fields
require 'octokit'
commits = Octokit.commits("StephenOTT/Test1")
commitComments = Octokit.commit_comments("StephenOTT/Test1", "b08156d2327b47c5bfb2543b224cd6aee726add5")
commits.each do |x|
puts x.attrs[:commit].attrs[:author].attrs[:date]
end
@StephenOTT
StephenOTT / task lists.rb
Last active January 1, 2016 02:19
Get Tasks from a GitHub Issue Body or Comment using RegEx to parse issue body or issue comment for a task.
def get_comment_tasks (commentBody, taskStatus = :incomplete)
tasks = []
startStringOpen = /\-\s\[\s\]\s/
startStringClosed = /\-\s\[x\]\s/
endString = /[\r\n]|\z/
if taskStatus == :incomplete
tasksInBody = commentBody.scan(/#{startStringOpen}(.*?)#{endString}/)
@StephenOTT
StephenOTT / Time Tracking Reporting options.md
Last active August 29, 2015 13:57
Time Tracking Reporting Options for GitHub Time Tracking
  • Get all Issues Time

  • Get all Issues Budget Get all issues Time and Budget (meta report that merges output from two previous reports)

  • Get a Issue Time

  • Get a Issue Budget Get a Issue Time and Budget (meta report that merges output from two previous reports)

  • Get all Issues Time for a Milestone

  • Get all Issues Budget for a Milestone

@StephenOTT
StephenOTT / GitHub Search Repo Parameter Limit.rb
Last active August 29, 2015 13:57
Determine what the Max number of Repo parameters that GitHub Search API supports
require 'octokit'
require 'pp'
class GHSearchTest
def gh_authenticate(username, password)
@ghClient = Octokit::Client.new(
:login => username.to_s,
:password => password.to_s,
@StephenOTT
StephenOTT / Missing Dates.rb
Created April 18, 2014 07:48
Find Missing Dates between a Date Range
a = []
output.each do |x|
a << x["converted_date"]
end
b = (output.first["converted_date"]..output.last["converted_date"]).to_a
zeroValueDates = (b.map{ |date| date.strftime("%b %Y") } - a.map{ |date| date.strftime("%b %Y") }).uniq
zeroValueDates.each do |zvd|
zvd = DateTime.parse(zvd)
output << {"repo"=> repo , "state"=>"closed", "closed_year"=>zvd.strftime("%Y").to_i, "closed_month"=>zvd.strftime("%m").to_i, "count"=>0, "converted_date"=>zvd}
@StephenOTT
StephenOTT / time_difference.rb
Created May 1, 2014 23:54
Example of using Chronic gem and TimeDifference gem to get the duration between two statements
require 'chronic'
require 'time_difference'
humanStatement1 = "this tuesday 1pm"
humanStatement2 = "this tuesday 3pm"
humanStatement1Parsed = Chronic.parse(humanStatement1)
humanStatement2Parsed = Chronic.parse(humanStatement2)
@StephenOTT
StephenOTT / qless zscan.rb
Created May 8, 2014 05:33
Ruby Redis example of using ZSCAN and ZSCAN Match to get a specific DateTime for a Job ID in a QLess scheduled job
require "redis"
redis = Redis.new
puts redis.zscan("ql:q:testing-scheduled", 5, {match: "7f81bbe64bcd4599b565c95c817cf363"})
@StephenOTT
StephenOTT / date_conversion.rb
Created March 26, 2015 05:10
Date Conversion for MongoDB
Here is a way to deal with this issue:
def convertIssueDatesInMongo (issues)
issues.each do |y|
y["created_at"] = DateTime.strptime(y["created_at"], '%Y-%m-%dT%H:%M:%S%z').to_time.utc
y["updated_at"] = DateTime.strptime(y["updated_at"], '%Y-%m-%dT%H:%M:%S%z').to_time.utc
end
return issues
end