Skip to content

Instantly share code, notes, and snippets.

@radames
radames / README.md
Last active March 4, 2024 06:44
How to connect to your Google Colab Notebook via SSH!

Connect to your Google Colab Notebook via SSH

Using this amazing project tmate.io you can SSH tunnel to your colab notebook machine. You can with few lines of code download the binary, run an instance in the background and output the generated SSH address.

!wget -nc https://github.com/tmate-io/tmate/releases/download/2.4.0/tmate-2.4.0-static-linux-i386.tar.xz &> /dev/null
!tar --skip-old-files -xvf tmate-2.4.0-static-linux-i386.tar.xz &> /dev/null
!rm -f nohup.out; bash -ic 'nohup ./tmate-2.4.0-static-linux-i386/tmate -S /tmp/tmate.sock new-session -d & disown -a' >/dev/null 2>&1
!./tmate-2.4.0-static-linux-i386/tmate -S /tmp/tmate.sock wait tmate-ready
@radames
radames / umap_learn_on_apple_silicon.md
Created April 6, 2022 05:22
How to install umap-learn on Apple Silicon M1
# https://github.com/numba/llvmlite/issues/693#issuecomment-909501195
brew install llvm@11   
LLVM_CONFIG="/opt/homebrew/Cellar/llvm@11/11.1.0_4/bin/llvm-config" arch -arm64 pip install llvmlite

pip install umap-learn
@radames
radames / grid.js
Created May 24, 2023 06:48
Amethyst Custom Layout Simple Square Grid
function layout() {
return {
name: "Grid",
getFrameAssignments: (windows, screenFrame) => {
const numWindows = windows.length;
const numRows = Math.floor(Math.sqrt(numWindows));
const numCols = Math.ceil(Math.sqrt(numWindows));
const cellWidth = screenFrame.width / numCols;
const cellHeight = screenFrame.height / numRows;
@radames
radames / opencv_video_to_pygame.py
Last active April 17, 2023 15:34
OpenCV VideoCapture running on PyGame - repo ref https://github.com/radames/opencv_video_to_pygame
from pygame.locals import KEYDOWN, K_ESCAPE, K_q
import pygame
import cv2
import sys
camera = cv2.VideoCapture(1)
pygame.init()
pygame.display.set_caption("OpenCV camera stream on Pygame")
screen = pygame.display.set_mode([1280, 720])
@radames
radames / api-inference-Stable-Diffusion.py
Created February 1, 2023 20:16
Save Image from API inference Stable Diffusion on Hugging Face in Python
import json
import requests
from PIL import Image
import io
import re
from time import time
API_TOKEN = "" # token in case you want to use private API
headers = {
# "Authorization": f"Bearer {API_TOKEN}",
@radames
radames / a-bookmark-stable-diffusion-ui.MD
Last active February 1, 2023 01:57
Minimal Stable Diffusion UI as a browser bookmark

Bookmark this javascript code to make the minimal Stable Diffusion UI thanks to @huggingface inference API pic.twitter.com/i1slI4ObdH

— Radamés Ajna (@radamar) February 1, 2023
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

Bookmark this code

javascript:p=prompt("Enter your prompt:");fetch("https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5",{method:"POST",headers:{"content-type":"application/json","X-Wait-For-Model":"true"},body:JSON.stringify({inputs:p})}).then(e=&gt;e.blob()).then(e=&gt;window.open(URL.createObjectURL(e),"_self"))

@radames
radames / opencv_video_to_pygame_raspberry_pi.py
Last active August 11, 2022 17:55
OpenCV VideoCapture running on PyGame on Raspberry PI
import pygame
from pygame.locals import *
import cv2
import numpy as np
import time
import picamera
import picamera.array
screen_width = 640
@radames
radames / Planet_Kronos_x8.ino
Last active June 25, 2022 13:56
Sample code for controlling a motor via OSC messages using Arduino and Ethernet Shield
//Planet_Kronos_x8 The Kazimier Dezember 2015
//The MIT License (MIT)
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <OSCBundle.h>
#define DEBUG 1
@radames
radames / timerArduino.ino
Last active July 10, 2021 18:47
Simple Arduino Hour Minute counter
long lastTime = 0;
long minutes = 0;
long hours = 0;
void setup() {
}
void loop() {
@radames
radames / python_opencv_camera_haar.py
Last active January 5, 2021 14:25
Example of Python with Opencv and camera face detection - repo complete https://github.com/radames/python_opencv_camera_haar
import cv2
cap = cv2.VideoCapture(0)
cap.set(3, 640) # WIDTH
cap.set(4, 480) # HEIGHT
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_eye.xml")
while(True):