Skip to content

Instantly share code, notes, and snippets.

View orthodoX's full-sized avatar

Slobodan Erak orthodoX

View GitHub Profile
@ntamvl
ntamvl / create-ruby-gem-that-adds-rake-tasks.md
Last active February 16, 2024 19:13
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.

@castwide
castwide / rails.rb
Last active April 27, 2024 08:54
Enhance Rails Intellisense in Solargraph
# The following comments fill some of the gaps in Solargraph's understanding of
# Rails apps. Since they're all in YARD, they get mapped in Solargraph but
# ignored at runtime.
#
# You can put this file anywhere in the project, as long as it gets included in
# the workspace maps. It's recommended that you keep it in a standalone file
# instead of pasting it into an existing one.
#
# @!parse
# class ActionController::Base
@gabeodess
gabeodess / custom_arel.rb
Last active September 20, 2020 23:16
An example of how to add a custom predicate to Arel
module Arel::Predications
def has_key(right)
Arel::Nodes::HasKey.new(self, quoted_node(right))
end
end
class Arel::Nodes::HasKey < Arel::Nodes::Binary
def operator; :"?" end
end
@ventsislaf
ventsislaf / phoenix_heroku_reset_db.md
Last active May 18, 2023 14:14
Reset database on Heroku running Phoenix app

Note: Don't do this on a production evniroment!

Get the heroku database name:

heroku pg:info

Name can be found in the reponse from the command above. For example: Add-on: soaring-newly-1337.

@ssaunier
ssaunier / db.rake
Last active January 8, 2021 11:46 — forked from abstractcoder/import.rake
Rake task to back up heroku database and restore it locally.
namespace :db do
desc "Backs up heroku database and restores it locally."
task import_from_heroku: [ :environment, :create ] do
HEROKU_APP_NAME = nil # Change this if app name is not picked up by `heroku` git remote.
c = Rails.configuration.database_configuration[Rails.env]
heroku_app_flag = HEROKU_APP_NAME ? " --app #{HEROKU_APP_NAME}" : nil
Bundler.with_clean_env do
puts "[1/4] Capturing backup on Heroku"
`heroku pg:backups capture DATABASE_URL#{heroku_app_flag}`
@netzfisch
netzfisch / post_policy_spec.rb
Created June 26, 2014 13:51
RSpec example for rails authorisation with Pundit's policy_scope method
describe PostPolicy do
let(:scope) { Post.where(:published => true }
subject(:policy_scope) { PostPolicy::Scope.new(user, scope).resolve }
permissions ".scope" do
context "for an ordinary user"
let(:user) { User.new(:admin => false) }
it "hides unpublished post" do
post = Post.create(:published => false)
@madhums
madhums / Preferences.sublime-settings
Created April 16, 2012 23:36
my sublime text settings!
{
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"draw_minimap_border": true,
"find_selected_text": true,
"font_face": "Bitstream Vera Sans Mono",
"font_options":
[
"subpixel_antialias",
"bold"
],