Skip to content

Instantly share code, notes, and snippets.

# Add to Gemfile
gem 'google-analytics-data', require: 'google/analytics/data'
-------------------------------------------------------------
# /path/to/google_analytics/report.rb
module GoogleAnalytics
class Report
DEFAULT_PROPERTY_ID = 'default-property-id' # store in Rails secrets or ENV variable
attr_reader :metrics
attr_reader :property_id
$ gem install google-analytics-data
-----------------------------------
require 'google/analytics/data'
# METHOD FOR EXTRACTING VIEWS FROM REPORT
def extract_page_views(report)
report.rows.each_with_object({}) do |row, memo|
page_path = row.dimension_values.first.value
memo[page_path] = row.metric_values.first.value.to_i
SELECT
pid,
now() - pg_stat_activity.query_start AS duration,
query,
state
FROM pg_stat_activity
WHERE (now() - pg_stat_activity.query_start) > interval '5 minutes';
SELECT
idstat.relname AS TABLE_NAME, -- имя таблицы
indexrelname AS index_name, -- индекс
idstat.idx_scan AS index_scans_count, -- число сканирований по этому индексу
pg_size_pretty(pg_relation_size(indexrelid)) AS index_size, -- размер индекса
tabstat.idx_scan AS table_reads_index_count, -- индексных чтений по таблице
tabstat.seq_scan AS table_reads_seq_count, -- последовательных чтений по таблице
tabstat.seq_scan + tabstat.idx_scan AS table_reads_count, -- чтений по таблице
n_tup_upd + n_tup_ins + n_tup_del AS table_writes_count, -- операций записи
pg_size_pretty(pg_relation_size(idstat.relid)) AS table_size -- размер таблицы
@unavailabl3
unavailabl3 / aws_sdk_ruby_s3_upload_file
Last active February 8, 2019 14:57
AWS S3 upload file with Ruby/Rails
Using gem aws-sdk for a ror application for uploading images to s3
Uploading images to a fixed bucket with different folders for each object or application.
The s3 keeps a limitation on the number of buckets creattion whereas there is no
limitation for content inside a bucket.
This code will upload image for a user to s3 using aws-sdk gem. The bucket and the image uploaded are made public
so that the images uploaded are directly accessible
Method for aws-sdk v3