Skip to content

Instantly share code, notes, and snippets.

@gabriel-curtino
gabriel-curtino / sqlite_full_text_search.rb
Created September 7, 2024 13:57
Rails SQLite Full Text Search (per table, at db level)
## SqliteFullTextSearch Concern
#
# The `SqliteFullTextSearch` concern provides a set of methods and triggers to enable full-text search capabilities for ActiveRecord models using SQLite's FTS5 extension.
#
# ### Key Features
# - **Full-Text Search Scope**: Adds a `search` scope to the model for performing full-text searches.
# - **Index Creation and Management**: Automatically creates and manages FTS5 tables and triggers for the model.
# - **Attribute Configuration**: Allows specifying attributes to include in the full-text search index.
# - **Trigger Management**: Sets up triggers to keep the search index up-to-date with model changes.
#
@omarzina
omarzina / csv_to_hash_array.rake
Created April 28, 2022 12:08 — forked from voleinikov/csv_to_hash_array.rake
Ruby -- turn CSV file into array of hashes with headers as keys (rake task)
# Adapted from StackOverflow answers:
# http://stackoverflow.com/a/8477067/1319740
# and
# http://stackoverflow.com/a/18113090/1319740
# With help from:
# http://technicalpickles.com/posts/parsing-csv-with-ruby/
# A small rake task that validates that all required headers are present in a csv
# then converts the csv to an array of hashes with column headers as keys mapped
# to relevant row values.
@stevenharman
stevenharman / format-ruby
Created March 19, 2020 15:05
Run `standardrb --fix` as a git pre-commit hook. NOTE: this assumes `gem "standard"` is in your Gemfile
#!/bin/sh
# This file is `.git/hooks/format-ruby` and it has been `chmod +x`'d
# Assumption: https://github.com/testdouble/standard is in your Gemfile
set -e
rubyfiles=$(git diff --cached --name-only --diff-filter=ACM "*.rb" "*.rake" "Gemfile" "Rakefile" | tr '\n' ' ')
[ -z "$rubyfiles" ] && exit 0
# Standardize all ruby files
@andreicristianpetcu
andreicristianpetcu / ansible-summary.md
Created May 30, 2016 19:25
This is an ANSIBLE Cheat Sheet from Jon Warbrick

An Ansible summary

Jon Warbrick, July 2014, V3.2 (for Ansible 1.7)

Configuration file

intro_configuration.html

First one found from of

@rhardih
rhardih / convert.sh
Created August 26, 2015 17:18
Recursively find and convert .epub to .mobi using calibres ebook-convert (in parallel)
find . -name "*.epub" -exec sh -c 'ebook-convert "{}" "$(dirname "{}")/$(basename -s .epub "{}").mobi" &' \;
@JamesMGreene
JamesMGreene / gitflow-breakdown.md
Last active March 27, 2025 17:19
`git flow` vs. `git`: A comparison of using `git flow` commands versus raw `git` commands.

Initialize

gitflow git
git flow init git init
  git commit --allow-empty -m "Initial commit"
  git checkout -b develop master

Connect to the remote repository

@DanHerbert
DanHerbert / fix-homebrew-npm.md
Last active November 27, 2024 13:36
Instructions on how to fix npm if you've installed Node through Homebrew on Mac OS X or Linuxbrew

OBSOLETE

This entire guide is based on an old version of Homebrew/Node and no longer applies. It was only ever intended to fix a specific error message which has since been fixed. I've kept it here for historical purposes, but it should no longer be used. Homebrew maintainers have fixed things and the options mentioned don't exist and won't work.

I still believe it is better to manually install npm separately since having a generic package manager maintain another package manager is a bad idea, but the instructions below don't explain how to do that.

Fixing npm On Mac OS X for Homebrew Users

Installing node through Homebrew can cause problems with npm for globally installed packages. To fix it quickly, use the solution below. An explanation is also included at the end of this document.

@stevenyap
stevenyap / RailsAdmin.md
Created February 21, 2014 08:49
Rails Admin

Extracting model configuration

# app/models/booking.rb
class Booking
  include RailsAdmin::Booking
end

# app/models/concerns/rails_admin/booking.rb
module RailsAdmin::Booking
@isaacs
isaacs / node-and-npm-in-30-seconds.sh
Last active March 20, 2025 09:05
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')