Skip to content

Instantly share code, notes, and snippets.

View tbilous's full-sized avatar

Taras Bilous tbilous

  • Varna, Bulgaria
View GitHub Profile
module Streaks
class Drives
MINIMUM_RATING_FOR_STREAK = 5
ACTIVE_STREAK_MINIMUM_AMOUNT = 3
def initialize user
@user = user
end
# Create a Secret Key for Rails
#
# You can generate a secure one through the Greenlight docker image
# with the command.
#
# docker run --rm bigbluebutton/greenlight:v2 bundle exec rake secret
#
SECRET_KEY_BASE=
# The endpoint and secret for your BigBlueButton server.
# frozen_string_literal: true
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
#
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
#
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
@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")
#!/usr/bin/env ruby
# example: ruby task_p2.rb
require 'json'
require 'yaml'
def set(hash, path, val)
parts = path.split('.')
scope = hash
@tbilous
tbilous / task_p1_t2_v2.rb
Created July 12, 2019 05:56
Part 1 Task2 (Ver.2)
#!/usr/bin/env ruby
# example: ruby task_p1_t2_v2.rb 'To be or not to be -that is the question' 5
require 'ostruct'
v1, v2 = ARGV
input_str = v1
n = v2.to_i
input_words = input_str.split(/\s+/)
@tbilous
tbilous / task_p1_t2_v1.rb
Created July 12, 2019 05:55
Part 1 Task 2 (Ver.1)
#!/usr/bin/env ruby
# example: ruby task_p1_t2_v1.rb 'To be or not to be that is the question' 5
v1, v2 = ARGV
puts v1.scan(/.{1,#{v2}}\b|.{1,#{v2}}/).each(&:lstrip!).join("\n")
@tbilous
tbilous / task_p1_t1.rb
Created July 11, 2019 15:58
part 1 task 1
#!/usr/bin/env ruby
# example: ruby task_p1_t1.rb 'abcdab987612'
require 'ostruct'
input_str = ARGV[0]
input_chars = input_str.chars
first_char = input_chars.shift
initial_state = OpenStruct.new(