Skip to content

Instantly share code, notes, and snippets.

View frankyston's full-sized avatar
🎯
Ruby on Rails is Fun

Frankyston Lins frankyston

🎯
Ruby on Rails is Fun
View GitHub Profile
@frankyston
frankyston / add_unaccent_to_postgres
Created April 26, 2023 17:07 — forked from AlexVKO/add_unaccent_to_postgres
Adding extensions to Postgresql database with Rails
The default Postgresql installation on Mac OS X using homebrew includes a single extension - plpgsql (PL/pgSQL procedural language) but there are a number of them available in the lib directory (/usr/local/Cellar/postgresql/9.2.1/lib on my machine)
To install an extension into the database, the easiest way I found was to open a database console using the 'rails db' command and then create it directly. I have seen mention of doing this in a Rails migration but this did not work for me.
Note that an extension is installed in a specific database, rather than being added to all databases.
The command to list the installed extensions is '\dx'
$ rails db
psql (9.2.1)
@frankyston
frankyston / transaction.rb
Created March 14, 2023 21:16
Usando uma coleção de hash de uma outra API
params = [
{
"id": "00012572000000133723",
"dataRegistro": "15.03.2021",
"dataVencimento": "08.06.2021",
"valorOriginal": 14900,
"valorPagoSacado": 344.6,
"numeroConvenio": 000,
"numeroOperacao": 0000,
"carteiraConvenio": 17,
You could just make your own pg_dump directly from your Heroku database.
First, get your postgres string using `heroku config:get DATABASE_URL`.
Look for the Heroku Postgres url (example: `HEROKU_POSTGRESQL_RED_URL: postgres://user3123:[email protected]:6212/db982398`), which format is `postgres://<username>:<password>@<host_name>:<port>/<dbname>`.
Next, run this on your command line:
pg_dump --host=<host_name> --port=<port> --username=<username> --password --dbname=<dbname> > output.sql
@frankyston
frankyston / main.dart
Created February 27, 2023 20:13 — forked from leonino/main.dart
Draw Menu
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@frankyston
frankyston / stored_procedure_service.rb
Created February 27, 2023 11:59 — forked from ys/stored_procedure_service.rb
Execute stored procedure
class StoredProcedureService
def self.instance
@instance ||= StoredProcedureService.new
end
def execute(name, *args)
results = []
begin
connection.execute("CALL #{name}(#{args.join(',')})").each(as: :hash, symbolize_keys: true) do |row|
@frankyston
frankyston / Dockerfile
Last active June 19, 2023 04:21
Dockerizar um projeto rails ou criar um novo projeto rails com docker
FROM ruby:3.1.2
ARG NODE_MAJOR_VERSION=19
RUN curl -sL https://deb.nodesource.com/setup_$NODE_MAJOR_VERSION.x | bash -
RUN apt-get update -qq && \
apt-get install -y build-essential libvips nodejs libpq-dev postgresql-client && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man && \
npm install -g yarn
@frankyston
frankyston / docker-pry-rails.md
Created December 21, 2022 17:30 — forked from briankung/docker-pry-rails.md
Using pry-rails with Docker

Comentar no admin.js o Turbo stream

// Turbo.session.drive = false

Colocar o data para usar o turbo stream

data: { turbo_method: :delete, turbo_confirm: 'Are you sure?' }
@frankyston
frankyston / 01_metodos_de_instancia.rb
Created October 8, 2022 12:11 — forked from serradura/01_metodos_de_instancia.rb
Ruby - Métodos de instância VS de classe VS lambda
class Calc
def sum(a, b)
a + b
end
def multiply(a, b)
a * b
end
end