Skip to content

Instantly share code, notes, and snippets.

View gowda's full-sized avatar

Basavanagowda Kanur gowda

View GitHub Profile
@gowda
gowda / webmock-faraday.rb
Last active September 8, 2021 14:17
All (almost) examples from webmock README.md using faraday
# frozen_string_literal: true
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'minitest', '~> 5.14.0'
gem 'webmock', '~> 3.14.0'
gem 'faraday', '~> 1.7.0'
@gowda
gowda / events.rb
Created May 11, 2021 11:17
Recurring events implementation in ruby
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem 'rails', '6.1.0'
gem 'sqlite3'
end
@gowda
gowda / polynomial.hs
Last active April 6, 2021 08:00
Read list of coefficients & generate a polynomial representation
-- install hspec
-- $ cabal install --lib hspec
--
-- import in GHCi
-- $ ghci polynomial.hs
-- *Main> toPolynomial "1"
-- "1.0"
-- *Main> toPolynomial "0 1 0 3"
-- "1.0 * x^1 + 3.0 + x^3"
--
@gowda
gowda / interpolation.rb
Last active April 5, 2021 09:50
Finding polynomial of degree n, given n points (x, y) by method of interpolation
# frozen_string_literal: true
require 'bundler/inline'
class Polynomial
attr_reader :coeffs
def initialize(coeffs)
@coeffs = coeffs
end
@gowda
gowda / rack-echo-server.rb
Last active April 1, 2021 20:21
HTTP Echo server in rack
# frozen_string_literal: true
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'rack'
gem 'minitest'
gem 'rack-test'
@gowda
gowda / extensibe-profile-using-activerecord.rb
Created April 1, 2021 14:39
Extensible profile using ActiveRecord
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source 'https://rubygems.org'
gem 'activerecord', '6.1.0'
gem 'sqlite3'
end
const assert = require('assert').strict;
function solution(a, k) {
if (k === 0 || a.length === 0) {
return a;
}
const last = a[a.length - 1];
const butlast = a.slice(0, a.length - 1);
return solution([last, ...butlast], k - 1);
@gowda
gowda / fizz-buzz.rb
Created April 27, 2020 11:18
Fizz buzz in ruby
# frozen_string_literal: true
# Run all tests:
# $ ruby fizz-buzz.rb
#
def generate_functional(limit)
fizzes = [nil, nil, :fizz].cycle
buzzes = [nil, nil, nil, nil, :buzz].cycle
fizzes.take(limit).zip(buzzes.take(limit))
@gowda
gowda / path_expander_filter_files_dir_with_subdir.rb
Created March 23, 2020 23:08
PathExpander#filter_files fails for directory with subdirectories
# frozen_string_literal: true
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'path_expander', '~> 1.1.0'
gem 'minitest', '~> 5.11.0'
end
@gowda
gowda / carrierwave-base64.rb
Last active December 27, 2019 16:27
`carrierwave-base64` breaks ActiveRecord validations
# frozen_string_literal: true
require "bundler/inline"
CARRIERWAVE_BASE64_VERSION = ENV['CARRIERWAVE_BASE64_VERSION'] || '~> 2.3.5'
gemfile(true) do
source "https://rubygems.org"
gem 'rails', '~> 5.2.0'