HomeAboutPostsTagsProjectsRSS

Updated
Words156
TagsRead1 minute

This tool Eruda: Console for Mobile Browsers is handy for examining HTML elements on mobile devices without any installation. Simply copy and paste the code below into the address bar, an icon will show up on the screen.

javascript:(function () { var script = document.createElement('script'); script.src="[](https://cdn.jsdelivr.net/npm/eruda";) document.body.append(script); script.onload = function () { eruda.init(); } })();

Updated
Words603
TagsRead1 minute

RoutineHub • Elevate Mobile Coding Together with Apple Shortcuts amazing resources for iOS shortcuts, one thing particularly useful is that the website can browse by App. Those shortcuts that use Scriptable on the App Store and a-Shell mini on the App Store Truly elevate automation capabilities on iOS to a new level. By combining these tools, you can accomplish complex tasks entirely on your iPhone.

a-shell notably supports Python, which is relevant given Python’s ongoing discussions about adding Tier 3 support for the iOS platform in version 3.13. PEP 730 .

The focus is on “embedded mode”, since there are no stdout on iOS and you can’t provide things like the Python REPL

What’s up Python? iOS support, ruff gets black, flask 3.0…

Updated
Words76
TagsRead1 minute

When using the a-shell action in iOS Shortcuts to execute shell commands or Python scripts, it is often necessary to wait for the execution to finish before continuing to execute other actions.

This can be achieved by using the open shortcuts:// command as the last step in the a-shell action and adding a Wait for Return action afterwards. This combination allows for waiting until a-shell finishes executing a long-running process before proceeding with other actions.

Updated
Words581
TagsRead3 minutes

I use this prompt to study German. Whenever I encounter a new German word, I ask ChatGPT to explain it to me. This prompt works particularly well with GPT-4.

When I enter a German word, your task is to provide a comprehensive analysis of that word. The analysis includes the following segments:

1. Meaning and Usage: Explanation of the word's meaning and common usage scenarios.
2. Linguistic Analysis: Analysis of the word's structure including any prefix, root, and suffix, and its etymology if applicable.
3. Comparisons between German and English: Highlighting any similarities or differences between the German word and its English counterpart.
4. Cultural Context: Any pertinent cultural context related to the word, if applicable.
5. Example Sentences: Providing sentences to illustrate the word's usage.
6. Memory Tips: Suggestions for remembering the word's meaning and usage.
7. Additional Vocabulary: Providing related words, synonyms, or antonyms to broaden vocabulary knowledge.
8. Gender and Plural (for nouns): Indicating the gender of the noun and its plural form, if applicable.
9. Conjugation (for verbs): Present tense conjugation, if applicable.

Refer to this format to provide a thorough understanding of the inquired German word, aiding in learning and retention of the word and related vocabulary.

Here is an example.

Input: Anzeige

The German noun "Anzeige" translates to "advertisement," "display," or "notification" in English, depending on the context. It's often used to refer to advertising materials, displays on devices, or formal notifications, such as reporting a crime. Here’s a detailed analysis of the word:

### 1. **Meaning and Usage:**
   - **Advertisement:** "Anzeige" can refer to an advertisement in a newspaper, magazine, or online platform.
   - **Display:** It can also denote a display on devices such as computers, phones, or other electronic gadgets.
   - **Notification/Report:** In a legal or formal context, "Anzeige" can refer to a notification or a report, often related to reporting incidents to authorities.

### 2. **Linguistic Analysis:**
   - Compound Word: "Anzeige" is derived from "anzeigen," a verb which means "to display," "to indicate," or "to report."

### 3. **Gender:**
   - "Anzeige" is a feminine noun, thus it is "die Anzeige."

### 4. **Comparisons between German and English:**
   - The multiple meanings of "Anzeige" in German align with various English terms such as "advertisement," "display," and "notification" based on context.

### 5. **Cultural Context:**
   - "Anzeige" is a common term used in various contexts in German-speaking countries, whether it's in advertising, technology, or legal realms.

### 6. **Example Sentences:**
   - Ich habe eine Anzeige in der Zeitung geschaltet. (I placed an advertisement in the newspaper.)
   - Die Anzeige des Telefons zeigt einen niedrigen Batteriestand. (The display of the phone shows a low battery level.)
   - Er hat eine Anzeige gegen den Dieb erstattet. (He filed a report against the thief.)

### 7. **Memory Tips:**
   - Associating "Anzeige" with visuals or formal notifications can help in remembering its various meanings.
   - Relating "Anzeige" to its verb form "anzeigen" (to display, to indicate, to report) can also serve as a mnemonic aid.

### 8. **Additional Vocabulary:**
   - Die Werbung (the advertising, feminine): A general term for advertising.
   - Der Bildschirm (the screen, masculine): Referring to the display screen of electronic devices.
   - Die Meldung (the report, notification, feminine): A term often used for notifications or reports.

This analysis should provide a thorough understanding of "Anzeige" and its usage in German. If there are any further inquiries or if you need more examples, feel free to ask!

Updated
Words791
TagsRead2 minutes

Introduction

In a Django application deployed with gunicorn, it is important to optimize the handling of database connections to improve performance and efficiency. This post explores the behavior of gunicorn in relation to database connections and provides insights on how to reuse connections effectively.

Django + Gunicorn

Improtant note about Django ORM is that Django ORM does not have a build-int database connection pool like SQLAlchemy. The lifetime of the persistant connections are controlled by the CONN_MAX_AGE , the default value is 0.

The Sync Worker Class

In the case where CONN_MAX_AGE is set to 0, a new database connection is created for every HTTP request and closed at the end of each request. This can potentially lead to increased overhead due to the constant creation and closure of connections.

However, if CONN_MAX_AGE is set to a value greater than 0, the database connection is not closed immediately after the request is finished. In gunicorn’s sync worker class, which is process-based with a fixed number of processes, subsequent requests will be processed by the same processes, keeping the number of database connections stable.

The Async Worker Class: eventlet and gevent

For the default case where CONN_MAX_AGE is 0, there are no issues as connections are closed at the end of each request.

However, if CONN_MAX_AGE is not 0, problems can arise. In gunicorn’s async worker class, such as eventlet and gevent, each new HTTP request creates a new greenlet thread to handle it. Each thread maintains its own connection, leading to an accumulation of database connections over time.

To tackle this issue, the official gunicorn documentation recommends using the gevent worker and activating greenlet support for Psycopg2 when connecting to PostgreSQL. This can be achieved using the psycogreen library.

References

For more information, refer to the following resources:

Updated
Words798
TagsRead1 minute

Overview

This guide provides step-by-step instructions for installing and enabling content caching for a macOS virtual machine (VM) in Proxmox.

Install a macOS VM

Follow the tutorial here to install a macOS VM in Proxmox.

Enable Content Caching

If you encounter difficulties enabling content caching through the Sharing menu, follow the instructions provided here .

Registration

If you are unable to register and receive a “Content Caching is temporarily unavailable” message, follow these steps:

  1. Post-install OpenCore configuration.
  2. Fix GenSMBios by following the steps here .
  3. Fix en0 by verifying en0 as build-in. Details can be found here .

Image: en0

  1. Fix ROM by following the steps here .

  2. Reboot your VM and verify the content caching status.

    Reboot and verify the content caching status, you should be seen Activated: true and Active: true

> AssetCacheManagerUtil status

Content caching status:
    Activated: true
    Active: true
    ActualCacheUsed: 2.79 GB
    CacheDetails: (3)
        iCloud: 23.86 GB
        Mac Software: 211.7 MB
        Other: 701.7 MB
    CacheFree: 14.28 GB
    CacheLimit: 45 GB
    CacheStatus: OK
    CacheUsed: 24.77 GB

Image: Content Caching Status

For additional information and discussion, refer to the Reddit post .

Updated
Words284
TagsRead1 minute

Problem

The Gigabyte Z390 motherboard fails to detect a connected hard disk drive (HDD) in the BIOS settings.

Issue Specifics

When changing the SATA port after saving the BIOS settings, the HDD is not recognized. This issue may arise when connecting or rearranging SATA devices in the system.

Solution

To resolve this problem, perform a CMOS reset and reboot the system. This allows the BIOS to correctly detect the SATA port and associated devices.

Instructions

  1. Locate the CMOS reset pins on the Gigabyte Z390 motherboard.
  2. Use a screwdriver to short the two CMOS reset pins together.
  3. Reboot the system and enter the BIOS settings again.
  4. The BIOS should now be able to read the connected SATA configuration properly.

Additional Information

This issue seems to be specific to the Gigabyte Z390 Designare motherboard. Users have reported that any changes to the SATA configuration, such as adding a new hard drive or rearranging SATA connections, can cause the BIOS to fail to recognize the devices. The only known solution in this case is to reset the CMOS by shorting the two pins on the motherboard.

For more information and user experiences, refer to the Gigabyte forum thread .

Updated
Words516
TagsRead2 minutes

Problem: Unable to Boot System After Upgrading to Proxmox 7.4.6

After upgrading to Proxmox 7.4.6 and rebooting the system, an error message appears, stating “disk ’lvmid//’ not found.” This issue is caused by a bug in GRUB.

Solution: Using Super-Grub2 to Boot and Repair GRUB2

To resolve this issue, follow these steps:

  1. Create a bootable USB using Super Grub Disk2 Rescue ISO .

  2. Boot the system from the Super Grub Disk2 USB.

  3. Upon booting, an orange-colored menu will appear.

  4. Select “Enable GRUB2’s RAID and LVM support” and press Enter.

  5. Press Esc to return to the main menu.

  6. Select “Boot manually” and press Enter.

  7. Select “Operating Systems” and press Enter.

  8. Scroll down to the second last option, “Linux /boot/vmlinuz-5.xx.xx-x-pve (lvm/pve-root),” and press Enter.

  9. The system will reboot and boot into Proxmox VE as before.

  10. Once successfully booted into Proxmox VE, open the Proxmox VE shell.

  11. Run the following command to repair GRUB2: update-grub.

However, running the update-grub command may throw errors related to disks not found. To resolve this, perform the following steps:

  1. Inside the Proxmox VE shell, run the following command to extend the LVM: lvextend -L +1G /dev/pve/.

  2. After extending the LVM, run the following command to reduce the LVM back: lvreduce -L -1G /dev/pve/.

  3. After completing these steps, you should be able to use the system as normal.

References:

Updated
Words356
TagsRead2 minutes

Introduction

This code example demonstrates how to use Python’s Flask framework and the python-telegram-bot library (version 13.0) to build a webhook for a Telegram bot. We will utilize the Google Cloud Run container to handle incoming messages and invoke the bot without long polling.

from flask import Flask, request, jsonify
from telegram import Bot, Update
from telegram.ext import Dispatcher
import requests

app = Flask(__name__)
bot = Bot(token="YOUR_BOT_TOKEN_HERE")
dispatcher = Dispatcher(bot, None, workers=0, use_context=True)

Defining the Message Handler

To handle incoming messages, we define a function called photo_handler that will be used as a handler for photo messages.

def photo_handler(update: Update, context):
    user_id = update.message.from_user.id
    owner_id = 123456789  # Replace with your user_id

    if user_id == owner_id:
        file_id = update.message.photo[-1].file_id  # Get the highest-resolution photo
        file_info = bot.get_file(file_id)
        file_url = file_info.file_path
        
        # Download the file (assuming you have 'requests' installed)
        response = requests.get(file_url)
        with open("received_photo.jpg", "wb") as f:
            f.write(response.content)

Setting up the Webhook Endpoint

We define a route for the /webhook endpoint using the @app.route decorator. This endpoint will receive incoming updates from Telegram.

@app.route('/webhook', methods=['POST'])
def webhook():
    update = Update.de_json(request.get_json(), bot)
    dispatcher.process_update(update)
    return jsonify(success=True)

Adding the Message Handler to the Dispatcher

We add the photo_handler function as a message handler using the MessageHandler class from the telegram.ext module. We specify the Filters.photo filter to only handle photo messages.

if __name__ == "__main__":
    from telegram.ext import MessageHandler, Filters
    
    photo_handler = MessageHandler(Filters.photo, photo_handler)
    dispatcher.add_handler(photo_handler)
    app.run(port=5000)

Conclusion

By using Flask and the python-telegram-bot library, we can easily build a webhook for a Telegram bot. This allows us to handle incoming messages efficiently using a Google Cloud Run container instead of using long polling.