Skip to content

Instantly share code, notes, and snippets.

View 7even's full-sized avatar

Vsevolod Romashov 7even

View GitHub Profile
@7even
7even / db_schema_dumper.rb
Created August 27, 2020 00:13
Schema dumper draft for DbSchema
#!/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
@7even
7even / meduza.clj
Created April 28, 2020 19:07
Meduza RSS parser in Clojure
(defn find-tag [tag nodes]
(->> nodes
(filter #(= (:tag %) tag))
first))
(defn tag-content [tag nodes]
(-> (find-tag tag nodes)
:content
first))
module Enumerable
def my_each_slice(num, &block)
offset = 0
while offset < count
yield self.to_a[offset, num]
offset += num
end
end
end
chars = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
40.times.map { chars.sample }.join
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
@7even
7even / cf.rb
Created December 11, 2018 16:35
#!/usr/bin/env ruby
require 'sinatra'
require 'oj'
Oj.default_options = {
mode: :compat
}
post '/client/v4/zones/:zone_id/purge_cache' do
@7even
7even / Guardfile
Created September 19, 2017 14:27
Guardfile for guard-rspec in Hanami application
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})
@7even
7even / .pryrc
Created November 13, 2015 14:05
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
@7even
7even / gist:79609a787a7781209ffc
Last active August 29, 2015 14:18
Exercises from "7 languages in 7 weeks".
;; 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"))
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)