OpenAI beta

Anyone not interested in this ?

I asked it for a fedora bash script to check BTRFS drives and it worked. ?

Dont think I need to learn to code anymore as a truck driver.

need a bash script to maintain a btrfs file system

Here is a sample bash script that you can use to maintain a btrfs file system:

Copy code

#!/bin/bash

# Check if btrfs is installed
if ! command -v btrfs > /dev/null; then
    echo "Error: btrfs is not installed on this system." >&2
    exit 1
fi

# Check if the script is run as root
if [ "$(id -u)" -ne 0 ]; then
    echo "Error: this script must be run as root." >&2
    exit 1
fi

# Set the path to the btrfs file system
btrfs_path="/path/to/btrfs/file/system"

# Check if the path exists and is a btrfs file system
if [ ! -d "$btrfs_path" ] || [ "$(stat -f -c %T "$btrfs_path")" != "btrfs" ]; then
    echo "Error: the path does not exist or is not a btrfs file system." >&2
    exit 1
fi

# Define the functions for the script

# Perform a balance operation on the btrfs file system
function btrfs_balance() {
    btrfs balance start "$btrfs_path"
}

# Perform a scrub operation on the btrfs file system
function btrfs_scrub() {
    btrfs scrub start "$btrfs_path"
}

# Perform a defragmentation operation on the btrfs file system
function btrfs_defrag() {
    btrfs filesystem defragment "$btrfs_path"
}

# Show the status of the btrfs file system
function btrfs_status() {
    btrfs filesystem show "$btrfs_path"
}

# Show the help text for the script
function show_help() {
    echo "Usage: $(basename "$0") [OPTION]..."
    echo "Maintain a btrfs file system."
    echo
    echo "  -b, --balance    perform a balance operation on the file system"
    echo "  -s, --scrub      perform a scrub operation on the file system"
    echo "  -d, --defrag     perform a defragmentation operation on the file system"
    echo "  -S, --status     show the status of the file system"
    echo "  -h, --help       show this help text"
    echo
    echo "Run 'man btrfs' for more information about the btrfs command-line utility."
}

# Parse the command-line options
while [ "$#" -gt 0 ]; do
    case "$1" in
        -b|--balance) btrfs_balance;;
        -s|--scrub) btrfs_scrub;;
        -d|--defrag) btrfs_defrag;;
        -S|--status) btrfs_status;;
        -h|--help) show_help; exit 0;;
        *) echo "Error: unknown option '$1'. Run $(basename "$0") --help for usage information." >&2; exit 1;;
    esac
    shift
done

To use the script, save it to a file (e.g. `btrfs-m

![](data:image/svg+xml,%3csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20version=%271.1%27%20width=%2730%27%20height=%2730%27/%3e)Marten

it need it run periodicly

To run the script periodically, you can use a cron job. Cron is a built-in Linux utility that allows you to schedule tasks to run automatically at specified intervals.

Here’s how you can use cron to run the script periodically:

  1. Open the crontab editor by running the following command:

Copy code

crontab -e
  1. This will open the crontab file in a text editor. Add a new line to the file with the following format:

Copy code

<minute> <hour> <day of month> <month> <day of week> <command>

For example, to run the script every day at 12:00 PM, you can add the following line:

Copy code

0 12 * * * /path/to/script/btrfs-maintain.sh --balance --scrub

This will run the script with the --balance and --scrub options every day at 12:00 PM.

  1. Save the crontab file and exit the editor. The cron job will now run the script at the specified time.

For more information about cron and how to use it, see the crontab man page:

Copy code

man crontab

You can also run the script manually at any time by running the following command:

Copy code

/path/to/script/btrfs-maintain.sh [OPTIONS]

Replace /path/to/script/ with the actual path to the script on your system, and [OPTIONS] with the options you want to use. Run the script with the --help option to see a list of available options and their usage.

![](data:image/svg+xml,%3csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20version=%271.1%27%20width=%2730%27%20height=%2730%27/%3e)Marten

Id like a scrub once a month and file system check once a week

To run the script with the --scrub option once a month and the --status option once a week, you can add the following line to your crontab file:

Copy code

0 12 1 * * /path/to/script/btrfs-maintain.sh --scrub
0 12 * * 1 /path/to/script/btrfs-maintain.sh --status

This will run the --scrub option on the first day of every month at 12:00 PM, and the --status option on every Monday at 12:00 PM.

Remember to replace /path/to/script/ with the actual path to the script on your system.

To edit your crontab file, run the following command:

Copy code

crontab -e

Add the above lines to the file and save it. The cron job will now run the script at the specified times.

For more information about cron and how to use it, see the crontab man page:

Copy code

man crontab

You can also run the script manually at any time by running the following command:

Copy code

/path/to/script/btrfs-maintain.sh [OPTIONS]

Replace /path/to/script/ with the actual path to the script on your system, and [OPTIONS] with the options you want to use. Run the script with the --help option to see a list of available options and their usage.

![](data:image/svg+xml,%3csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20version=%271.1%27%20width=%2730%27%20height=%2730%27/%3e)Marten

Show me the code again

Here is the code again:

Copy code

#!/bin/bash

# Check if btrfs is installed
if ! command -v btrfs > /dev/null; then
    echo "Error: btrfs is not installed on this system." >&2
    exit 1
fi

# Check if the script is run as root
if [ "$(id -u)" -ne 0 ]; then
    echo "Error: this script must be run as root." >&2
    exit 1
fi

# Set the path to the btrfs file system
btrfs_path="/path/to/btrfs/file/system"

# Check if the path exists and is a btrfs file system
if [ ! -d "$btrfs_path" ] || [ "$(stat -f -c %T "$btrfs_path")" != "btrfs" ]; then
    echo "Error: the path does not exist or is not a btrfs file system." >&2
    exit 1
fi

# Define the functions for the script

# Perform a balance operation on the btrfs file system
function btrfs_balance() {
    btrfs balance start "$btrfs_path"
}

# Perform a scrub operation on the btrfs file system
function btrfs_scrub() {
    btrfs scrub start "$btrfs_path"
}

# Perform a defragmentation operation on the btrfs file system
function btrfs_defrag() {
    btrfs filesystem defragment "$btrfs_path"
}

# Show the status of the btrfs file system
function btrfs_status() {
    btrfs filesystem show "$btrfs_path"
}

# Show the help text for the script
function show_help() {
    echo "Usage: $(basename "$0") [OPTION]..."
    echo "Maintain a btrfs file system."
    echo
    echo "  -b, --balance    perform a balance operation on the file system"
    echo "  -s, --scrub      perform a scrub operation on the file system"
    echo "  -d, --defrag     perform a defragmentation operation on the file system"
    echo "  -S, --status     show the status of the file system"
    echo "  -h, --help       show this help text"
    echo
    echo "Run 'man btrfs' for more information about the btrfs command-line utility."
}

# Parse the command-line options
while [ "$#" -gt 0 ]; do
    case "$1" in
        -b|--balance) btrfs_balance;;
        -s|--scrub) btrfs_scrub;;
        -d|--defrag) btrfs_defrag;;
        -S|--status) btrfs_status;;
        -h|--help) show_help; exit 0;;
        *) echo "Error: unknown option '$1'. Run $(basename "$0") --help for usage information." >&2; exit 1;;
    esac
    shift
done

Remember to replace /path/to/btrfs/file/system with the actual path to your btrfs file system. You can also customize the

2 Likes

have a friend callen Ryan thay love chat videos. Can you make a script to find great cat videos for Ryan to watch ?

Sure, I can help you create a script to find great cat videos for Ryan to watch. Here is an example of what the script might look like:

Copy code

# This script searches for popular cat videos on YouTube and outputs a list of video titles and URLs for Ryan to watch

import requests
import json

# Set YouTube API key
API_KEY = "YOUR_API_KEY"

# Set search query
query = "cat videos"

# Set maximum number of results to return
max_results = 10

# Send request to YouTube API
url = f"https://www.googleapis.com/youtube/v3/search?part=snippet&q={query}&type=video&key={API_KEY}&maxResults={max_results}"
response = requests.get(url)

# Parse response
results = json.loads(response.text)["items"]

# Output list of video titles and URLs
for result in results:
    print(result["snippet"]["title"])
    print(f"https://www.youtube.com/watch?v={result['id']['videoId']}")

To use this script, you will need to replace YOUR_API_KEY with a valid YouTube API key. You can obtain an API key by following the instructions here. You can also customize the search query and the maximum number of results to return to fit Ryan’s preferences. I hope this helps! Let me know if you have any other questions.

Gave zero fucks about my poor spelling :frowning:

2 Likes

This is insane. I just used it to do something similar, and posted here. OMG

It was a major topic in last Friday’s WAN show on LTT. Luke simply can’t get enough of it and it seems he’s infected Linus similarly :wink:

This sort of thing will be great to augment jobs, but will not replace them anytime in the near future. Short bash scripts are neat but don’t go into the in-depth design required to build, and more importantly maintain, complex systems.

Explain why level 1 tech likes Weird Al

Weird Al Yankovic is a musician known for his humorous and satirical songs that often parody popular culture. He has been active since the late 1970s, and has a dedicated fan base, including among level 1 techs. Level 1 techs may enjoy his music because it is funny and relatable, and because it often references technology and popular culture in a way that resonates with them. Additionally, Yankovic’s music is often clever and cleverly written, which can be appreciated by people who are interested in technology and other intellectual pursuits.

1 Like

I work in bioinformatics, so I do a reasonable(?) amount of coding. I think that the ChatGPT is really cool, but I’m also not worried about losing my job to it any time soon.

I tried having it create some code for some basic bioinformatics tasks. First, I ask it to load protein sequences from a FASTA file, which is a common, text-based file format used for storing protein or DNA sequence data.

Hi, Can you create python code to convert a protein fasta file into a dictionary of sequences?

Sure, here is some sample code that should do the job:

import re

def fasta_to_dict(fasta_string: str) -> dict:
    """
    Convert a FASTA string into a dictionary of sequences.

    :param fasta_string: The FASTA string to convert.
    :return: A dictionary where the keys are the FASTA headers and the values are the corresponding sequences.
    """
    # First, split the string into a list of lines.
    lines = fasta_string.strip().split('\n')

    # Initialize the dictionary.
    fasta_dict = {}

    # Keep track of the current sequence.
    current_sequence = None

    # Iterate over the lines in the string.
    for line in lines:
        # If the line is a FASTA header, then store it as the current sequence.
        if line.startswith('>'):
            current_sequence = line[1:]
            fasta_dict[current_sequence] = ""
        # Otherwise, append the line to the current sequence.
        else:
            # Remove any whitespace characters (such as spaces and tabs) from the line.
            clean_line = re.sub(r'\s+', '', line)
            fasta_dict[current_sequence] += clean_line

    return fasta_dict

To use this function, you would first need to read the contents of your FASTA file into a string, and then pass that string to the fasta_to_dict() function. Here is an example of how you could do this:

# Open the FASTA file.
with open('path/to/file.fasta', 'r') as file:
    # Read the contents of the file into a string.
    fasta_string = file.read()

# Convert the FASTA string into a dictionary of sequences.
fasta_dict = fasta_to_dict(fasta_string)

# Print the dictionary to verify that it was created correctly.
print(fasta_dict)

I hope this helps! Let me know if you have any other questions.

This is… perfectly functional code? Doing a file.read() on what could potentially be a multi-gigabyte file is not a great idea, and there are probably better choices than re.sub for cleaning white spaces, but it would do. If I told a 1st or 2nd year biology student to do the same thing, this is about what I would expect. Interestingly, if I ask the same question again, I get very different code:

Sure, here is a possible solution using the BioPython library:

from Bio import SeqIO

# create an empty dictionary to store the sequences
sequences = {}

# parse the FASTA file using the SeqIO.parse function
for record in SeqIO.parse("protein.fasta", "fasta"):
    # add each sequence to the dictionary using the ID as the key and the sequence as the value
    sequences[record.id] = str(record.seq)

# print the dictionary for testing purposes
print(sequences)

This code assumes that the FASTA file is named protein.fasta and contains protein sequences in the standard FASTA format, with each sequence having a unique identifier (ID) in the header line. The resulting dictionary will contain the ID as the key and the sequence as the value for each sequence in the file.

Again, it would work. It uses a the biopython library, which would have to be installed first, but SeqIO.parse should create a generator, which prevents reading the whole file into memory first.

Next, let’s ask it to perform a in-silico tryptic digest on the protein sequences - this should split our protein sequences at the amino acids lysine or arginine:

Can you show me code to perform a tryptic digest on the sequences in the dictionary?

Sure, here is a possible solution using the BioPython library:

from Bio import Seq
from Bio.Seq import Seq
from Bio.Alphabet import IUPAC

# define the tryptic enzyme and the cleavage site
enzyme = "trypsin"
site = "KR"

# loop over the sequences in the dictionary
for id, seq in sequences.items():
    # convert the sequence string to a Seq object using the IUPAC alphabet
    seq = Seq(seq, IUPAC.protein)

    # perform the tryptic digest using the Seq.split function
    peptides = seq.split(site)

    # print the ID and the resulting peptides for testing purposes
    print(id, peptides)

This code assumes that the dictionary of sequences is named sequences and contains protein sequences in the form of Seq objects. It uses the Seq.split function to perform a tryptic digest on each sequence, using the specified enzyme and cleavage site. The resulting peptides are printed for testing purposes.

This code doesn’t work - the sites should be K or R, not both together. The worst part is that it won’t cause any error, just give incorrect data. Let’s be more specific:

Can you show me python code that splits protein sequences at lysine or arginine residues?

Sure, here is a possible solution using the BioPython and re (regular expression) libraries:

import re
from Bio import Seq
from Bio.Seq import Seq
from Bio.Alphabet import IUPAC

# define the tryptic enzyme and the cleavage site
enzyme = "trypsin"
site = "K|R"  # this regular expression matches either a 'K' or a 'R'

# compile the regular expression pattern to match the cleavage site
pattern = re.compile(site)

# loop over the sequences in the dictionary
for id, seq in sequences.items():
    # convert the sequence string to a Seq object using the IUPAC alphabet
    seq = Seq(seq, IUPAC.protein)

    # perform the tryptic digest using the regular expression pattern
    # and the Seq.split function, which takes a regex pattern as an argument
    peptides = seq.split(pattern)

    # print the ID and the resulting peptides for testing purposes
    print(id, peptides)

This code assumes that the dictionary of sequences is named sequences and contains protein sequences in the form of Seq objects. It uses the re.compile function to create a regular expression pattern that matches either a ‘K’ or a ‘R’ character, which are the residues that trypsin cleaves at. It then uses the Seq.split function to perform a tryptic digest on each sequence, using the compiled regex pattern as an argument. The resulting peptides are printed for testing purposes.

This looks like it should work (it actually fooled me a first), but the Seq.split method can’t take regular expression patterns, only strings. Let’s try one more time:

Can you show me python code that split protein sequences at lysine or arginine residues without using biopython

Sure, here is a possible solution using the re (regular expression) library:

import re

# define the tryptic enzyme and the cleavage site
enzyme = "trypsin"
site = "K|R"  # this regular expression matches either a 'K' or a 'R'

# compile the regular expression pattern to match the cleavage site
pattern = re.compile(site)

# loop over the sequences in the dictionary
for id, seq in sequences.items():
    # perform the tryptic digest using the regular expression pattern
    # and the re.split function, which takes a regex pattern as an argument
    peptides = pattern.split(seq)

    # print the ID and the resulting peptides for testing purposes
    print(id, peptides)

This code assumes that the dictionary of sequences is named sequences and contains protein sequences as strings. It uses the re.compile function to create a regular expression pattern that matches either a ‘K’ or a ‘R’ character, which are the residues that trypsin cleaves at. It then uses the re.split function to perform a tryptic digest on each sequence, using the compiled regex pattern as an argument. The

The incomplete sentence at the end isn’t an error - it just stopped there. But at least code seems to work this time. Okay, let’s try one more task: aligning the tryptic peptides to a genome sequence. I had to try a few different version of the question to even get it close to what I wanted (it kept trying to perform a multiple sequence alignment with all the peptides), but I partially blame that on me not being specific enough. However, when I asked it:

Can you show me code for performing local alignment of a tryptic peptides to a reference genome?

I got close to the right answer:

Sure, here is an example of how you might perform local alignment of tryptic peptides to a reference genome using the Needleman-Wunsch algorithm:

# Import the Needleman-Wunsch module
from needleman_wunsch import NeedlemanWunsch

# Define the reference genome and the tryptic peptides to align
reference_genome = "ATGTTAGAATCATCGAGCAGGTCCCTCTAGAGGGG"
tryptic_peptides = ["ATCATCGA", "CTCTAGAGGGG"]

# Initialize the Needleman-Wunsch aligner
nw = NeedlemanWunsch()

# Perform the local alignment for each tryptic peptide
for peptide in tryptic_peptides:
    alignment = nw.align(peptide, reference_genome, local=True)
    
    # Print the alignment
    print(alignment)

This code uses the Needleman-Wunsch algorithm to perform local alignment, which allows for gaps in the alignment. The NeedlemanWunsch class is imported from a module called needleman_wunsch . This module is not included in Python by default, so you would need to install it before running the code.

Note that this is just an example of how you might approach this problem, and there are many other ways to perform local alignment of tryptic peptides to a reference genome.

This almost does what I want (perform an individual alignment for each peptide), but it’s dangerously wrong - Needleman-Wunsch does global alignment, not local alignment (you want Smith-Waterman for that), and neither of those have anything to do with having gaps in the alignment. Not only is the code incorrect, it also provide incorrect information in the “explanation”.

Additionally, you can’t actually align a peptide (protein sequence) to a genome (DNA sequence directly) - you need to do a six-frame translation of the DNA sequence first. However, I didn’t ask it to do that, just to do the alignment, so it’s… not as bad?

As a final test, I asked to perform a six-frame translation before doing the alignment…

Can you show me code for performing local alignment of a tryptic peptides to a reference genome after performing a six-frame translation of the genome?

Sure, here is an example of how you might perform local alignment of tryptic peptides to a reference genome after performing a six-frame translation of the genome:

# Import the Needleman-Wunsch module
from needleman_wunsch import NeedlemanWunsch

# Define the reference genome and the tryptic peptides to align
reference_genome = "ATGTTAGAATCATCGAGCAGGTCCCTCTAGAGGGG"
tryptic_peptides = ["ATCATCGA", "CTCTAGAGGGG"]

# Perform a six-frame translation of the genome
translated_genome = six_frame_translation(reference_genome)

# Initialize the Needleman-Wunsch aligner
nw = NeedlemanWunsch()

# Perform the local alignment for each tryptic peptide
for peptide in tryptic_peptides:
    alignment = nw.align(peptide, translated_genome, local=True)
    
    # Print the alignment
    print(alignment)

This code uses the Needleman-Wunsch algorithm to perform local alignment, which allows for gaps in the alignment. The NeedlemanWunsch class is imported from a module called needleman_wunsch . This module is not included in Python by default, so you would need to install it before running the code.

Before performing the alignment, the code performs a six-frame translation of the reference genome using a function called six_frame_translation . This function is not included in the code, so you would need to implement it yourself or use a third-party library to perform the six-frame translation.

Note that this is just an example of how you might approach this problem, and there are many other ways to perform local alignment of tryptic peptides to a reference genome after performing a six-frame translation.

…and it basically told me to go fuck myself and figure it out on my own. I guess I asked too many question.

Overall, this made me realize that it’s not some magic coding AI - it’s basically just a code regurgitator. And since there’s lots of bad bioinformatics code, it give lots of bad results.

Essentially you’re saying this is an ELIZA machine? :wink:

It will self drive you into a wall and smile :slight_smile:

I’ve seen a lot of people talk about this on Twitter. One thing I’m curious about, is this AI developing as people are using it now?

No, it was trained on a 2021 data set and is not learning from user input. They’re trying to avoid another Tay scenario I think.

Haha! Yes i guess that makes sense.

I’ve been using as a better google+stackoverflow replacement. The cool thing about this is that it can follow a conversation style query.

“Please give me an example of this” and then you can ask “can you do it without using x”. This is not possible with normal google searches.

1 Like

I was playing around with the chatbot today. It doesn’t always work quite right…

Granted, this is the chatbot. But that’s the kind of question a chatbot should be expecting, yes?

Could it have been some other kind of glitch?

If you want to make the site crash, ask it to write pong with comments and to add netcode

Linus Sebastian asks ChatGPT how to build a PC. Hilarity ensues…

I wrote a python thing to play with music stuff and basically got chatgpt to write my documentation for me.

I dumped the output of my script:

and asked it to verify if my calculations were correct


I’m pretty impressed with its ability to understand context.

I wrote this code ~5 years ago and left a magic number 1200 and coming back to it now I forgot why its was 1200. 1200 what and why?

So I asked it to help me reverse engineer my own code:

It ended up being that 1200 = 12 notes * 100 cents or 1 octave = 1200 cents So that was actually really handy. And a good reminder not to leave magic numbers!


I also asked it how do I center a font in libgdx. I added a glyph layout and it worked first compile. This surprised me a little because I didnt expect it to return such a specific and useful answer for such a specific problem.


A limitation tho. I had some data in two columns and asked it what was in the first column that was missing from the second.And it kept giving wrong results, so it’s not a computational engine. You have to phrase things in certain ways to get the right output.

I also asked it how to apply a shader to a shaperender and it was convinced you do shaperender.setShader() but that API simply does not exist. no matter how i phrased it it returned that answer with such confidence.

seems when it is wrong it is confidently wrong so you have to fact check it

Hey neat!

This reminds me of a compression algo example from one of my textbooks:



Basically it goes from an ASCII representation of ‘ACTG’ (1 byte per char), to 2 bit per char as there are only 4 states. Compressing a virus with a size of 50,000 bits down to 12536 bits

It then goes further into some other compressing algorithms and comparisons. credit: Algorithms fourth ed.