Skip to content

Instantly share code, notes, and snippets.

@mosleymos
mosleymos / ChatGPT Canvas HTML Renderer from Clipboard.url
Created October 7, 2024 15:18 — forked from rmtbb/ChatGPT Canvas HTML Renderer from Clipboard.url
Chrome Bookmarklet the lets you render a full HTML page with any included css and javascript that is currently copied to your clipboard. Also works for SVG code. Useful with ChatGPT Canvas
javascript:(function(){try{navigator.clipboard.readText().then(function(clipboardText){if(clipboardText){var newWindow=window.open("","_blank","width=800,height=600");newWindow.document.open();newWindow.document.write(clipboardText);newWindow.document.close();}else{alert('Clipboard is empty. Please copy some text to the clipboard first.');}}).catch(function(err){console.error('Failed to read clipboard contents: ',err);alert('An error occurred while trying to access the clipboard. Please ensure your browser allows clipboard access.');});}catch(e){console.error('An error occurred:',e);alert('An error occurred while trying to open the new window with the clipboard content.');}})();
@mosleymos
mosleymos / sidekiq_transfer.rake
Created November 13, 2023 10:19 — forked from jfilipe/sidekiq_transfer.rake
Rake task to transfer Sidekiq jobs from one redis instance to another
# This task should be run inside an environment that is already configured to connect to the redis
# instance that we're transfering AWAY FROM.
#
# The task should be handed the URL of the redis instance that we're MOVING TO.
#
# To run it and pass in the destination Redis you'd do something like this:
# rake sidekiq:transfer[redis://...]
#
# As jobs are added to the destination Redis, they're deleted from the source Redis. This
# allows the task to be restarted cleanly if it fails in the middle due to a network error
@mosleymos
mosleymos / redis.yml
Created November 5, 2023 12:29 — forked from idyll/redis.yml
defaults:
:port: 6379
:host: localhost
development:
:db: 2
:namespace: development
# force use of Redis::Distributed
:host:
- localhost
@mosleymos
mosleymos / rails-docker
Created November 5, 2023 12:29 — forked from davidtolsma/rails-docker
This sets up docker for rails with nginx, postgres, redis, sidekiq, and action_cable, # rails 6.1 # ruby 2.7.2 # required gems: pg, redis, sidekiq # requires config/sidekiq.yml config/initializers/sidekiq.rb cable/config.ru
# rails app:template LOCATION='https://gist.github.com/davidtolsma/3af8f8961abe3a635e41776fe2f3af54/raw'
# This sets up docker for rails with nginx, postgres, redis, sidekiq, and action_cable
# rails 6.1
# ruby 2.7.2
# required gems: pg, redis, sidekiq
# requires config/sidekiq.yml config/initializers/sidekiq.rb cable/config.ru
create_file 'docker/nginx/Dockerfile' do <<~YAML
@mosleymos
mosleymos / conf-server-and-deploy-rails.md
Created November 5, 2023 12:29 — forked from pedromschmitt/conf-server-and-deploy-rails.md
Setting up a new server and deploy Ruby

Setting up a new server and deploy Ruby on Rails project with Capistrano on VPS (Digital Ocean/Hetzner/etc)

This use Rails 5 or 6, RVM and Puma.

If you want to deploy with RBenv and Passenger, take a look at Phyl Smy script https://github.com/philsmy/cable-guy-example/blob/main/SetUpServer.txt and his video where he recorded each step https://www.youtube.com/watch?v=CZtYDplotiI&t=1s

If you need to deploy to a EC2 on AWS, check this video of how to create the server first: https://www.youtube.com/watch?v=M0avxObh8J8

Script

Dependencies

@mosleymos
mosleymos / rdb2proto.py
Created November 3, 2023 17:19 — forked from jdp/rdb2proto.py
dump redis protocol from rdb file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import calendar
import sys
import rdbtools
def emit_protocol(*args):

11.17/18.2021 - SDC

Challenge: Optimization 2 (Load balancing)

Action

  • Probably doing caching first is not the best option. I now realize if I have morethan one server, they should be sharing one single redis store and one single databae. Currently my database and my redis store live on the same instance as my server, which is not the ideal architecture. So I re-designed my architecture.
  • Before: Screen Shot 2021-11-18 at 2 36 23 PM
  • After: Screen Shot 2021-11-18 at 2 18 58 PM
  • I now have 5 instances for the backend service. One for load balancer, two for my servers, one for redis and one for database.
  • Need to be careful about security group settings. Both of the two servers need to allow traffic from the load balancer, redis needs to allow traffic from th
@mosleymos
mosleymos / Dockerfile
Created October 16, 2023 15:10 — forked from mdoyle13/Dockerfile
Rails 6, ruby 2.7 Docker for Development
FROM ruby:2.7
RUN apt-get update && apt-get install -y \
curl \
build-essential \
libpq-dev &&\
curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && apt-get install -y nodejs yarn vim
@mosleymos
mosleymos / nixos_in_virtualbox.md
Created April 1, 2023 18:32 — forked from johnrichardrinehart/nixos_in_virtualbox.md
NixOS from "scratch" as Virtualbox Guest

Steps

New VirtualBox Machine

  1. Create a new disk image (I use VDI for compatibility with VirtualBox)
  2. Allocate some RAM (>6 GiB to start)
  3. Add some video memory and enable 3D acceleration, if needed
  4. Optional: Enable EFI (instead of BIOS)
  5. Attach nixos-minimal ISO for installation
  6. Boot into the ISO

Inside the Live CD

UEFI instructions

@mosleymos
mosleymos / rails_in_nix-shell.md
Created July 9, 2022 17:51 — forked from bobvanderlinden/rails_in_nix-shell.md
Running Rails through nix-shell

Use the following to generate gemset.nix:

nix run nixpkgs.bundix --command bundix

Then run:

nix-shell