Skip to content

Instantly share code, notes, and snippets.

View dbelyaeff's full-sized avatar

Dmitriy Belyaev dbelyaeff

  • Russia, Saint-Petersburg
View GitHub Profile
@dbelyaeff
dbelyaeff / mysql2-m1.md
Created July 25, 2022 11:14 — forked from fernandoaleman/mysql2-m1.md
How to install mysql2 gem on m1 Mac

Problem

Installing mysql2 gem errors on m1 Mac.

Solution

Make sure mysql, openssl and zstd are installed on Mac via Homebrew.

brew install mysql openssl zstd
@dbelyaeff
dbelyaeff / functions.php
Last active April 22, 2020 08:57
Replace links with active links and links to images / AnyComment
<?php
function filter_anycomment_text( $data, $comment = null ) {
$data['content'] = preg_replace('#((?!"|\')https?://([^\s]*)\.(jpg|gif|png|jpeg|webp|svg)(?!"|\'))#', '<img class="embedded-image-link" src="$1" alt=""/>', $data['content']);
$data['content'] = preg_replace('/(?!.*(?:jpg|jpeg|gif|png|webp|svg))(https?:\/\/[\w\?\/\=\._-]+)/', '<a href="$1" rel="noopener">$1</a>', $data['content']);
return $data;
}
add_filter( 'anycomment/rest/comments/item_for_response', 'filter_anycomment_text', 10, 2 );
@dbelyaeff
dbelyaeff / functions.php
Created April 22, 2020 07:21
Хук для парсинга и трансформации ссылок и ссылок на картинки в AnyComment
<?php
function filter_anycomment_text( $data, $comment = null ) {
$data['content'] = preg_replace('#((?!"|\')http(s?)://([^\s]*)\.(jpg|gif|png|bmp|jpeg|webp|svg)(?!"|\'))#', '<img class="embedded-image-link" src="$1">', $data['content']);
$data['content'] = preg_replace_callback("/
((?<![\"']) # don't look inside quotes
(\b
( # protocol or www.
[a-z]{3,}:\/\/
|
@dbelyaeff
dbelyaeff / import_export_gz.sql
Created August 13, 2019 17:04 — forked from rakeshtembhurne/import_export_gz.sql
MySQL: Import and export in gzip form
// Export database in gzip form
mysqldump -u user -p database | gzip > database.sql.gz
// Import database from gzip form
gunzip < database.sql.gz | mysql -u user -p database
@dbelyaeff
dbelyaeff / Gemfile
Created March 22, 2019 06:18 — forked from cblunt/Gemfile
Configure Carrierwave for Amazon S3 Storage and Heroku
# ...
gem 'carrierwave'
gem 'fog', '~> 1.0.0' # Need to specify version, as carrierwave references older (0.9.0) which doesn't allow configuration of Rackspace UK Auth URL
@dbelyaeff
dbelyaeff / instagram.rb
Created March 19, 2019 16:19
Download videos and split them into chunks by 59 sec for Instagramm
#!/usr/bin/env ruby
require 'time'
puts ARGV.inspect
link = ARGV[0]
puts('Link is needed!') && exit if link.nil?
puts title = `youtube-dl -e #{link}`
puts duration = `youtube-dl --get-duration #{link}`
duration = duration.split(':')
@dbelyaeff
dbelyaeff / lib_domains.rb
Created March 12, 2019 19:48
Rails subdomains
class Subdomain
def self.matches?(request)
request.subdomain.present? && request.subdomain != "www"
end
end
class Domain
def self.matches?(request)
request.domain.present? && request.domain != "mydomain.com"
end
@dbelyaeff
dbelyaeff / Gemfile
Created November 11, 2018 17:33
Auto open browser after Rails server starts
gem 'launchy'
@dbelyaeff
dbelyaeff / img.l
Created November 3, 2018 08:49 — forked from webmasterkai/img.l
Mirror remote image files, supports dynamic resizing of images. nginx image_filter remote fetching with a local mirror of original and resized image. Using try_files instead of if statements and proxy_pass with proxy_store for permanent local storage. No cache expiration, that will need to be handled outside of this.
server {
server_name img.l;
root /var/www/cache/store/ns365;
index index.html;
# This requests the original file from itself and then resizes the image.
location ~ /resize/(\d+)x(\d+)/(.*) {
proxy_pass http://img.l/$3;
image_filter resize $1 $2;
image_filter_jpeg_quality 90;