Skip to content

Instantly share code, notes, and snippets.

View formigarafa's full-sized avatar

Rafael Santos formigarafa

View GitHub Profile
#
# Proof of concept - import maps with JSX transpilation. Can trivially
# be extended to TypeScript and all the languages currently supported
# with Sprockets.
#
# There are two parts to this:
# * Have `find_javascript_files_in_tree` in importmap-rails to not only
# find JS files, but also files that can be transpiled to JS.
# * Add sprockets JSX transformer, making use of esbuild
#
@brgaulin
brgaulin / Readme.md
Last active April 19, 2024 10:03
ESP32-S2 Keyboard on Arduino
@rponte
rponte / using-uuid-as-pk.md
Last active April 26, 2024 12:47
Não use UUID como PK nas tabelas do seu banco de dados

Pretende usar UUID como PK em vez de Int/BigInt no seu banco de dados? Pense novamente...

TL;TD

Não use UUID como PK nas tabelas do seu banco de dados.

Um pouco mais de detalhes

@tumainimosha
tumainimosha / page-info.ts
Last active August 29, 2023 11:02
NestJS Graphql Cursor Based pagination
import { ObjectType, Field } from "@nestjs/graphql";
@ObjectType()
export class PageInfo {
@Field({ nullable: true })
startCursor: string;
@Field({ nullable: true })
endCursor: string;
@straker
straker / README.md
Last active April 20, 2024 10:20
Basic Snake HTML and JavaScript Game

Basic Snake HTML and JavaScript Game

Snake is a fun game to make as it doesn't require a lot of code (less than 100 lines with all comments removed). This is a basic implementation of the snake game, but it's missing a few things intentionally and they're left as further exploration for the reader.

Further Exploration

  • Score
  • When the snake eats an apple, the score should increase by one. Use context.fillText() to display the score to the screen
@wbotelhos
wbotelhos / clear-sidekiq-jobs.sh
Last active April 2, 2024 10:04
Clear Sidekiq Jobs
require 'sidekiq/api'
# 1. Clear retry set
Sidekiq::RetrySet.new.clear
# 2. Clear scheduled jobs
Sidekiq::ScheduledSet.new.clear
@matthewrudy
matthewrudy / db-structure-clean.rake
Created February 26, 2017 23:40
Clean differences from your rake db:structure:dump - it seems to work for 9.4, 9.5 and 9.6
# frozen_string_literal: true
namespace :db do
namespace :structure do
STRUCTURE_PATH = 'db/structure.sql'
def clean_structure_file
original = File.read(STRUCTURE_PATH)
cleaned = original.dup
@alassek
alassek / 01_Annotated_Source.md
Last active November 19, 2023 11:53
Extending Arel to support @> operator

I've been doing some work lately with JSON documents in PostgreSQL using jsonb columns. You can query these documents using a GIN index in PG, but the syntax can be a little cumbersome

SELECT "events".* FROM "events" WHERE "events"."body" @> '{"shift":{"user_id":2}}'

You have to construct the right side of the query as a JSON string, which is a bit annoying. So I wondered if I could adapt Arel to do the tedious stuff for me.

@graemeboyd
graemeboyd / gist:cc6f4a325283b8ef03d9
Created November 4, 2015 15:01
Dump Heroku database structure and schema
# Sleep 5 tries to avoid Heroku truncating the output by terminating the connection before everything has transferred.
# Dump structure.sql as heroku_structure.sql
heroku run 'bundle exec rake db:structure:dump && cat db/structure.sql && sleep 5' --app app-name > db/heroku_structure.sql
# Dump schema.rb as heroku_schema.db
heroku run 'bundle exec rake db:schema:dump && cat db/schema.rb && sleep 5' --app app-name > db/heroku_schema.rb
@janko
janko / arel.rb
Created July 28, 2015 00:09
Insert statement in Arel
require "active_record"
ActiveRecord::Base.establish_connection("postgres:///db")
insert = Arel::Nodes::InsertStatement.new
insert.relation = Arel::Table.new(:movies)
insert.columns = hash.keys.map { |k| Arel::Table.new(:movies)[k] }
insert.values = Arel::Nodes::Values.new(hash.values, insert.columns)
ActiveRecord::Base.connection.execute(insert.to_sql)