Skip to content

Instantly share code, notes, and snippets.

@korun
korun / benchmark.rb
Created Apr 3, 2015
ruby const_get vs ::
View benchmark.rb
require 'benchmark'
n = 1_000_000
class Parent
HANDLER_METHOD = :awesome_method
end
class Children < Parent
HANDLER_METHOD = :not_very_awesome_method
View benchmark.rb
require 'benchmark'
n = 1_000_000
login = 'login'
time = Time.now.to_i
Benchmark.bmbm 20 do |results|
results.report 'cycle' do
n.times do
@korun
korun / time_ago.js
Last active Aug 29, 2015 — forked from codeincontext/gist:1285806
Javascript function to show how long ago a timestamp was as a pretty string (support Russian language and genitive)
View time_ago.js
// time in seconds
// genitive - использовать ли родительный падеж (true / false)
(function (){
var units = [
{ name: "second", limit: 60, in_seconds: 1 },
{ name: "minute", limit: 3600, in_seconds: 60 },
{ name: "hour", limit: 86400, in_seconds: 3600 },
{ name: "day", limit: 604800, in_seconds: 86400 },
{ name: "week", limit: 2629743, in_seconds: 604800 },
{ name: "month", limit: 31556926, in_seconds: 2629743 },
View ruby_ftp_example.rb
require 'net/ftp'
CONTENT_SERVER_DOMAIN_NAME = "one-of-the-ftp-server.thought-sauce.com.hk"
CONTENT_SERVER_FTP_LOGIN = "saucy-ftp-server-login"
CONTENT_SERVER_FTP_PASSWORD = "saucy-ftp-server-password"
# LOGIN and LIST available files at default home directory
Net::FTP.open(CONTENT_SERVER_DOMAIN_NAME, CONTENT_SERVER_FTP_LOGIN, CONTENT_SERVER_FTP_PASSWORD) do |ftp|
files = ftp.list
@korun
korun / .gitignore
Last active Aug 29, 2015
Выгрузка комментариев ВКонтакте
View .gitignore
# See http://help.github.com/ignore-files/ for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'
# Ignore popular IDE local-settings.
.idea/*
.settings/*
@korun
korun / devise.ru.yml
Last active Aug 29, 2015 — forked from EvilFaeton/ devise.ru.yml
Russian I18n locale for devise.
View devise.ru.yml
ru:
devise:
confirmations:
confirmed: "Ваша учётная запись подтверждена. Теперь вы вошли в систему."
send_instructions: "В течение нескольких минут вы получите письмо с инструкциями по подтверждению вашей учётной записи."
send_paranoid_instructions: "Если ваш адрес email есть в нашей базе данных, то в течение нескольких минут вы получите письмо с инструкциями по подтверждению вашей учётной записи."
failure:
already_authenticated: "Вы уже вошли в систему."
inactive: "Ваша учётная запись ещё не активирована."
invalid: "Неверный адрес email или пароль."
View simple_form_bootstrap3.rb
# -*- encoding : utf-8 -*-
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
config.wrappers :bootstrap3, tag: 'div', class: 'form-group', error_class: 'has-error',
defaults: {input_html: {class: 'default_class'}} do |b|
b.use :html5
b.use :min_max
b.use :maxlength
b.use :placeholder
@korun
korun / git_fork_update.sh
Last active Dec 28, 2015
How to update a fork from the original repository? The answer in this article.
View git_fork_update.sh
git remote add --track master repo_orig SOME_REPO.git
# Verify new remote
git remote -v
git fetch repo_orig
git merge repo_orig/master