Skip to content

Instantly share code, notes, and snippets.

@trodrigu
trodrigu / bench_models.ex
Last active October 22, 2023 22:34
bench_models
Mix.install(
[
{:exla, "~> 0.6.1"},
{:bumblebee, "~> 0.4.2", github: "elixir-nx/bumblebee", branch: "main"},
{:benchee, "~> 1.1"}
],
config: [nx: [default_backend: EXLA.Backend]]
)
Benchee.run(%{
@trodrigu
trodrigu / find_path.rb
Created August 23, 2018 20:58
Longest increasing path in a matrix
def find_longest_rising_route(matrix)
matrix_with_locations =
matrix.each_with_index.map do |row, index|
row.each_with_index.map do |el, inner_index|
[index, [inner_index, el]]
end
end
sorted_with_locations =
@trodrigu
trodrigu / make_custom.applescript
Created July 23, 2018 03:56
make custom dog name in illustrator
set saveLocation to ((path to desktop) as string)
set fullPath to saveLocation & "newDogName"
set newFilePath to fullPath & ".svg"
log fullPath
tell application "Adobe Illustrator"
activate
make document with properties {name:"dogName"}
set theFrame to (make new text frame in current document with properties {contents:"Chi Chi", kind:area text, name:"notes"})
make new character style in document 1 with properties {name:"dog Name Character Style"}
@trodrigu
trodrigu / solution_to_rails_bundle_installation
Last active May 27, 2016 19:19
Solves problem with libv8, therubyracer and event_machine
gem install eventmachine -v '1.0.7' -- --with-cppflags=-I/usr/local/opt/openssl/include
gem uninstall libv8
gem install therubyracer -v YOUR_RUBY_RACER_VERSION
gem install libv8 -v YOUR_VERSION -- --with-system-v8
# if issue with capybara-webkit
brew install qt
@trodrigu
trodrigu / remove_header.sh
Created March 18, 2016 18:58
Shell script to remove lines from top of file
#!/bin/bash
# Make sure to chmod +x remove_header.sh
ag 'Created (?=by)' -l | while read file
do
sed -i .bak '1,17d' $file
rm "$file.bak"
done
@trodrigu
trodrigu / 213.rb
Created September 10, 2015 16:49
class Rule90
def initialize input
@input = input.split(//).map(&:to_i)
end
def get_next target_index, input
input[target_index + 1]
end
def get_prev target_index, input
@trodrigu
trodrigu / rad
Created September 3, 2015 01:41
echo "Enter app name "
read name
echo "Your app's name is: $name"
echo "Installing..."
rails new $name -T -d postgresql
cd $name
echo 'gem "rspec-rails", :group => [:development, :test]' >> Gemfile
bundle
rails g rspec:install
echo 'gem "devise"' >> Gemfile
@trodrigu
trodrigu / index.md
Last active August 29, 2015 14:25 — forked from rstacruz/index.md

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one