Skip to content

Instantly share code, notes, and snippets.

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

Gabriel Chuan gczh

🏠
Working from home
View GitHub Profile
@wilsonowilson
wilsonowilson / settings.json
Created January 2, 2024 14:56
Minimal Vscode w/ APC extension
{
"workbench.colorTheme": "Aura Dark",
"workbench.iconTheme": "material-icon-theme",
"editor.fontFamily": "'Geist Mono', Menlo, Monaco, 'Courier New', monospace",
"apc.listRow": {
"height": 24,
"fontSize": 11
},
"window.titleBarStyle": "native",
"apc.font.family": "Geist Mono",
@alexrudall
alexrudall / #ChatGPT Streaming.md
Last active July 2, 2024 22:32
ChatGPT streaming with ruby-openai, Rails 7, Hotwire, Turbostream, Sidekiq and Tailwind!

How to add ChatGPT streaming to your Ruby on Rails 7 app!

This guide will walk you through adding a ChatGPT-like messaging stream to your Ruby on Rails 7 app using ruby-openai, Rails 7, Hotwire, Turbostream, Sidekiq and Tailwind. All code included below!

Want more content like this, for free? Check out my free book, RailsAI!

Alt Text

@thorpj
thorpj / popup_controller.js
Last active August 13, 2023 22:00
StimulusJS Controller for popups using tippy.js.
import ApplicationController from './application_controller';
import tippy from 'tippy.js';
import 'tippy.js/dist/tippy.css';
// Inspired by https://chrislabarge.com/posts/stimulus-popup/
// NOTE: ApplicationController must have `this.element[this.identifier] = this;` in the connect() method.
/*
// Manually set content and trigger
// 'data-popup-trigger': :manual is optional. When no content is given, the controller isn't going to show a popup on mouseenter or click
# mailboxes/concerns/mail_params.rb
module MailParams
extend ActiveSupport::Concern
def mail_params
attachments = build_attachments
body = build_rich_body(attachments)
{ subject: mail.subject, body: body, attachments: attachments.map { |a| a[:blob] } }
end
@caendekerk
caendekerk / Gemfile
Created March 4, 2021 10:48
Rails API only with Okta but without Devise
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.0'
# Shorten boot time
gem 'bootsnap'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', github: 'rails/jbuilder'
@jaredcwhite
jaredcwhite / README.md
Last active April 21, 2024 14:28
Use Shoelace Form Components with Hotwire Turbo

This is a Stimulus controller which will allow a Shoelace Form component to be processed and submitted by Turbo.

Just wrap your <sl-form> control with a form tag:

<%= form_with url: "/test-submit" do %>
  <sl-form data-controller="shoelace-form">
    controls go here
  </sl-form>
&lt;% end %&gt;
@obie
obie / _search.haml
Created November 5, 2020 01:24
Search Implementation using stimulus, shoelace, and mark.js
.spreadsheet--search.grid.grid-flow-col.grid-cols-auto.gap-0.auto-cols-fr.pl-1.pr-8.hidden{ data: { controller: "spreadsheet--search", action: "toggle-search@window->spreadsheet--search#toggleSearch" }}
.input.col-span-9.p-2
%sl-input.w-full(placeholder="Search" size="small" clearable pill){ data: { target: "spreadsheet--search.input"}}
%sl-icon(name="search" slot="prefix")
%sl-dropdown(slot="suffix" placement="bottom-end" hoist){ data: { target: "spreadsheet--search.dropdown"}}
%sl-button(slot="trigger" caret type="text" size="small"){ data: { target: "spreadsheet--search.trigger"}} Highlight
%sl-menu
%sl-menu-item{ data: { target: "spreadsheet--search.higlight"}, checked: true} Highlight
%sl-menu-item{ data: { target: "spreadsheet--search.filter"}} Filter
@jesster2k10
jesster2k10 / README.md
Last active May 6, 2024 18:16
Rails API Social Login

Rails API-Only Social Login

This is another piece of code I've extrapolated from a Ruby on Rails project I'm currently working on. The code implmenets social login with a RoR API-based application, targeted at API clients.

The setup does not involve any browser-redirects or sessions as you would have to use working with Omniauth. Instead, what it does is takes an access_token generated on client-side SDKs, retireves user info from the access token and creates a new user and Identity in the database.

This setup works with native applications as described in the Google iOS Sign In Docs (see Authenticating with a backend server)

@jesster2k10
jesster2k10 / README.md
Last active July 11, 2024 08:48
JWT Auth + Refresh Tokens in Rails

JWT Auth + Refresh Tokens in Rails

This is just some code I recently used in my development application in order to add token-based authentication for my api-only rails app. The api-client was to be consumed by a mobile application, so I needed an authentication solution that would keep the user logged in indefinetly and the only way to do this was either using refresh tokens or sliding sessions.

I also needed a way to both blacklist and whitelist tokens based on a unique identifier (jti)

Before trying it out DIY, I considered using:

@adriaandotcom
adriaandotcom / aa-readme.md
Last active December 17, 2019 16:54
Run AB-tests without cookies and IPs

Goal

I'm creating AB-tests and want to have a client side JavaScript function that returns a small integer. The integer will be the same every time the same user connects to my website. I don't want to use cookies, localStorage or IPs for this. Just a very simple hash with the user agent and maybe a few more variables.

Read more on Twitter: https://twitter.com/AdriaanvRossum/status/1198102973114654720

Results

We tested all convert to int functions with the dataset from agents.js, these are the results: