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 | |
db_name = ARGV.first | |
raise ArgumentError, 'No database name given' if db_name.nil? | |
require 'db_schema' | |
require 'db_schema/reader/postgres' | |
db = Sequel.connect(adapter: 'postgres', database: db_name) do |db| | |
db.extension :pg_enum |
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
(defn find-tag [tag nodes] | |
(->> nodes | |
(filter #(= (:tag %) tag)) | |
first)) | |
(defn tag-content [tag nodes] | |
(-> (find-tag tag nodes) | |
:content | |
first)) |
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
module Enumerable | |
def my_each_slice(num, &block) | |
offset = 0 | |
while offset < count | |
yield self.to_a[offset, num] | |
offset += num | |
end | |
end | |
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
chars = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a | |
40.times.map { chars.sample }.join |
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 'nokogiri' | |
require 'faraday' | |
def urls_valid?(file_path) | |
doc = Nokogiri::XML(File.read(file_path)) | |
urls = doc.css('loc').map { |loc| loc.children.first.text } | |
urls.all? do |url| | |
Faraday.head(url).status == 200 | |
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
#!/usr/bin/env ruby | |
require 'sinatra' | |
require 'oj' | |
Oj.default_options = { | |
mode: :compat | |
} | |
post '/client/v4/zones/:zone_id/purge_cache' do |
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
guard :rspec, cmd: 'bundle exec rspec' do | |
require 'guard/rspec/dsl' | |
dsl = Guard::RSpec::Dsl.new(self) | |
rspec = dsl.rspec | |
watch(rspec.spec_helper) { rspec.spec_dir } | |
watch(rspec.spec_support) { rspec.spec_dir } | |
watch(rspec.spec_files) | |
dsl.watch_spec_files_for(%r{apps/(.*)\.rb}) |
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
def generate_password(length: 20) | |
chars = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a | |
length.times.map { chars.sample }.join | |
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
;; Macros | |
(defmacro unless-else | |
[cond if-true if-false] | |
(list 'if cond if-false if-true)) | |
(macroexpand '(unless-else false (println "false") (println "true"))) | |
;;=> (if false (println "true") (println "false")) | |
(unless-else false (println "false") (println "true")) |
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
def post_author(properties_or_obj = {}) | |
# Теперь пользователь может передать свой объект или просто хэш с параметрами | |
author = if properties_or_obj.respond_to?(:author) | |
properties_or_obj.to_author | |
else | |
properties_or_obj | |
end | |
raise ArgumentError unless author.is_a?(Hash) | |
NewerOlder