Skip to content

Instantly share code, notes, and snippets.

View Darkflib's full-sized avatar
🏠
The real problem is not whether machines think, but whether men do.

Mike Preston Darkflib

🏠
The real problem is not whether machines think, but whether men do.
View GitHub Profile
from googleapiclient.discovery import build
from google.oauth2 import service_account
def create_and_share_google_doc(service_account_file, user_email):
# Authenticate with the service account
creds = service_account.Credentials.from_service_account_file(service_account_file, scopes=[
'https://www.googleapis.com/auth/documents',
'https://www.googleapis.com/auth/drive'
])

Yes, you can indeed combine the use of systemd units to mount a block device when detected with parameterized unit files. Systemd supports instantiating units, which allows you to pass parameters to unit files. This is particularly useful for mounting devices dynamically based on their UUID or any other identifying parameter. Here's how you can set this up:

  1. Create a Parameterized Unit File: You need to create a systemd mount unit file that can take the UUID as a parameter. This file should be named following the pattern extdrive@.mount. Place this file under /etc/systemd/system/.

    Here's an example of what the content might look like:

    [Unit]
    Description=Mount External Drive at %i
    Requires=local-fs.target

After=local-fs.target

@Darkflib
Darkflib / output.txt
Created April 4, 2024 14:21
TZ examples
BST
2024-04-04 14:20:19.982576+00:00
2024-04-04 14:20:19
UTC
2024-04-04 14:20:19.982576+00:00
2024-04-04 14:20:19 UTC
2024-04-04 10:20:19.982576-04:00
2024-04-04 10:20:19 EDT
2024-04-04 15:20:19.982576+01:00
2024-04-04 15:20:19 BST
import subprocess
import time
def get_current_song():
"""Fetches the current song playing on Spotify."""
script = '''
tell application "Spotify"
if it is running then
if player state is playing then
import os
import logging
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
def sanitize_filename(filename):
"""Remove leading dots from the filename."""
return filename.lstrip('.')

Sure, I'll guide you through setting up LUKS with TPM on Ubuntu 23. Remember, this is like teaching a fish to climb a tree, but since you're not a fish, you'll probably manage just fine. Here's how to do it:

  1. Update Your System: Let's start with the basics. Open a terminal and run:

    sudo apt update && sudo apt upgrade

    This is like saying "hello" to your system before you start messing with it.

  2. Install Necessary Tools: You'll need tpm2-tools for TPM interactions. Run:

On Amazon EKS (Elastic Kubernetes Service), you can log into a pod. This is a common task for troubleshooting and inspecting the state of applications running within your Kubernetes cluster. To do so, you'll typically use the kubectl exec command, which allows you to execute commands inside a container in a pod.

Here's a basic example of how to log into a pod on EKS:

  1. Ensure kubectl is Configured: First, make sure your kubectl is configured with the correct context to interact with your EKS cluster. You can check your current context using kubectl config current-context.

  2. Find Your Pod: Identify the pod you want to log into. You can list all pods in a specific namespace using kubectl get pods -n <namespace>. If you don’t specify a namespace, it will list pods in the default namespace.

  3. Exec into the Pod: To log into the pod, use the kubectl exec command. If the pod has only one container, you can simply use:

import os
import sys
from dotenv import load_dotenv
import openai # pip install openai
import re
# Load the API key from the .env file
load_dotenv()
# Get the API key from the environment variable
@Darkflib
Darkflib / quick action.md
Created November 13, 2023 14:20
create a quick action to open in vscode

Adding a right-click option to open files or folders with Visual Studio Code (VSCode) on a Mac involves creating a service using Automator, a macOS tool for automating tasks. Here's a step-by-step guide to achieve this:

  1. Open Automator:

    • Go to your Applications folder and open Automator.
  2. Create a New Service:

    • In Automator, select File > New.
    • Choose Service or Quick Action (depending on your macOS version).
  3. Configure the Service:

@Darkflib
Darkflib / turing-vs-shannon.txt
Created November 3, 2023 19:58
Example from openai
USER
Write a rap battle between Alan Turing and Claude Shannon.
Sample response
Verse 1 - Alan Turing:
I'm Turing, the father of all computation,
Built a machine that helped end a nation.
Your information theory, it's imitation,