Skip to content

Instantly share code, notes, and snippets.

☀️
Catching the sun

Dmitry Polushkin dmitry

☀️
Catching the sun
Block or report user

Report or block dmitry

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dmitry
dmitry / convert_utf8_to_utf8mb4
Last active Jan 22, 2018 — forked from dschneider/convert_utf8_to_utf8mb4
How to easily convert utf8 tables to utf8mb4 in MySQL 5.5
View convert_utf8_to_utf8mb4
# 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 Jan 17, 2018
Download audio files
View slavmir.fm.rb
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`
View flush-disk.md
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 Jan 4, 2018
ffmpeg timelapse scripts for sony as300
View timelapse.sh
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 Jun 15, 2017
Sort Items fast with mysql and postgres queries on acts_as_list position column
View sort_items_extension.rb
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)
View benchmark_sql.rb
(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)
View animation_name_hack.css
body {
animation-duration: 0.001s;
}
@media screen and (min-width: 769px) {
body {
animation-name: media-table;
}
}
@media screen and (max-width: 768px) {
body {
View capistrano_test.rb
namespace :test do
run 'echo #{bundle_cmd}'
end
View elasticsearch code.js
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
You can’t perform that action at this time.