Skip to content

Instantly share code, notes, and snippets.

View dmitry's full-sized avatar
🇪🇪
Water, earth and air.

Dmitry Polushkin dmitry

🇪🇪
Water, earth and air.
View GitHub Profile
@dmitry
dmitry / convert_utf8_to_utf8mb4
Last active January 22, 2018 08:06 — forked from dschneider/convert_utf8_to_utf8mb4
How to easily convert utf8 tables to utf8mb4 in MySQL 5.5
# For each database:
ALTER DATABASE century21_development CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
# For each table:
SELECT CONCAT('ALTER TABLE `', TABLE_NAME,'` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;') AS mySQL FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA= "century21_development"
# For each column:
select CONCAT('ALTER TABLE `', TABLE_SCHEMA, '.', TABLE_NAME,'` CHANGE ',COLUMN_NAME,' ', COLUMN_NAME, ' ', DATA_TYPE,'(',CHARACTER_MAXIMUM_LENGTH,') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;') as column_alter from INFORMATION_SCHEMA.COLUMNS WHERE DATA_TYPE IN('varchar', 'text') AND TABLE_SCHEMA = 'century21_development'
@dmitry
dmitry / slavmir.fm.rb
Created January 17, 2018 22:12
Download audio files
require 'open-uri'
require 'nokogiri'
domain = 'https://slavmir.fm'
Nokogiri::HTML(open(domain + '/blogs/programmy')).css('.article_preview').to_a.each do |v|
url = domain + v.attributes['href'].value
Nokogiri::HTML(open(url)).css('.track-play').to_a.each do |z|
`curl "#{z.attributes['data-play-music'].value}" -O`
openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt < /dev/zero | pv -pterb > /dev/sdb
@dmitry
dmitry / timelapse.sh
Last active January 4, 2018 21:31
ffmpeg timelapse scripts for sony as300
for FILE in `ls *.JPG`; do \
mogrify -resize 1920x -write resized/$FILE $FILE; \
done
for FILE in `ls *.JPG`; do \
mogrify -resize 1920x1080^ -gravity center -crop 1920x1080+0+0 +repage -write resized/$FILE $FILE; \
done
for i in $(ls *.JPG); do exiv2 -r '%Y%m%d.%H%M%S' rename $i; done
@dmitry
dmitry / sort_items_extension.rb
Last active June 15, 2017 21:39
Sort Items fast with mysql and postgres queries on acts_as_list position column
module SortItemsExtension
def sort_items(ids)
unless ids.is_a?(Array)
raise ArgumentError, "ids isn't an array"
end
ids.map!(&:to_i)
old_ids = proxy_association.ids_reader
ids = ids - (ids - old_ids)
(0..24).to_a.map do Thread.new do 0.upto(20000) do |i| ActiveRecord::Base.connection.execute("SELECT * FROM properties WHERE #{i}=#{i} LIMIT 1").to_a end end end.map(&:join)
@dmitry
dmitry / animation_name_hack.css
Last active March 2, 2017 13:45
animation-name hack
body {
animation-duration: 0.001s;
}
@media screen and (min-width: 769px) {
body {
animation-name: media-table;
}
}
@media screen and (max-width: 768px) {
body {
namespace :test do
run 'echo #{bundle_cmd}'
end
var value = 1;
var c = days.length;
for (var i = 0; i < c; i++) {
var v = _source.minimum_stays[days[i]];
if (v && value < v) {
value = v;
}
}
if (value == 1) {
value = _source.minimum_nights