Skip to content

Instantly share code, notes, and snippets.

@mfa777
mfa777 / worker.js
Last active May 11, 2025 08:54
Use Cloudflare Worker as Proxy for Gemini API Access
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
// 1. Define the target Google API base URL
const targetApiUrl = 'https://generativelanguage.googleapis.com';
// 2. Get the original path and query string from the incoming request
const url = new URL(request.url);
@mfa777
mfa777 / ffprobe.sh
Last active May 13, 2024 17:43
How to check if mp4 is complete
# Relying solely on file size to determine if an MP4 file is complete can be unreliable,
# especially if the download process gets interrupted.
ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 your_video.mp4
# how to use ffprobe to check all MP4 files in the current folder
for file in *.mp4; do
if ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$file" > /dev/null 2>&1; then
echo "$file: OK"
else
@mfa777
mfa777 / create_dns_records.rb
Last active October 7, 2023 20:49
Create one same DNS record for multiple domains on cloudflare
# Description:
# An interactive script for setting DNS records for domains in `domains.txt`.
# The script fetches zones from Cloudflare, prompts the user for DNS type
# (A or AAAA), the corresponding IP value, and a comment (with a shortcut
# for "N2 address"). It then creates the specified DNS record for each
# domain in the file matching with the Cloudflare zones. Ideal for batch
# setting DNS records.
require 'http'
require 'json'
@mfa777
mfa777 / add-multiple-zones.sh
Created October 7, 2023 18:01
Add multiple domains for cloudflare
#!/bin/bash
# Define global variables
CLOUDFLARE_EMAIL="<CLOUDFLARE_EMAIL>"
API_KEY="<API_KEY>"
ACCOUNT_ID="<ACCOUNT_ID>"
DOMAINS_FILE="domains.txt"
# Main script
for domain in $(cat $DOMAINS_FILE); do
@mfa777
mfa777 / ssh_yubikey.org
Last active December 4, 2022 01:19
Windows 10 support SSH YubiKey FIDO2

Upgrade SSH version

Download Powershell ssh version to update openssl to 8.2+ https://github.com/PowerShell/Win32-OpenSSH/releases/

Make sure download zip version. Here we assume you download OpenSSH-Win64.zip.

Replace windows 10 default ssh

  1. Copy the following code and save it as script.ps1
  2. Open you powershll, change location to download folder, type & .\script.ps1 .
@mfa777
mfa777 / loading.org
Created March 2, 2021 17:43 — forked from TheBB/loading.org
Loading in Spacemacs

Emacs packages, features, files, layers, extensions, auto-loading, require, provide, use-package… All these terms getting you confused? Let’s clear up a few things.

Files

Emacs files contains code that can be evaluated. When evaluated, the functions, macros and modes defined in that file become available to the current Emacs session. Henceforth, this will be termed as loading a file.

One major problem is to ensure that all the correct files are loaded, and in the

@mfa777
mfa777 / spacemacs-cheatsheet.txt
Created March 2, 2021 17:42 — forked from k3yavi/spacemacs-cheatsheet.txt
Spacemacs cheatsheet
//from http://www.saltycrane.com/blog/2015/12/switching-emacs-vim-actually-spacemacs/
Useful Spacemacs commands
SPC q q - quit
SPC w / - split window vertically
SPC w - - split window horizontally
SPC 1 - switch to window 1
SPC 2 - switch to window 2
SPC w c - delete current window
@mfa777
mfa777 / Spacemacs on Windows 10.md
Created January 15, 2021 10:04 — forked from cdaven/Spacemacs on Windows 10.md
Setting up Spacemacs on Windows 10

Install Emacs First

Download emacs-w64 and extract somewhere, e.g. a tools or apps folder like C:\Users\<user>\tools\emacs.

Select Emacs' Home

Emacs and many other applications store its configuration in the user's "home" folder. Translated directly from the Unix world, that is %UserProfile% (C:\Users\<user>), but Windows prefers %AppData% instead (C:\Users\<user>\AppData\Roaming).

For simplicity's sake, override this by specifying the HOME environment variable explicitly. Emacs and some other applications (e.g. MinGW) lets this override the default.

Render and Redirect

The normal controller/view flow is to display a view template corresponding to the current controller action, but sometimes we want to change that. We use render in a controller when we want to respond within the current request, and redirect_to when we want to spawn a new request.

Render

The render method is very overloaded in Rails. Most developers encounter it within the view template, using render :partial => 'form' or render @post.comments, but here we'll focus on usage within the controller.

:action

@mfa777
mfa777 / Weighted_Random_Sample.rb
Last active June 2, 2017 03:34
带权重的随机选取 Ruby 版
def rand_from_weighted_hash hash
total_weight = hash.inject(0) { |sum,(weight,v)| sum+weight }
running_weight = 0
n = rand*total_weight
hash.each do |weight,v|
return v if n > running_weight && n <= running_weight+weight
running_weight += weight
end
end