Skip to content

Instantly share code, notes, and snippets.

View baldrailers's full-sized avatar
🤖

Julius Francisco baldrailers

🤖
  • Paranaque City, PH
View GitHub Profile
@drnic
drnic / Hello.tsx
Created June 15, 2023 23:37
In Rails apps using StimulusJS, load React components found at app/javascript/react/*/index.tsx, and make them available via Ruby helper react(name)
import React from "react";
const Hello = ({ name }: { name: string }) => <span>Hello {name}</span>;
Hello.defaultProps = { name: "World" }
export default Hello;
@alexrudall
alexrudall / #ChatGPT Streaming.md
Last active May 27, 2024 15:20
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!

Alt Text

First, add the ruby-openai gem! Needs to be at least version 4. Add Sidekiq too.

@benkoshy
benkoshy / ransack-post-form-pagy-2.md
Last active May 17, 2024 02:29
Pagy Documentation - Using Stimulus JS

Using Stimulus JS to POST

Whenever you use pagy links that require interception, you will need to reinitialise any javascript that you need to run. If you submit a form, and use a turbo frame to render those search results, and to also render the pagination links to those results, how are you going to reinitialize your javascript code to intercept those pagy page links?

Stimulus JS is very handy for reinitialising javascript code, and is useful if you are using a library like hotwire (by Basecamp) where changes are made to the DOM.

// pagy_controller.js - a stimulus JS controller
import { Controller } from "@hotwired/stimulus"
@aanari
aanari / set-alacritty-default.sh
Last active May 26, 2024 21:34
Set Alacritty as Default Terminal Editor (Ubuntu)
sudo update-alternatives --install /usr/bin/x-terminal-emulator x-terminal-emulator $(which alacritty) 50
sudo update-alternatives --config x-terminal-emulator
@rengler33
rengler33 / scrape_with_logs.py
Last active May 2, 2024 07:30
How to Capture Network Traffic When Scraping with Selenium & Python
# see rkengler.com for related blog post
# https://www.rkengler.com/how-to-capture-network-traffic-when-scraping-with-selenium-and-python/
import json
import pprint
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
capabilities = DesiredCapabilities.CHROME
@jsoverson
jsoverson / intercept.js
Created February 19, 2019 21:28
Intercept responses with chrome and puppeteer
const puppeteer = require('puppeteer');
const prettier = require('prettier');
const atob = require('atob');
const btoa = require('btoa');
const scriptUrlPatterns = [
'*'
]
const requestCache = new Map();
@zparnold
zparnold / one_liner.sh
Last active May 6, 2024 13:14
A simply script to delete all failed pods from Kubernetes
kubectl get pods --all-namespaces | grep Evicted | awk '{print $2 " --namespace=" $1}' | xargs kubectl delete pod
@amishshah
amishshah / har-extract.js
Created February 12, 2017 16:14
Rough script to extract images from HTTP Archive (HAR) files
const fs = require('fs');
const file = JSON.parse(fs.readFileSync('./dump.har')).log;
const targetMimeType = 'image/jpeg';
let count = 1;
for (const entry of file.entries) {
if (entry.response.content.mimeType === targetMimeType) {
// ensure output directory exists before running!
fs.writeFileSync(`output/${count}.png`, new Buffer(entry.response.content.text, 'base64'), 'binary');
count++;
@mdang
mdang / ALEXA.md
Last active December 20, 2019 15:36
Lesson: Alexa