Skip to content

Instantly share code, notes, and snippets.

View yanfengliu's full-sized avatar
⌨️
Learning

Yanfeng Liu yanfengliu

⌨️
Learning
View GitHub Profile
@yanfengliu
yanfengliu / cypressNpmScripts.json
Created July 28, 2021 22:53
npm scripts for Cypress
...
"scripts": {
"start": "serve -p 5000",
"cy:run:chrome": "cypress run --browser=chrome",
"test:chrome": "start-server-and-test start http://localhost:5000 cy:run:chrome"
},
...
@yanfengliu
yanfengliu / dockerfileCypressHost
Created July 28, 2021 22:52
Dockerfile that starts a server then run cypress tests
FROM cypress/included:8.0.0
WORKDIR /app
COPY . .
RUN npm install
ENTRYPOINT ["npm", "run", "test:chrome"]
@yanfengliu
yanfengliu / cypressDockerGithubAction.yml
Created July 28, 2021 22:50
use Cypress Docker on GitHub Action
...
jobs:
cypress-run:
runs-on: ubuntu-latest
container: cypress/included:8.0.0 # this line specifies the docker image we want
...
@yanfengliu
yanfengliu / cypressUploadArtifact.yml
Created July 28, 2021 22:47
Cypress GitHub Action to upload artifact
- uses: actions/upload-artifact@v1
if: failure()
with:
name: cypress-screenshots
path: cypress/screenshots
- uses: actions/upload-artifact@v1
if: always()
with:
name: cypress-videos
path: cypress/videos
@yanfengliu
yanfengliu / turkeyCypressGithubActionV1.yml
Last active July 28, 2021 22:49
Turkey Cypress test GitHub Action v1
name: Turkey end-to-end tests chrome headless
on: [push]
jobs:
cypress-run:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: cypress-io/github-action@v2
with:
start: npm start
@yanfengliu
yanfengliu / cypressSnapshotTest.ts
Created July 28, 2021 22:43
Cypress snapshot test
describe("buttons", () => {
it("can change class", () => {
cy.getById("label_class").select("class1");
dot_mode_coordinates_2.forEach((coordinate) => {
cy.get("canvas").click(coordinate.x, coordinate.y);
});
cy.get("canvas").matchImageSnapshot("multi_class");
});
}
@yanfengliu
yanfengliu / inverse_kinematics.py
Last active January 1, 2019 22:01
Solving inverse kinematics using a neural network, assuming 2D environment, a robot arm with 2 segments, each of length 1
import keras
import numpy as np
from keras.models import Sequential, Model
from keras.layers import Dense, Activation, LeakyReLU, Input, Lambda, Concatenate
from keras.losses import mean_absolute_error, mean_squared_error
import os
import sys
%matplotlib inline
import matplotlib.pyplot as plt
from keras import optimizers
def transform_matrix_tensor(theta, d, a, alpha):
# tensor version of transform matrix
matrix = [[tf.cos(theta), tf.multiply(-tf.sin(theta), tf.cos(alpha)), tf.multiply(tf.sin(theta), tf.sin(alpha)), tf.multiply(a, tf.cos(theta))],
[tf.sin(theta), tf.multiply(tf.cos(theta), tf.cos(alpha)), tf.multiply(-tf.cos(theta), tf.sin(alpha)), tf.multiply(a, tf.sin(theta))],
[tf.zeros_like(theta), tf.sin(alpha), tf.cos(alpha), d],
[tf.zeros_like(theta), tf.zeros_like(theta), tf.zeros_like(theta), tf.ones_like(theta)]]
return matrix
def batch_matmul(location_v, batch_theta_v):
# perform matrix multiplication between the location vector and the transform matrix,
@yanfengliu
yanfengliu / model.py
Created January 1, 2019 06:28
Neural network architecture for inverse kinematics
model = Sequential([
Dense(256, input_shape=(2,)),
LeakyReLU(),
Dense(256),
LeakyReLU(),
Dense(256),
LeakyReLU(),
Dense(256),
LeakyReLU(),
Dense(256),
@yanfengliu
yanfengliu / generate_training_data.py
Created January 1, 2019 06:25
Generate forward kinematics data for neural network training
def transformMatrix(theta, d, a, alpha):
return np.array([[np.cos(theta), -np.sin(theta)*np.cos(alpha), np.sin(theta)*np.sin(alpha), a*np.cos(theta)],
[np.sin(theta), np.cos(theta)*np.cos(alpha), -np.cos(theta)*np.sin(alpha), a*np.sin(theta)],
[0, np.sin(alpha), np.cos(alpha), d],
[0, 0, 0, 1]])
def forwardKinematics_2(theta1, theta2):
T00 = transformMatrix(theta1,0,1,0)
T01 = transformMatrix(theta2,0,1,0)
pos = [0, 0, 0, 1]