Skip to content

Instantly share code, notes, and snippets.

View criess's full-sized avatar

Christoph Rieß criess

  • Carl Finance
  • Berlin
View GitHub Profile
# - all user*
# - all contract*
# - all discounts
# - all credit_memos
# - all product*
# - all subscriptions
# - all invoice*
# - all agent*
# - without any agent_result*
# - all social_media_trackers
puts(
((0..9).to_a + %w[a b c d e f]).in_groups_of(4).map do |g|
AnalyticsEvent.where(context_scope: :SellingProfile).where('context_id::varchar LIKE ? OR context_id::varchar LIKE ? OR context_id::varchar LIKE ? OR context_id::varchar LIKE ?', "#{g[0]}%", "#{g[1]}%", "#{g[2]}%", "#{g[3]}%").group(:context_id).pluck(:context_id, Arel.sql('ARRAY_AGG(ARRAY[session_id::varchar,user_id::varchar])')).map do |k|
calced = Time.now
uniq_sessions = k[1].map(&:first).uniq.size
uniq_users = k[1].map(&:last).uniq.size
[uniq_sessions, "::OUT:: selling profile #{k[0]} with uniq sessions #{uniq_sessions} and uniq users #{uniq_users} (in #{'%.4f' % ((Time.now - calced) * 1000)} ms)"]
end
#!/usr/bin/env ruby
#
# reads filenames from stdin and renames them according to contained
# exif data
#
require 'time'
require 'yaml'
require 'fileutils'
#!/bin/bash
##
# needs these env:
# FILENAME_PREFIX: prefix on basename of file to iterate over
# DBNAME: psql database name on local machine (or uri)
# default: 40
KEEP_BACKUPS=${KEEP_BACKUPS:-40}
#!/bin/bash
##
# uses this env:
# REMOTE_BUCKET: gcs bucket adress prefix (can include foldername)
# FILENAME_PREFIX: Filename prefix (prefix on basename)
LOCAL_LS="$(tempfile)"
REMOTE_LS="$(tempfile)"
gsutil ls "$REMOTE_BUCKET$FILENAME_PREFIX*" | cut -d "/" -f5 > "$REMOTE_LS"
if RUBY_PLATFORM =~ /darwin/ && !File.exists?(RbConfig::CONFIG["rubyarchhdrdir"])
RbConfig::CONFIG["rubyarchhdrdir"].sub!(RUBY_PLATFORM.split('-').last, Dir.entries(File.dirname(RbConfig::CONFIG["rubyarchhdrdir"])).reject{|d|d.start_with?(".","ruby")}.first.split('-').last)
end
RbConfig::CONFIG["rubyhdrdir"].gsub!(/^/, '/app/ruby')
RbConfig::CONFIG["rubyarchhdrdir"].gsub!(/^/, '/app/ruby')
RbConfig::CONFIG["archlibdir"].gsub!(/^/, '/app/ruby')
require 'mkmf'
FROM debian:bullseye
RUN apt-get update &&\
apt-get -y install curl gnupg
RUN curl -s "https://www.postgresql.org/media/keys/ACCC4CF8.asc" | apt-key add - &&\
echo "deb http://apt.postgresql.org/pub/repos/apt/ bullseye-pgdg main" > /etc/apt/sources.list.d/pgdg.list &&\
apt-get update &&\
apt-get install -y postgresql-client-13 libpq-dev
require 'csv'
require 'net/http'
require 'optparse'
require 'securerandom'
##
# example csv:
# ```
# email;gender;lastname;firstname;role
# you@andme.com;other;Some;Name;admin
force_delete = ARGV.find { |x| x == '--force-delete' }
from_date = Date.new(2021,4,1)
filter_item_type = 'BuyingProfile'
def lookup_lli(event)
LongListItem.find(event.context_id)
end
AnalyticsEvent.where(context_scope: :LongListItem)
@criess
criess / rails_rubocop_include_analyzer.rb
Created May 5, 2021 08:23
analyzes includes between two folders on a rails application
#!/usr/bin/env ruby
#
# script can be run from rails runner like so:
# rails r this_file.rb -- <including_directory_path> <included_directory_path>
#
# for example on a rails concerns setup: rails r thisfile.rb -- app/models app/models/concerns
#
# rubocop is required to parse the code
#