Skip to content

Instantly share code, notes, and snippets.

View tbilous's full-sized avatar

Taras Bilous tbilous

  • Varna, Bulgaria
View GitHub Profile
@tbilous
tbilous / axios-catch-error.js
Created July 8, 2020 07:57 — forked from fgilio/axios-catch-error.js
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨
# routes.rb
match 'ads/:id/present/*path.:format', :to => 'ads#present'
# ads_controller.rb
def present
@ad = Ad.find(params[:id])
path = "#{params[:path]}.#{params[:format]}"
send_data(@ad.get_file(path), :filename => path, :disposition => 'inline')
end
@tbilous
tbilous / rails-jsonb-queries
Created February 12, 2020 06:42 — forked from mankind/rails-jsonb-queries
Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
@tbilous
tbilous / lenovo_ideapad_330_ubuntu.md
Created March 1, 2019 21:37 — forked from debojyoti/lenovo_ideapad_330_ubuntu.md
Lenovo ideapad 330 (15ARR) ubuntu issues and there solutions

Lenovo ideapad 330 (15ARR) ubuntu issues and their solutions

Issue-1: None of the ubuntu distros are getting installed

Solution: Ubuntu distros lower than 18.10 will not work in this laptop, as minimum kernal version required is 4.18.

So install ubuntu 18.10 / xubuntu 18.10 / lubuntu 18.10 / kubuntu 18.10 in UEFI mode

Issue-2: Wifi is not working

@tbilous
tbilous / gist:e3611662dbb757819e1b188f3f783121
Created February 6, 2019 18:38 — forked from webdev1001/gist:e848abef8064c55c2f6443a282f75651
Array values in the parameter to `Gem.paths=` are deprecated.
Array values in the parameter to `Gem.paths=` are deprecated.
Please use a String or nil.
An Array (...) was passed in from bin/rails:3:in `load'
Solution
========
https://github.com/rubygems/rubygems/issues/1551
If you came to this issue by googling the error specified in the description of this issue, you should know that it has already been fixed in spring-1.6.4 and all you need to do is to update to latest spring and regenerate binstubs, like this:
worker_processes 1;
events {
worker_connections 1024;
}
http {
# passenger_root /home/deployer/.rvm/gems/ruby-2.3.3/gems/passenger-5.1.0;
# passenger_ruby /home/deployer/.rvm/gems/ruby-2.3.3/wrappers/ruby;
@tbilous
tbilous / Guardfile
Created October 11, 2016 17:22 — forked from palkan/Guardfile
Guardfile for Rails
# По умолчанию запускаем только необходимых для тестов наблюдателей,
# то есть всех, кроме server.
# Для запуска всех: bundle exec guard -g default
scope groups: ['specs']
group 'specs' do
# запускаем тесты и использованием Spring
guard :rspec, cmd: "bundle exec spring rspec" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)
@tbilous
tbilous / rubocop_pre_commit_hook
Created October 11, 2016 17:22 — forked from palkan/rubocop_pre_commit_hook
Rubocop pre-commit hook
#!/usr/bin/env ruby
ADDED_OR_MODIFIED = /^\s*(A|AM|M)/.freeze
changed_files = `git status --porcelain`.split(/\n/)
unstaged_files = `git ls-files -m`.split(/\n/)
changed_files = changed_files.select { |f| f =~ ADDED_OR_MODIFIED }
changed_files = changed_files.map { |f| f.split(" ")[1] }
@tbilous
tbilous / capybara cheat sheet
Created July 16, 2016 10:43 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')