Skip to content

Instantly share code, notes, and snippets.

View 771991673's full-sized avatar
💭
I may be slow to respond.

James Lau 771991673

💭
I may be slow to respond.
View GitHub Profile
@senstella
senstella / parakeet-nemo-to-mlx.py
Created May 6, 2025 14:04
A simple script to convert NeMo Parakeet weights to MLX.
import torch
from safetensors.torch import save_file
INPUT_NAME = "model_weights.ckpt"
OUTPUT_NAME = "model.safetensors"
state = torch.load(INPUT_NAME, map_location="cpu")
new_state = {}
for key, value in state.items():
import asyncio
import base64
import json
import os
import pyaudio
from websockets.asyncio.client import connect
class SimpleGeminiVoice:
def __init__(self):
@ugik
ugik / data grabber
Created February 26, 2020 17:56
Data grabber for Backtrader
import requests
import json
from datetime import datetime, timedelta
cookies = {'sessionid': 'zw53stv84dn2am47ag5prl0uvh31joz3'}
ETFs =['SPY', 'SH', 'VXX', 'EEM', 'QQQ', 'PSQ', 'XLF', 'GDX', 'HYG', 'EFA', 'IAU', 'XOP', 'IWM', 'FXI', 'SLV', 'USO', 'XLE', 'IEMG', 'AMLP', 'EWZ', 'XLK', 'XLI', 'VWO', 'GLD', 'XLP', 'JNK', 'EWJ', 'XLU', 'VEA', 'IEFA', 'XLV', 'PFF', 'VIXY', 'TLT', 'GDXJ', 'LQD', 'XLB', 'BKLN', 'XLY', 'SMH', 'OIH', 'ASHR', 'RSX', 'MCHI', 'VTI', 'EWH', 'SPLV', 'KRE', 'IVV', 'DIA', 'IEF', 'EZU', 'EWT', 'SPDW', 'VOO', 'SCHF', 'EWY', 'MYY', 'DOG', 'EUM']
for ticker in ETFs:
period = 365
endDate = datetime.today().strftime('%Y-%m-%d')
startDate = (datetime.today() - timedelta(days=period)).strftime('%Y-%m-%d')
url = "https://api.tiingo.com/tiingo/daily/%s/prices?startDate=%s&endDate=%s" % (ticker, startDate, endDate)
@rstml
rstml / crop.md
Last active June 9, 2023 06:02
Keras center and random crop support for ImageDataGenerator

Keras center and random crop support for ImageDataGenerator

preprocess_crop.py script below adds center and random crop to Keras's flow_from_directory data generator.

It first resizes image preserving aspect ratio and then performs crop. Resized image size is based on crop_fraction which is hardcoded but can be changed. See crop_fraction = 0.875 line where 0.875 appears to be the most common, e.g. 224px crop from 256px image.

Note that the implementation has been done by monkey patching keras_preprocessing.image.utils.loag_img function as I couldn't find any other way to perform crop before resizing without rewriting many other classes above.

Due to these limitations, the cropping method is enumerated into the interpolation field. Methods are delimited by : where the first part is interpolation and second is crop e.g. lanczos:random. Supported crop methods are none, center, random. When no crop method is specified, none is assumed.

@korakot
korakot / selenium.py
Last active November 21, 2024 06:30
Use selenium in Colab
# install chromium, its driver, and selenium
!apt update
!apt install libu2f-udev libvulkan1
!wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
!dpkg -i google-chrome-stable_current_amd64.deb
!wget https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/118.0.5993.70/linux64/chromedriver-linux64.zip
!unzip -j chromedriver-linux64.zip chromedriver-linux64/chromedriver -d /usr/local/bin/
!pip install selenium chromedriver_autoinstaller
# set options to be headless, ..
@kenwoodjw
kenwoodjw / flask_upload.py
Created April 10, 2018 03:04
flask upload image return image base64
#coding:utf-8
import os,io
from flask import Flask, request, redirect, url_for,Response,render_template,send_file,make_response,jsonify,send_from_directory
from werkzeug import secure_filename
from flask_cors import CORS,cross_origin
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
UPLOAD_FOLDER = os.path.join(APP_ROOT, 'static\\upload')
@Deub27
Deub27 / UIStackView+removeAll.swift
Created November 25, 2017 14:00
Remove all arranged subviews from UIStackView at once
import UIKit
extension UIStackView {
func removeAllArrangedSubviews() {
let removedSubviews = arrangedSubviews.reduce([]) { (allSubviews, subview) -> [UIView] in
self.removeArrangedSubview(subview)
return allSubviews + [subview]
}
@morishin
morishin / left-align-stack-view.png
Last active March 22, 2024 00:25
Align to Left the contents of UIStackView
left-align-stack-view.png
@simoncos
simoncos / miniconda_on_rpi.md
Last active October 7, 2024 11:50
Install Miniconda 3 on Raspberry Pi
@RaminNietzsche
RaminNietzsche / image_stof.py
Created April 9, 2017 10:57
Python flask upload base64 image
import base64
from io import BytesIO
from PIL import Image
file = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAcAAAAHACAYAAAA1JbhzAAAgAElEQVR4Xoy96ZKt3XKVt5p97pmgMSDAdI6wABMWdiB+yEgQQoBN38h34HMkjiTEraCqtYgc4xmZOd+qT+EtON/eVWu9zZzZjBzZzPuf+Y2fv+/v2+19e91u98ftcb/dPl/v2/N2v71v79vtdr/Vb+s/79dNfx6P2+31ft/u9/pd/fau79W/3++60ut2fz1ut4e/7c/oJvrM/f6+vd/32+N9u32+b7rXq65/e90e9/re+/aqX9Rn+b7+w/1ubz+Zf1T3vt9eLz9cninfrWeuF6zn0mfrWd5ctV6cN6z3edyft9f7k2f0c75u79vj9tSz1bff70/97FnP+ao3rcd91EvUwun56xO1IHlGrdn9x+19+6yFu9Vb1RvkWe+v9+398HrUf+tVtMZcoR5Tz32v+7/0NJ999R+35+2z/13Xut/rYW5a07qK//eu79Uz1Xp/1lPUhete7/utlqT++al98P77+/lTT+Br1XPWs2kv65lrP0oAstestaRHH6h7WTYe9bs361wXuj18LV3zfnve57m1T6/b7VnXrjUq2by9bz/qWWu5tY48T/2s9roeMz971bVqvfIutX7elfqZJful69Sf+p3ur/evfaxrzi6+63k/7tprfRe5q2vVn+zJo/5dz/L0Netr9f4fklGvWcmsZarWxd/V52rj37W/dU0/u69bP3/d7qVfev/77V6y8raEavV41Fon3VfX9nUka6UHein//zeyohW4l3RoEdBWXQQLUM9dMuUb1Ecsu++2A+9Xyf7T+lA/r/dHDu6lz+icf1bPW+vw0p56S7APWleLWq3vo97x86131f3Qn9ipeo96z3qtkpHS+/f9pWtKFPQ6tRYlZ/V/slYtuyUfdcO6V62tzCDrV+8ou1