Skip to content

Instantly share code, notes, and snippets.

View davidmerwin's full-sized avatar
🏠
Working from home

David Jeffrey Merwin davidmerwin

🏠
Working from home
View GitHub Profile

TypeScript Snippet

Preview:
// Calculating the step size for each iteration
const stepSize = topmostChordPos / circlesPerHalf;

// Loop from topmostChordPos down to 0
for (let i = topmostChordPos; i > 0; i -= stepSize) {
  // Adding current position (positive and negative) to the chordYPositions array
 chordYPositions.push(i);

TypeScript Snippet

Preview:
it('adds the correct number of GridQubit objects with overlapping rows', () => {
  // Create a new instance of GridCircuit with 'moments' and an array of symbols.
  const circuit = new GridCircuit(moments, [
    symbols[0],
    symbols[1],
    symbols[5],
 ]);
@davidmerwin
davidmerwin / cirq_mixture.md
Last active November 24, 2023 05:22
This code sample defines a method called `_mixture_` in a class. The method returns a list of tuples, where each tuple contains the probability and unitary of a gate option. The probability is calculated as 1 divided by the number of gate options. The unitary of each gate option is obtained using the `cirq.unitary` function. The method then crea…

cirq_mixture

Preview:
# This code snippet defines a method named `_mixture_` in a class.
# The method returns a list of tuples, where each tuple contains the probability and unitary of a gate option.

def _mixture_(self):
    # Calculate the probability for each gate option
    probability = 1 / len(self.gate_options)
 

Python Snippet

Preview:
# Function to multiply two pauli-string-likes together
def multiply_pauli_strings(self, other: 'cirq.PAULI_STRING_LIKE') -> 'cirq.PauliString':
    """
    Multiplies two pauli-string-likes together.
    
    The result is not mutable.
 """

Python Snippet

Preview:
# Import necessary libraries
from typing import List, Tuple
import numpy as np

class XPowGate:
    # Initialize class attribute
    _eigencomponents = {}

Python Snippet

Preview:
# Human-Readable Python Code:

The following code snippet is an asynchronous method named `cancel_reservation_async` that cancels a quantum reservation. It takes in three arguments: `project_id`, `processor_id`, and `reservation_id`, all of which are strings.

```python
async def cancel_reservation_async(
 self, project_id: str, processor_id: str, reservation_id: str
@davidmerwin
davidmerwin / Git clone and navigate to Doxygen repository..md
Created November 24, 2023 00:07
This code snippet clones the doxygen repository from GitHub and then changes the current directory to the doxygen repository.

Git clone and navigate to Doxygen repository.

Preview:
@echo off

REM Check if the target folder already exists
if exist <target_folder> (
    echo Target folder already exists. Skipping cloning...
) else (
 REM Clone the repository
@davidmerwin
davidmerwin / Number Guessing Game.md
Last active November 22, 2023 04:33
This code tries to guess a number between 1 and 10, then prints an error message if it is wrong.

Number Guessing Game

Preview:
import random

number = random.randint(1, 10)

while True:
    guess = int(input('Guess a number between 1 and 10: '))
@davidmerwin
davidmerwin / Matrix Brew Guessing Game.md
Last active November 22, 2023 03:48
This code asks the user to guess a number between 1 and 10, then prints an error message if it fails.

Matrix Brew Guessing Game

Preview:
import numpy as np
import random

def main():
    global guess
    guess = 0
 print('Welcome to the Matrix Brew Guessing Game!')
@davidmerwin
davidmerwin / Count Words in Paragraph.c.md
Last active November 22, 2023 02:53
Counts the number of times each word appears in a given paragraph and prints them to their console.

Count Words in Paragraph.c

Preview:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h> // added to use tolower()

// Function prototype
int *count_words_in_paragraph(char *paragraph);