Skip to content

Instantly share code, notes, and snippets.

@ramses-lopez
ramses-lopez / crop_images.rb
Created April 29, 2023 03:46
Use ruby-vips to crop one image into smaller images
require 'vips'
input_image = Vips::Image.new_from_file('all_pics.webp')
x = 0
y = 0
width = 100
height = 100
gap = 28
@ramses-lopez
ramses-lopez / ruby.json
Last active March 14, 2023 14:41
VS Code snippets - *.rb
{
"byebug": {
"prefix": "bb",
"body": [
"byebug"
],
"description": "Insert byebug call"
},
"pry": {
"prefix": "bp",
@ramses-lopez
ramses-lopez / erb.json
Created March 14, 2023 14:40
VS Code Snippets - erb
"Interpolate ruby": {
"prefix": "ir",
"body": [
"<%= $1 %>"
],
"description": "Interpolate"
},
"Insert bracket pair ruby": {
"prefix": "irp",
"body": [
ssh-add ~/.ssh/id_rsa
ssh -vT git@github.com
@ramses-lopez
ramses-lopez / remove_merged_branchs.sh
Last active February 2, 2021 15:24
Remove merged branchs
git branch --merged | grep -v "\*" | xargs -n 1 git branch -d && git remote prune origin
@ramses-lopez
ramses-lopez / controller_actions_keyword_args.rb
Created October 2, 2020 18:03 — forked from kuahyeow/controller_actions_keyword_args.rb
a rewriter to upgrade to Rails 5.1 style controller test actions
=begin
USAGE: ruby-rewrite -l controller_actions_keyword_args.rb -m <FILE>
This rewriter moves your Rails controller tests from `get action, params, session, flash` to
`get action, params: params, session: session, flash: flash`.
Which is needed if you see the following message in your Rails 5.0 tests :
DEPRECATION WARNING: Using positional arguments in functional tests has been deprecated,
in favor of keyword arguments, and will be removed in Rails 5.1.
@ramses-lopez
ramses-lopez / git_branch_cleanup.sh
Created November 28, 2019 03:00
Remove merged branches & remove references to deleted branches in remote
git branch --merged | grep -v "\*" | xargs -n 1 git branch -d && git remote prune origin
@ramses-lopez
ramses-lopez / install nokogiri
Created May 24, 2019 19:34
one-liner to install nokogiri on OSX
gem install nokogiri -v '1.9.1' -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.15 --use-system-libraries --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml2
@ramses-lopez
ramses-lopez / find_duplicates.sql
Created May 21, 2019 20:40
Example query for finding duplicates and using window functions
SELECT
opportunities.id "opp_id",
title,
expiry_date,
ROW_NUMBER() OVER dupes,
FIRST_VALUE(opportunities.id) OVER dupes "parent"
FROM opportunities
WINDOW dupes AS (PARTITION BY opportunities.title, opportunities.expiry_date ORDER BY opportunities.created_at)
@ramses-lopez
ramses-lopez / delete_selected_sessions.sql
Last active April 22, 2019 17:07
Clear selected sessions from rails table
set bytea_output to 'escape';
-- delete
select session_id, decode(data, 'base64')::text
from sessions
where decode(data, 'base64')::text ilike '%return_to%'
and decode(data, 'base64')::text ilike '%password%new%';