Skip to content

Instantly share code, notes, and snippets.

View cmorss's full-sized avatar

Charlie Morss cmorss

View GitHub Profile
@cmorss
cmorss / response.rb
Created August 16, 2016 23:04
Response.rb. Updated to include error subclass.
class Response
attr_accessor :data
delegate :[], :map, :select, :each, :first, :inject, to: :data
def initialize(data = nil)
self.data = data
end
def value
@cmorss
cmorss / daily_reviews_emails.html.haml
Created August 3, 2016 17:47
change to start date
- for id, app in @email[:app_reviews]
- reviews_link = "#{root_url}apps/#{id}/reviews?start_date=#{app[:start_date].to_s}&end_date=#{@email[:end_date].to_s}&#{ga_suffix}"
- store_name = app[:store].downcase == 'itunes' ? 'App Store' : 'Google Play'
@cmorss
cmorss / reviews_report.rb
Created August 3, 2016 17:46
Start_date changes
rails.logger.debug "[reviews report] building review data for app (#{app.id})"
token = make_jwt_token(user, app)
start_date = if user.last_review_email.present? && !env["force_emails"]
(user.last_review_email - 1.day).to_date
else
30.days.ago.to_date
end
start_date = [start_date, app.organization.active_entitlement.days_of_reviews_history.days.ago.to_date].max
@cmorss
cmorss / mongo-connect-production.log
Created July 15, 2016 16:22
Simple mongo query with connection issues then a very slow query.
MOPED: 127.0.0.1:27017 COMMAND database=admin command={:ismaster=>1} (0.3254ms)
MOPED: Could not connect to any node in replica set <Moped::Cluster nodes=[<Moped::Node resolved_address="127.0.0.1:27017">]>, refreshing list.
MOPED: 127.0.0.1:27017 COMMAND database=admin command={:ismaster=>1} (0.9255ms)
MOPED: 127.0.0.1:27017 COMMAND database=apptentive_production command={:count=>"survey_responses", :query=>{"deleted_at"=>nil, "survey_id"=>"572bdf52fd7381d6ee000004", "summary.572bdf52fd7381d6ee000008"=>{:$exists=>true}}} (555.3071ms)
=> 4838
@cmorss
cmorss / response_summary.rb
Created July 14, 2016 16:40
Create answer summaries on survey responses
Mongoid.default_session["survey_responses"].find.each_with_index do |response, index|
summary = {}
other_text_summary = {}
(response["answers"] || []).each do |answer|
if answer["_type"] == "Survey::Answers::Multiselect"
choices = (answer["selections"] || []).map { |s| s && s["answer_choice_id"] && s["answer_choice_id"].to_s }
summary[answer["question_id"].to_s] = choices if choices.present?
other = (answer["selections"] || []).detect { |s| s && s["text"].present? }
def from_rack(env_hash)
req = ::Rack::Request.new(env_hash)
self.url = req.scheme && req.url.split('?').first
self.method = req.request_method
self.query_string = req.query_string
self.data = read_data_from(req)
self.headers = format_headers_for_sentry(env_hash)
self.env = format_env_for_sentry(env_hash)
@cmorss
cmorss / moods.rb
Created April 4, 2014 16:46
Top Genres and Moods for an Artist
def artist_stats ids
Artist.find(ids).each do |artist|
puts artist.name
tracks = artist.tracks.active
puts "tracks : #{tracks.count}"
puts "streams : #{tracks.map {|t| Track.hits[t.id]}.sum}"
downloads = Filing.joins(:folder).where("filings.track_id in (?) and folders.name = 'Downloads'", tracks.map(&:id)).count
puts "downloads : #{downloads}"
@cmorss
cmorss / example.markdown
Created September 12, 2013 14:51
Updated JSON
{
  "id"                   : (integer, read only),
  "lid"                  : (string, read only),
  "custom_id"            : (string, optional),
  "state"                : (string, optional),

  "trusted_platforms"    : (array of integers, optional),
  "restricted_encrypted" : (boolean, optional),
  "trusted_only"         : (boolean, optional),
%button {
color: red;
font-size: 14px;
}
%button-big {
font-size: 18px;
}
identify: (options = {}) =>
callback = options.callback
delete options.callback
attrs = _.extend options, "Account": App.name
if App.params.utm_campaign
attrs["Campaign Type"] = App.params.utm_medium
attrs["Campaign"] = App.params.utm_campaign