Skip to content

Instantly share code, notes, and snippets.

View azelenets's full-sized avatar
:octocat:
Impossible is nothing

Andrii Zelenets azelenets

:octocat:
Impossible is nothing
View GitHub Profile
@azelenets
azelenets / directory_upload.rb
Created January 15, 2016 20:48 — forked from milesmatthias/directory_upload.rb
S3 directory upload in ruby. Switched http://avi.io/blog/2013/12/03/upload-folder-to-s3-recursively to use the official aws ruby sdk.
#!/usr/bin/env ruby
require 'rubygems'
require 'aws-sdk'
class S3FolderUpload
attr_reader :folder_path, :total_files, :s3_bucket
attr_accessor :files
## IMAGES
Add a gem https://github.com/sdsykes/fastimage
cas = CreativesAttachment.where(width: nil, height: nil, attribute_name: %w(image icon_image end_card_image portrait_image landscape_image))
cas.each do |ca|
width, height = FastImage.size("http://i.loopme.me/#{ca.read_attribute(:converted_file)}")
ca.update_columns(width: width, height: height)
end
def date_range
@date_range ||= Reports::DateRange.new(:custom, :day, '2016-05-23', '2016-05-23')
end
options = { date_range: date_range, filters: { app_id: '17327' } }
metrics = [:earnings, :inbox_opens, :video_completes]
@group_by = [:country, :date]
data = Statistics::App.grouped_by(@group_by, options)
@azelenets
azelenets / test unzip feature.rb
Last active April 15, 2022 12:32
Upload ZIP archive, unarchive and create attachments from the archive files
require 'zip'
IMAGE_EXTENSIONS = %w(.jpg .jpeg .png .gif)
VIDEO_EXTENSIONS = %w(.mp4)
EXTENSIONS_WHITELIST = IMAGE_EXTENSIONS + VIDEO_EXTENSIONS
attachment = User.includes(:attachments).where(email: 'mikhaild+adv@loopme.com').first.attachments.where(file_type: 'archive').last
def cache_dir
Rails.root.join(CarrierWave::Uploader::Base.cache_dir)
@azelenets
azelenets / array_validator.rb
Created January 6, 2017 09:34 — forked from ssimeonov/array_validator.rb
Enumerable and array validators for ActiveModel::Validations in Rails. Especially useful with document-oriented databases such as MongoDB (accessed via an ODM framework such as Mongoid).
# Syntax sugar
class ArrayValidator < EnumValidator
end
@azelenets
azelenets / README.md
Created February 13, 2017 07:39 — forked from denji/README.md
Remove settings/CLI for macOS (OS X) – DataGrip, AppCode, CLion, Gogland, IntelliJ, PhpStorm, PyCharm, Rider, RubyMine, WebStorm

Quick uninstall JetBrains settings:

curl -sL https://gist.github.com/denji/9731967/raw/jetbrains-uninstall.sh | bash -s

Quick backup JetBrains settings:

curl -sL https://gist.github.com/denji/9731967/raw/jetbrains-backup.sh | bash -s
class String
def my_index(string)
self.length.times do |i|
char = self[i]
string.length.times do |j|
incoming_char = string[j]
next unless incoming_char == char
return "position: #{i+1}" if self[i..i+string.length-1] == string
end
end
function formatDate(date) {
var monthNames = [
"Jan", "Feb", "Mar",
"Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct",
"Nov", "Dec"
];
var day = date.getDate();
var monthIndex = date.getMonth();
@azelenets
azelenets / ffmpeg_install.md
Created May 31, 2017 09:33 — forked from jmsaavedra/ffmpeg_install.md
Install FFmpeg on a Linux Box

###Install FFmpeg via CLI on Linux box

These steps walk through installing a static binary of any ffmpeg version on to your linux machine. If you want to compile from source, there are several ways to do so. Here's the official guide. Tested and works on an AWS EC2 Ubuntu instance, but should work on any Linux machine.

  • SSH into your instance and become root
https:\/\/(?:www\.)?youtube\.com(\/watch\?v=|(\/playlist\?list=))([\w\-\_]*)(&(amp;)?‌​[\w\?‌​=]*)?