Skip to content

Instantly share code, notes, and snippets.

View dankohn's full-sized avatar
☁️

Dan Kohn dankohn

☁️
View GitHub Profile
@dankohn
dankohn / circle.yml
Created July 16, 2014 16:47
Configuring CircleCI, Coveralls, and CodeClimate
## Customize test commands
test:
post:
- bundle exec rake coveralls:push
## Don't have CircleCI create coverage in an unexpected place, as coveralls wouldn't be able to find it.
general:
artifacts:
- "coverage"
def access_own_records
return if @user.super_administrator?
# Anyone can read or update anything they create
[Appointment, Claim, Referral, Study].each do |model|
can([:edit, :index, :read, :update], model,
model.where(created_id: @user.id)) do |instance|
instance.created_id == @user.id
end
end
end
@dankohn
dankohn / test_csv.js
Last active December 18, 2015 16:38
Parsing double-nested CSV fields
var csv = require('csv')
var cat = "Text"
var commaCat = "A, B, and C"
var cat2 = "More text"
csv()
.from.array([[cat,commaCat,cat2]])
.to.string( function(innerNest){
console.log(innerNest)
csv()
@dankohn
dankohn / k8s_contributors.sql
Last active February 26, 2017 02:45
K8s contributors
SELECT
actor.login as contributor,
COUNT(repo.name) AS commits,
FROM
[githubarchive:year.2016]
WHERE
type IN ("PushEvent") AND
repo.name = "kubernetes/kubernetes"
GROUP BY
contributor
@dankohn
dankohn / over_10_contributors.sql
Last active February 26, 2017 05:05
More than 10 contributors
SELECT
repo.name AS repository,
COUNT(repo.name) AS commits,
EXACT_COUNT_DISTINCT(actor.login) AS contributors
FROM
[githubarchive:year.2016]
WHERE
type IN ("PushEvent")
GROUP BY
repository
SELECT
repo.name,
ROUND(COUNT(*)/EXACT_COUNT_DISTINCT(actor.login),2) comments_per_author,
EXACT_COUNT_DISTINCT(actor.login ) authors,
COUNT(*) comments
FROM
[githubarchive:year.2016]
WHERE
type IN ('IssueCommentEvent')
AND actor.login NOT IN (
@dankohn
dankohn / by_commit.sql
Created February 26, 2017 06:06
By commit
SELECT
repo_name AS repository,
EXACT_COUNT_DISTINCT(author.name) AS authors,
EXACT_COUNT_DISTINCT(committer.name) AS committers,
COUNT(*) AS commits
FROM
[bigquery-public-data:github_repos.commits]
WHERE
committer.date >= TIMESTAMP("2016-01-01 00:00:00")
AND committer.date < TIMESTAMP("2017-01-01 00:00:00")
@dankohn
dankohn / project_commits.sql
Created February 26, 2017 06:32
Project commits
SELECT
repo_name AS repository,
EXACT_COUNT_DISTINCT(author.name) AS authors,
EXACT_COUNT_DISTINCT(committer.name) AS committers,
COUNT(*) AS commits
FROM
[bigquery-public-data:github_repos.commits]
WHERE
repo_name IN ( "torvalds/linux",
"facebook/react-native",
@dankohn
dankohn / commits_and_authors.sql
Created February 26, 2017 08:19
Commits and authors
SELECT
repo.name AS repository,
COUNT(repo.name) AS commits,
EXACT_COUNT_DISTINCT(actor.login) AS committers,
EXACT_COUNT_DISTINCT(JSON_EXTRACT(payload, '$.commits[0].author.email')) AS authors
FROM
[githubarchive:year.2016]
WHERE
type IN ("PushEvent")
GROUP BY
SELECT
repo.name AS repository,
COUNT(*) AS pull_requests,
EXACT_COUNT_DISTINCT(actor.login) AS contributors
FROM
[githubarchive:year.2016]
WHERE
type IN ( 'PullRequestEvent')
AND JSON_EXTRACT(payload, '$.action') IN ('"opened"')
GROUP BY