Skip to content

Instantly share code, notes, and snippets.

View ZilvinasKucinskas's full-sized avatar
:octocat:
Trust Me, I’am Software Engineer

Zilvinas Kucinskas ZilvinasKucinskas

:octocat:
Trust Me, I’am Software Engineer
View GitHub Profile
# Okasaki style Functional Red Black Tree
# https://www.cs.tufts.edu/comp/150FP/archive/chris-okasaki/redblack99.pdf
#
# leaves and root are black
# BST
# No red node has a red child
# Every path from the root to a leaf has the same number of black nodes
module RBTree
class Leaf
@ZilvinasKucinskas
ZilvinasKucinskas / .solargraph.yml
Created January 31, 2023 20:29 — forked from DRBragg/.solargraph.yml
My config with steps to use solargraph for Rails projects in VS Code (WIP)
---
include:
- "app/**/*.rb"
- "config/**/*.rb"
- "lib/**/*.rb"
exclude:
- spec/**/*
- vendor/**/*
- ".bundle/**/*"
require:
@ZilvinasKucinskas
ZilvinasKucinskas / clsx.rb
Created March 20, 2023 07:25 — forked from scottwater/clsx.rb
Quick Ruby implementation of https://www.npmjs.com/package/clsx
module Clsx
def clsx(*args)
process_args = args.map do |arg|
if arg.is_a?(Array)
clsx(*arg)
elsif arg.is_a?(Hash)
arg.map do |key, value|
key if value
end
else
@ZilvinasKucinskas
ZilvinasKucinskas / 1-oauth2_tweet_from_ruby.md
Created May 11, 2023 15:37 — forked from jkotchoff/1-oauth2_tweet_from_ruby.md
Twitter v2 Oauth2 send tweet from Ruby on Rails
@ZilvinasKucinskas
ZilvinasKucinskas / GPG and git on macOS.md
Created October 11, 2023 13:46 — forked from danieleggert/GPG and git on macOS.md
How to set up git to use the GPG Suite

GPG and git on macOS

Setup

No need for homebrew or anything like that. Works with https://www.git-tower.com and the command line.

  1. Install https://gpgtools.org -- I'd suggest to do a customized install and deselect GPGMail.
  2. Create or import a key -- see below for https://keybase.io
  3. Run gpg --list-secret-keys and look for sec, use the key ID for the next step
  4. Configure git to use GPG -- replace the key with the one from gpg --list-secret-keys
@ZilvinasKucinskas
ZilvinasKucinskas / config-initializers-trusted_proxies.rb
Created November 6, 2023 07:48 — forked from mrk21/config-initializers-trusted_proxies.rb
How to get a remote ip on CloudFront + Rails
# @see https://docs.aws.amazon.com/ja_jp/AmazonCloudFront/latest/DeveloperGuide/LocationsOfEdgeServers.html
# @see https://morizyun.github.io/ruby/rails-controller-get-ip.html
# @see https://dev.classmethod.jp/cloud/aws/get-ec2-public-ip-range-by-powershell/
# @see https://github.com/rails/rails/blob/c81af6a/actionpack/lib/action_dispatch/middleware/remote_ip.rb#L112-L150
Rails.application.configure do
ip_ranges_res = Faraday.get('https://ip-ranges.amazonaws.com/ip-ranges.json')
ip_ranges = JSON.parse(ip_ranges_res.body)
cloudfront_ips = ip_ranges['prefixes'].select { |v| v['service'] == 'CLOUDFRONT' }.map { |v| IPAddr.new(v['ip_prefix']) } +
ip_ranges['ipv6_prefixes'].select { |v| v['service'] == 'CLOUDFRONT' }.map { |v| IPAddr.new(v['ipv6_prefix']) }
@ZilvinasKucinskas
ZilvinasKucinskas / rate_limit.rb
Created January 15, 2024 10:51 — forked from hschne/rate_limit.rb
Leaky Bucket Rate Limiter in Ruby
frozen_string_literal: true
# A leaky bucket rate limiter for Ruby
#
# @see https://www.mikeperham.com/2020/11/09/the-leaky-bucket-rate-limiter/
# @see https://en.wikipedia.org/wiki/Leaky_bucket
class RateLimit
class Error < StandardError
attr_accessor :retry_in