Skip to content

Instantly share code, notes, and snippets.

module Base62
BASE_CHARS = '0SKVnQFHhGs9qo7p8cRW54duMYNXTCErx2tDmwO3kabfUB1elLvjiIgyJAZ6Pz'.split('')
BASE = BASE_CHARS.length
BASE_ENCODED_MIN_LENGTH = 1
def self.decode(number)
# assure string
number = number.to_s.reverse.split('')
decoded = 0
@ivan-leschinsky
ivan-leschinsky / application.rb
Last active August 29, 2015 14:07 — forked from brentertz/application.rb
Middleware for robots.txt disallowing
# Disallow site indexing in non-production environments
config.middleware.insert_before(::Rack::Lock, '::Rack::Robots')
# Configure Rack middleware
config.middleware.insert_before 0, 'WwwRedirect'
@ivan-leschinsky
ivan-leschinsky / rails_application_config.rb
Last active August 29, 2015 14:07 — forked from brentertz/rails
For SEO: Avoid SEO duplicate content issues
config.middleware.insert_before(0, 'Rack::SeoRedirect')
@ivan-leschinsky
ivan-leschinsky / masked_input.coffee
Last active August 29, 2015 14:22
Masked input helper for simple_form
// Requires http://digitalbush.com/projects/masked-input-plugin
element = $('[data-behaviour=masked-input]')
element.mask(element.data('mask'))
@ivan-leschinsky
ivan-leschinsky / music_renamer.rb
Created November 27, 2015 00:49
Renames music files accoriding to their netadata
#!/usr/bin/env ruby
require 'mp3info'
dir = ARGV[0]
Dir["#{dir}/*.mp3"].each do |filename|
new_file_name = ' - '
begin
Mp3Info.open(filename) do |mp3|
file_name = "#{mp3.tag.title} - #{mp3.tag.artist} (#{File.basename(filename)}).mp3"
@ivan-leschinsky
ivan-leschinsky / add_to_enumeration.rb
Last active November 27, 2015 00:58
How to add values to enumeration
class SomeEnumeration < EnumerateIt::Base
associate_values :one, :two
end
class SomeEnumeration < EnumerateIt::Base
# To add only new values
def self.add_values(*args)
values_hash = (keys + args).each_with_object({}) { |v, h| h[v] = v.to_s }
register_enumeration normalize_enumeration(values_hash)
@ivan-leschinsky
ivan-leschinsky / .zshrc
Last active December 14, 2015 15:08
Auto run vagrant shell for specified folders if running with Virtual box
# At the end of your .zshrc file
vagrant_folders=( '/Users/user/some_vagrant_folder' '/Users/user/some_another_vagrant_folder' )
source $HOME/vagrant_auto_run.sh
@ivan-leschinsky
ivan-leschinsky / db_on_js.js
Created January 22, 2016 12:51
simple indexDB for js workers or another
// Create/open database
var db, dbVersion = 1, request = indexedDB.open("simpleDB", dbVersion)
request.onerror = function (event) {
console.log("Error creating/accessing IndexedDB database");
};