Skip to content

Instantly share code, notes, and snippets.

View lsantosc's full-sized avatar

Lucas Santos da Costa lsantosc

  • Cascavel / Paraná - Brasil
View GitHub Profile
@jnunemaker
jnunemaker / partition_by_day.rb
Created December 2, 2021 19:42
Ruby class to partition by day using native declarative partitioning in postgres
# https://www.postgresql.org/docs/13/ddl-partitioning.html#DDL-PARTITIONING-DECLARATIVE
class PartitionByDay
class Row
include Virtus.model
attribute :name, String
attribute :expression, String
end
def self.all(table)
@ntamvl
ntamvl / create-ruby-gem-that-adds-rake-tasks.md
Last active March 9, 2025 00:04
How to create a Ruby gem that adds Rake tasks

How to create a Ruby gem that adds Rake tasks

Create a gem

One way to do this is to use bundler to scaffold our gem:

bundler gem my_gem

Add rake tasks to our gem

I prefer to put tasks meant to manage the gem itself in lib/tasks, and tasks the gem is meant to provide to gem users in lib/my_gem/tasks.

@javan
javan / direct-uploads.md
Last active January 9, 2025 01:00
Active Storage direct uploads

direct-uploads

rails/activestorage#81

// direct_uploads.js

addEventListener("direct-upload:initialize", event => {
  const { target, detail } = event
  const { id, file } = detail
@mbajur
mbajur / .md
Created April 29, 2016 07:16
How to create small, unique tokens in Ruby

How to create small, unique tokens in Ruby

That is is basically a "fork" of blog article i'm constantly returning to. It seems that the blog is down:

My choice: Dave Bass’s rand().to_s() trick

Dave Bass proposed this which I picked up for my implementation (here for an 8-chars token):

@uldza
uldza / gist:6711bc47c823656f97cd
Last active June 18, 2018 20:36
Image optim and dragonfly
# Add gem
https://github.com/toy/image_optim
# For production/demo install instructions look in gem readme
### UBUNTU 12.04 image_optim requirments:
> sudo add-apt-repository ppa:danmbox/ppa
> sudo apt-get update
> sudo apt-get install -y advancecomp gifsicle jhead jpegoptim libjpeg-progs optipng pngcrush pngquant
# download pngout from http://www.jonof.id.au/kenutils
@jakebellacera
jakebellacera / mamp-mysql2-rbenv.md
Created August 22, 2012 20:29
Instructions on how to use MAMP with the mysql2 gem and Ruby 1.9.3-p194 via rbenv

How to use MAMP with the mysql2 gem and Ruby 1.9.3-p194 via rbenv

Let's say you're a web developer who happens to work with both MAMP and Ruby when building different types of websites. Let's say you also like to keep your MySQL stuff in one place and don't like having to juggle both a local MySQL install as well as a MAMP MySQL install. Well, you can indeed connect your ruby apps to MAMP's MySQL. Here's a tutorial on how to do it.

Important! Before you do anything, download and install MAMP. MAMP Pro will work as well. At the time of this writing, MAMP 2.1.1 is the latest.

First, install Ruby via rbenv

  1. Install homebrew
  2. Install rbenv: brew install rbenv, follow any instructions homebrew gives you after the installation is complete.