Skip to content

Instantly share code, notes, and snippets.

@cutalion
cutalion / main.rs
Created March 6, 2023 16:56
Game of life written by ChatGPT
use std::fmt;
// Define the dimensions of the game board
const ROWS: usize = 20;
const COLS: usize = 20;
// Define the Cell struct
#[derive(Clone, Copy)]
struct Cell(bool);

Keybase proof

I hereby claim:

  • I am cutalion on github.
  • I am cutalion (https://keybase.io/cutalion) on keybase.
  • I have a public key ASCxHyC7j9qjGEbi58EVnguJc8s-TwbR9YLfegmqtwWXjAo

To claim this, I am signing this object:

@cutalion
cutalion / relation.rb
Last active February 11, 2022 14:40
rom-sql's "Relation#exist?" using EXISTS
# override original exist? so that it does not use COUNT()
def exist?(*args, &block)
sql = where(*args, &block).dataset.unordered.select(1).exists
db.select(sql.as(:exists)).first[:exists]
end
alias any? exist?
private
def db
# frozen_string_literal: true
require 'securerandom'
LETTERS = ('a'..'z').to_a.freeze
BIG_LETTERS = ('A'..'Z').to_a.freeze
DIGITS = ('0'..'9').to_a.freeze
SPECIAL = '~`!@#$%^&*()_+{}][;:\'"/?>.<,'.split.freeze
ALL = (LETTERS + BIG_LETTERS + DIGITS + SPECIAL).freeze
@cutalion
cutalion / exceptions.rb
Last active February 7, 2020 12:48
monads vs exceptions
require 'pry'
# A
# |- B
# | |- D
# |
# |- C
AppError = Class.new(StandardError)
Error1 = Class.new(AppError)
module Initializer
def initialize
puts 'Initializer#initialize'
super
end
end
class Klass
prepend Initializer
# Пусть админы могут удалять комментарии
# и мы уведомляем кого-нибудь, что комментарий был удален
class DeleteComment
def call(comment)
transaction do
comment.delete!
user.decrement(:comments_count)
end
@cutalion
cutalion / Gemfile
Last active March 5, 2018 17:03
ROM sql-memory combine
source "https://rubygems.org"
gem 'sqlite3'
gem 'dry-logic'
gem 'dry-types'
gem 'rom'
gem 'rom-sql'
gem 'pry'

Keybase proof

I hereby claim:

  • I am cutalion on github.
  • I am cutalion (https://keybase.io/cutalion) on keybase.
  • I have a public key ASA_TnJvySK6SN95G7RdeuuJi2XAcunV37SabTXa2IwBcAo

To claim this, I am signing this object:

require 'rom'
require 'rom-repository'
require 'rom-sql'
require 'pry'
module Entity
end
config = ROM::Configuration.new(:sql, 'sqlite::memory')
conn = config.gateways[:default].connection