Skip to content

Instantly share code, notes, and snippets.

@localhostdotdev
Created April 13, 2019 12:10
Show Gist options
  • Select an option

  • Save localhostdotdev/1dd72fd18197d161091c241c8afa11b9 to your computer and use it in GitHub Desktop.

Select an option

Save localhostdotdev/1dd72fd18197d161091c241c8afa11b9 to your computer and use it in GitHub Desktop.
using bigquery with ruby for free

using bigquery with ruby for free

main website asks for credit card, console/web ui just doesn't work.

.env:

BIGQUERY_PROJECT="everything-000000"
BIGQUERY_CREDENTIALS="secret/bigquery.json"
require "google/cloud/bigquery"
require "dotenv/load"

bigquery = Google::Cloud::Bigquery.new

results = bigquery.query(<<~QUERY)
  SELECT *
  FROM `bigquery-public-data.hacker_news.full`
  WHERE REGEXP_CONTAINS(text, '@ycombinator.com')
QUERY

EMAIL = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i

results.each do |row|
  puts row[:text].scan(EMAIL)
end

that's it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment