Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Chedli Bourguiba chaadow

🎯
Focusing
View GitHub Profile
View 0_unique_data.md

How to run examples

  1. Run $ createdb uniq-db-test to create DB
  2. Run example with Ruby (e.g., $ ruby 1_find_or_create_by_single_thread.rb)

Benchmark output

With many successful INSERTs

Warming up --------------------------------------
@reshleman
reshleman / bug.rb
Created Mar 11, 2021
ActiveStorage bug w/ multiple `#attach` calls in a transaction
View bug.rb
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
View 1_graphql_ruby_n_plus_one.md

How to run examples:

  1. Run $ createdb nplusonedb to create DB
  2. Run specs $ rspec demo.rb
@dhh
dhh / Gemfile
Created Jun 24, 2020
HEY's Gemfile
View Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@jesster2k10
jesster2k10 / README.md
Last active Sep 26, 2022
JWT Auth + Refresh Tokens in Rails
View README.md

JWT Auth + Refresh Tokens in Rails

This is just some code I recently used in my development application in order to add token-based authentication for my api-only rails app. The api-client was to be consumed by a mobile application, so I needed an authentication solution that would keep the user logged in indefinetly and the only way to do this was either using refresh tokens or sliding sessions.

I also needed a way to both blacklist and whitelist tokens based on a unique identifier (jti)

Before trying it out DIY, I considered using:

@HansMuller
HansMuller / system_back.dart
Last active Feb 14, 2022
Bottom navigation example with a Navigator per destination
View system_back.dart
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for NavigationBar with nested Navigator destinations.
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class Destination {
View dirty_tracking_benchmark.rb
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails"
@vovahost
vovahost / main.dart
Created Feb 27, 2019
CancelableOperation and CancelableCompleter usage example
View main.dart
import 'package:async/async.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test("CancelableOperation with future", () async {
var cancellableOperation = CancelableOperation.fromFuture(
Future.value('future result'),
onCancel: () => {print('onCancel')},
);
@ershad
ershad / rack_attack.rb
Last active Mar 5, 2019
Rack::Attack sample configuration
View rack_attack.rb
class Rack::Attack
# By default, Rack::Attack uses `Rails.cache` to store requests information.
# It's configurable as follows -
#
# redis_client = Redis.connect(url: ENV["REDIS_URL"])
# Rack::Attack.cache.store = Rack::Attack::StoreProxy::RedisStoreProxy.new(redis_client)
class Request < ::Rack::Request
@georgeclaghorn
georgeclaghorn / image.rb
Created Apr 24, 2018
Using a join model to annotate Active Storage blobs with custom data
View image.rb
class Image < ApplicationRecord
belongs_to :project
has_one_attached :file
delegate_missing_to :file
scope :positioned, -> { order(position: :asc) }
end