Skip to content

Instantly share code, notes, and snippets.

View leandro's full-sized avatar
🏠
Working from home

Leandro Camargo leandro

🏠
Working from home
View GitHub Profile
@mabenson00
mabenson00 / cheatsheet.rb
Last active July 2, 2024 11:47
Rails ActiveRecord JSON cheatsheet
# Basic key operators to query the JSON objects :
# #> : Get the JSON object at that path (if you need to do something fancy)
# -> : Get the JSON object at that path (if you don't)
# ->> : Get the JSON object at that path as text
# {obj, n} : Get the nth item in that object
# https://www.postgresql.org/docs/9.4/functions-json.html#FUNCTIONS-JSONB-OP-TABLE
# Date
# date before today
@kddnewton
kddnewton / json.rb
Last active October 6, 2023 09:25
JSON parser with pattern matching
require "json"
struct = { "a" => 1, "b" => 2, "c" => [1, 2, 3], "d" => [{ "e" => 3 }, nil, false, true, [], {}] }
source = JSON.dump(struct)
tokens = []
index = 0
until source.empty?
tokens <<
@JoelQ
JoelQ / month.rb
Last active November 10, 2023 04:17
require "date"
class Month
include Comparable
MONTHS_PER_YEAR = 12
def self.from_date(date)
self.from_parts(date.year, date.month)
end
@vitobotta
vitobotta / Dockerfile
Last active July 5, 2021 10:25
Dockerfile
######################
# Stage: Builder
FROM ruby:2.6.5-alpine as Builder
ARG FOLDERS_TO_REMOVE
ARG BUNDLE_WITHOUT
ARG RAILS_ENV
ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT}
ENV RAILS_ENV ${RAILS_ENV}
@rdiego26
rdiego26 / slck_imgs.js
Created March 7, 2019 16:39 — forked from gustavompo/slck_imgs.js
slck_imgs
[{url: "https://emoji.slack-edge.com/T6CU2169Z/100sual/b3a1531ff45f2acd.jpg", name: ":100sual:"}
,{url: "https://emoji.slack-edge.com/T6CU2169Z/1_don%2527t_pick_up_the_phone/8dd1f635352780e8.png", name: ":1_don't_pick_up_the_phone:"}
,{url: "https://emoji.slack-edge.com/T6CU2169Z/1hokage/9e66cda3a2ecf310.jpg", name: ":1hokage:"}
,{url: "https://emoji.slack-edge.com/T6CU2169Z/2_don%2527t_let_him_in/eb898e174fa62821.png", name: ":2_don't_let_him_in:"}
,{url: "https://emoji.slack-edge.com/T6CU2169Z/2hokage/63f4935ed5608b8c.gif", name: ":2hokage:"}
,{url: "https://emoji.slack-edge.com/T6CU2169Z/3_don%2527t_be_his_friend/68b9721a15ed8aeb.png", name: ":3_don't_be_his_friend:"}
,{url: "https://emoji.slack-edge.com/T6CU2169Z/3hokage/765b9b0f9d994981.jpg", name: ":3hokage:"}
,{url: "https://emoji.slack-edge.com/T6CU2169Z/4hokage/39a0745cfb994d6c.jpg", name: ":4hokage:"}
,{url: "https://emoji.slack-edge.com/T6CU2169Z/5hokage/0e9dcea089de5b8b.jpg", name: ":5hokage:"}
,{url: "https://emoji.slack-edge.com/T6CU2169Z/6hokag
@davygora
davygora / list_indexes_in_rails_console.rb
Created September 10, 2018 12:36
Get list of all indexes in rails console.
# rails console
ActiveRecord::Base.connection.tables.each do |table|
indexes = ActiveRecord::Base.connection.indexes(table)
if indexes.length > 0
puts "====> #{table} <===="
indexes.each do |index|
puts "----> #{index.name}"
end
puts "====> #{table} <===="
@swalkinshaw
swalkinshaw / tutorial.md
Last active November 13, 2023 08:40
Designing a GraphQL API
@pmarreck
pmarreck / migrations_in_console_cheatsheet.exs
Created September 25, 2017 16:47
How to run Ecto migrations in Elixir/Phoenix from an `iex -S mix` or production console
# How to run Ecto migrations from IEx console... Examples
# preliminaries assumed in the following code, change to fit your environment:
alias YourAppName.Repo
your_app_name_as_atom = :mpnetwork
downto_version = 20170724182558
# Down:
Ecto.Migrator.run(Repo, "priv/repo/migrations/", :down, [to: downto_version])
@teamon
teamon / box.ex
Created August 25, 2017 23:09
Define elixir structs with typespec with single line of code
defmodule Box do
defmacro __using__(_env) do
quote do
import Box
end
end
@doc """
Define module with struct and typespec, in single line
@javilobo8
javilobo8 / download-file.js
Last active July 1, 2024 23:21
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);