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
@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
@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 / 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 / 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 / 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 / .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:
# 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 / 0.result.md
Created December 15, 2022 14:24 — forked from nateberkopec/0.result.md
De-'Async Inject'ing Universal Analytics

De-'Async Inject' Universal Analytics

This gist applies the theory from Ilya Grigorik's Script-injected "async scripts" considered harmful on the default Universal Analytics snippet. TLDR place this above the CSS in the <head> of your document

<!-- Google Analytics Part 1: Creates window.ga, sets account, and queues pageview-->
<script>
  !function(n,t){n.GoogleAnalyticsObject=t,n[t]=n[t]||function(){(n[t].q=n[t].q||[]).push(arguments)},n[t].l=1*new Date}(window,"ga");
  ga('create', 'UA-XXXX-Y', 'auto'); // REPLACE UA-XXXX-Y w/ YOUR ACCOUNT
 ga('send', 'pageview');
@ZilvinasKucinskas
ZilvinasKucinskas / ci.yml
Created October 17, 2022 08:35
Github Action with PG, MySQL, SQLite
name: Tests
on:
pull_request:
branches:
- '*'
push:
branches:
- master
jobs:
@ZilvinasKucinskas
ZilvinasKucinskas / key.md
Created February 28, 2019 00:10
Twitter (un)official Consumer Key

Twitter Official Consumer Key

Twitter for Android

type:            PIN
Consumer key:    3nVuSoBZnx6U4vzUxf5w
Consumer secret: Bcs59EFbbsdF6Sl9Ng71smgStWEGwXXKSjYvPVt7qys

Twitter for iPhone

type:            PIN

Consumer key: IQKbtAYlXLripLGPWd0HUA