Skip to content

Instantly share code, notes, and snippets.

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

Cristian Molina megatux

🏠
Working from home
View GitHub Profile
@megatux
megatux / setup.sh
Created March 14, 2024 23:24
sample-02_bun_tw_phlex_htmx setup
rails new sample-02_bun_tw_phlex_htmx -j bun -c tailwind -d sqlite3 --skip-hotwire --skip-jbuilder --skip-bootsnap
bin-/bundle add rails-htmx
bin/bundle add phlex-rails
bin/rails generate phlex:install
bin/bundle add tailwindcss-rails
@megatux
megatux / article_component.rb
Last active March 15, 2024 03:11
sample-02_bun_tw_phlex_htmx article_component.rb
require "faker"
class ArticleComponent < ApplicationComponent
def template
article(class: "mb-2 bg-blue-600 rounded border-solid border-2 border-black item-article") {
h3(class: "text-left text-slate-200 pl-2 font-semibold") {
i { Faker::Lorem.sentence }
}
p(class: "bg-slate-200 p-4") { Faker::Lorem.paragraph }
}
@megatux
megatux / index_view.rb
Last active March 15, 2024 03:17
sample-02_bun_tw_phlex_htmx index_view.rb
class Articles::IndexView < ApplicationView
HEAD_STYLE = "p-2 font-mono font-bold font-lg font-bold"
BUTTON_STYLE = "font-mono rounded border-2 border-black bg-indigo-200 p-1 text-sm transition-colors focus-ring-2 focus:ring-indigo-800 hover:bg-indigo-100"
def template
div(class: "h-16 flex items-center justify-between") {
h1(class: HEAD_STYLE) { "Articles index" }
button("hx-post": articles_path, "hx-target": "#article-list", "hx-swap": "afterbegin",
class: BUTTON_STYLE) {
@megatux
megatux / articles_controller.rb
Created March 14, 2024 23:19
sample-02_bun_tw_phlex_htmx articles_controller.rb
class ArticlesController < ApplicationController
layout -> { ApplicationLayout }
def index
render Articles::IndexView.new
end
def create
render ArticleComponent.new, layout: false
end
@megatux
megatux / application_layout.rb
Created March 14, 2024 22:50
sample-02_bun_tw_phlex_htmx application_layout.rb
class ApplicationLayout < ApplicationView
include Phlex::Rails::Layout
def template(&block)
doctype
html do
head do
title { "Rails demo" }
meta name: "viewport", content: "width=device-width,initial-scale=1"
@megatux
megatux / Convert PostgreSQL to SQLite
Last active July 23, 2023 19:30 — forked from fiftin/Convert PostgreSQL to SQLite
Convert PostgreSQL to SQLite
1. Dump the data only sql to file
$ pg_dump --data-only --inserts YOUR_DB_NAME > dump.sql
2. scp to local
3. Remove the SET statements at the top
such as:
SET statement_timeout = 0;
SET client_encoding = 'SQL_ASCII';
4. Remove the setval sequence queries
$gtk.reset
class TetrisGame
# This is just to get GTK to not complain in the console for now.
def serialize ; { args: '' } ; end
def inspect ; serialize.to_s ; end
def to_s ; serialize.to_s ; end
def render_cube_pixelpos x, y, r, g, b, a=255
@args.outputs.solids << [ x, y, @boxsize, @boxsize, r, g, b, a ]
@megatux
megatux / main.rb
Created June 21, 2023 02:07 — forked from icculus/main.rb
Tetris in DragonRuby, code at the end of Part 2
$gtk.reset
class TetrisGame
def initialize args
@args = args
@next_piece = nil
@next_move = 30
@score = 0
@gameover = false
@grid_w = 10
@megatux
megatux / .editorconfig
Created May 11, 2022 12:18 — forked from JamesMGreene/.editorconfig
Example EditorConfig file
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
root = true
[*]
end_of_line = lf
charset = utf-8
@megatux
megatux / s3_folder_upload.rb
Last active January 22, 2021 14:24 — forked from leemour/s3_folder_upload.rb
Upload folder to S3 recursively with ruby, multi threads and aws-sdk v3 gem
# frozen_string_literal: true
require 'rubygems'
require 'aws-sdk'
module S3
# Upload directory recursively to S3
class DirectoryUpload
attr_reader :folder_path, :bucket, :include_folder
attr_accessor :files