This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pathname' | |
directories = Pathname.name('.').children.select(&:directory?) | |
file_paths = {} | |
directories.each do |directory| | |
directory.children.each do |file_path| | |
basename = file_path.basename | |
file_paths[basename] ||= [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set language environment | |
export LC_CTYPE=cs_CZ.UTF-8 | |
export LC_ALL=cs_CZ.UTF-8 | |
export LANG=cs_CZ.UTF-8 | |
# Setup preferred editor | |
export EDITOR='vim' | |
# Some handy aliases | |
alias l="ls -la" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A bunch of statistics-related methods. | |
# | |
# @example | |
# p Math::Stats.percentile(40, [15, 20, 35, 40, 50]) == 29.0 | |
# p Math::Stats.percentile(75, [1, 2, 3, 4]) == 3.25 | |
# p Math::Stats.median([15, 20, 35, 40, 50]) == 35.0 | |
# p Math::Stats.median([1, 2, 3, 4]) == 2.5 | |
# p Math::Stats.sum([15, 20, 35, 40, 50]) == 160 | |
# p Math::Stats.mean([15, 20, 35, 40, 50]) == 32.0 | |
# p Math::Stats.sample_variance([15, 20, 35, 40, 50]) == 207.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/telnet' | |
class Client | |
# Fetch weather forecast for NYC. | |
# | |
# @return [String] | |
def response | |
fetch_all_in_one_response | |
# fetch_multiple_responses | |
ensure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :db do | |
desc 'Find missing table indexes, foreign keys and null false columns' | |
task indexes: :environment do | |
require 'rainbow' | |
require 'tables_health' | |
connection = ActiveRecord::Base.connection | |
tables_health = TablesHealth.new(connection) | |
tables_health.indexes_report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'pathname' | |
require 'open3' | |
# Mass-pull git repositories. | |
# | |
# GitPull.mass_pull(Dir.pwd) | |
class GitPull | |
# Check for this string in directory names. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
class << self | |
# Make it available from the outside | |
attr_reader :traits | |
# This removes duplication in this class and subclasses | |
def init_variables | |
@traits = {} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Some time-related helpers. | |
class Fixnum | |
# Go back in time from right now. | |
# | |
# 5.days.ago => 2014-06-12 13:21:38 +0200 | |
# | |
# @return [Time] | |
def ago | |
before(Time.now) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ruby 1.8 Hash syntax: | |
some_hash = { :person => 'John Doe', :age => 30 } # Hash-Rocket-style | |
# Ruby 1.9 Hash syntaxes: | |
some_hash = { :person => 'John Doe', :age => 30 } # Hash-Rocket-style syntax still there. | |
some_hash = { person: 'John Doe', age: 30 } # JSON-style syntax, keys are symbols behind the scenes. | |
# Watch out! | |
some_hash = { 'person' => 'John Doe', 'age' => 30 } # This will work. | |
some_hash = { 'person': 'John Doe', 'age': 30 } # This will not work! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'asdščěřžýasd'.mb_chars.upcase | |
# or | |
require 'unicode' | |
Unicode.upcase 'asdščěřžýasd'.upcase |
NewerOlder