This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -- размер таблицы |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |