Skip to content

Instantly share code, notes, and snippets.

View palkan's full-sized avatar
✈️
Transcontinental hustle

Vladimir Dementyev palkan

✈️
Transcontinental hustle
View GitHub Profile
@palkan
palkan / clear_dirs
Created November 13, 2013 09:59
Script to delete directories older than 1 day within target directory. Path to target directory is stored in Erlang application's app.config file as {storage_dir, "path/to/dir"}. Pass path to config as the first argument.
#!/bin/bash
echo [$(date +"%Y-%m-%d %H:%M:%S")] Flush temporary files begins.
SOURCE="${BASH_SOURCE[0]}"
ROOT_DIR=$( dirname "${SOURCE}")
CONFIG=${1}
-module(file_utils).
-export([recursively_list_dir/1,
recursively_list_dir/2,
recursively_del_dir/1,
dir_traversal/2,
dir_traversal/3]).
% @type name() = string() | atom() | binary().
@palkan
palkan / gist:44837275114d66a24df4
Created December 1, 2014 12:32
[ruby] cyrillic detection becnh
class TestCyrillic
class << self
RUSSIAN_CODES = (1040..1103).to_a + (32..64).to_a + (91..96).to_a + (123..126).to_a + [1025, 1105, 8470]
def cyrillic?(string)
result = true
string.force_encoding("UTF-8").each_char{|c| result &&= RUSSIAN_CODES.include?(c.ord)}
result
end
@palkan
palkan / gist:beaf6bc52b125cc7a26c
Last active August 29, 2015 14:14
Page classnames stats
window._collect_css = (function(){
var ALPHABET_SIZE=36, classnames={},
data = {
total_elements: null,
total_classes: null,
avg_length: null,
compressed_length: null,
total_class_length: 0,
total_class_count: 0,
total_size: 0,
@palkan
palkan / gist:766b8d094c1e1f327c24
Last active June 8, 2017 15:56
rails issue #15468
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'sqlite3'
gem 'pry-byebug'
GEMFILE
system 'bundle'
@palkan
palkan / gist:31a70fd45b2b43024370
Created February 3, 2015 08:15
Convert all audio files within directory to MP3 (320) with FFMPEG
#!/usr/bin/env ruby
CONVERT_COMMAND = "ffmpeg -i ':input' -vn -ar 44100 -ac 2 -ab 320 -f mp3 ':output'"
def is_audio?(filename)
filename =~ /\.(wav|flac|aac)$/
end
def extract_name(filename)
File.basename(filename, File.extname(filename))+".mp3"
@palkan
palkan / rubocop_pre_commit_hook
Last active June 3, 2022 12:11 — forked from mpeteuil/rubocop_pre_commit_hook
Rubocop pre-commit hook
#!/usr/bin/env ruby
ADDED_OR_MODIFIED = /^\s*(A|AM|M)/.freeze
changed_files = `git status --porcelain`.split(/\n/)
unstaged_files = `git ls-files -m`.split(/\n/)
changed_files = changed_files.select { |f| f =~ ADDED_OR_MODIFIED }
changed_files = changed_files.map { |f| f.split(" ")[1] }
@palkan
palkan / gist:c1ae6f56b8e718e7941f
Last active August 29, 2015 14:15
Ruby method_missing bench
require 'benchmark'
_methods = ("a".."z").to_a
module A
module B
module C
module D
module E
class X
@palkan
palkan / test.rb
Last active August 29, 2015 14:15
Rails issue #18695
# Activate the gem you are reporting the issue against.
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'activerecord', '4.2.0'
gem 'pg', '0.18'
gem 'pry-byebug'
GEMFILE
system 'bundle'
@palkan
palkan / main.rb
Last active August 29, 2015 14:16
"Restore" S3 assets after updating Paperclip hash_data
# Suppose we updated our hash_data for Paperclip
OLD_HASH = ":class/:attachment/:id/:style"
NEW_HASH = ":class/:attachment/:id/:style/:updated_at"
ACL = :public_read
def restore(r)
return unless r.file.exists?
new_key = r.file.path[1..-1]
r.file.options[:hash_data] = OLD_HASH;