Skip to content

Instantly share code, notes, and snippets.

View christopherkade's full-sized avatar

Christopher Kade christopherkade

View GitHub Profile
@christopherkade
christopherkade / Bookmarklet
Last active February 23, 2024 20:00
Generates a Cardmarket "Wants" deck list based on the deck being viewed on any decklog-en.bushiroad.com/view/DECK-CODE page. Save the bookmarklet below as a bookmark or use the Javascript code directly in the console.
javascript:var%20%24jscomp%3D%24jscomp%7C%7C%7B%7D%3B%24jscomp.scope%3D%7B%7D%3B%24jscomp.createTemplateTagFirstArg%3Dfunction(a)%7Breturn%20a.raw%3Da%7D%3B%24jscomp.createTemplateTagFirstArgWithRaw%3Dfunction(a%2Cb)%7Ba.raw%3Db%3Breturn%20a%7D%3Bvar%20getDeckListFromDom%3Dfunction(a)%7Ba%3Dvoid%200%3D%3D%3Da%3F%22D%22%3Aa%3Bvar%20b%3D%22%22%3Bdocument.querySelectorAll(%22.card-controller-inner%22).forEach(function(c)%7Bvar%20d%3Dc.firstChild.title.split(%22%3A%22)%5B1%5D.trim()%3Bc%3Dc.lastChild.innerText%3Bd%3Dd.concat(%22%20%5B%22%2Ba%2B%22%20Format%5D%22)%3Bb%3Db.concat(%22%5Cn%22%2Cc%2B%22%20%22%2Bd)%7D)%3Breturn%20b%7D%2Clist%3DgetDeckListFromDom()%3Bprompt(%22Please%20copy%20your%20decklist%20and%20import%20it%20to%20Cardmarket%22%2Clist)%3Bvoid+0
@christopherkade
christopherkade / index.js
Created August 18, 2019 16:34
Calculating an angle based on mouse movement
/**
* Calculates the angle based on the user's mouse position and a given point
* @param {*} x1 - Mouse X pos
* @param {*} y1 - Mouse Y pos
*/
const getAngle = (x1, y1, x2, y2) => {
var distY = Math.abs(y2 - y1);
var distX = Math.abs(x2 - x1);
// Calculate the hypotenuse
var dist = Math.sqrt((distY * distY) + (distX * distX));
@christopherkade
christopherkade / test.spec.js
Created April 2, 2019 07:56
Unit test example 08
it("should increase counter when the button is clicked", () => {
wrapper.find("button").simulate("click")
expect(wrapper.find("h1").text()).toContain("1")
})
@christopherkade
christopherkade / test.spec.js
Created April 2, 2019 07:55
Unit testing example 07
import React from 'react';
import App from './App';
import { shallow } from 'enzyme'
// 1. Test suite
describe("[UNIT] Testing the App component", () => {
let wrapper
// 2. A Jest setup helper function
beforeEach(() => {
@christopherkade
christopherkade / test.spec.js
Created April 2, 2019 07:54
Unit testing example 06
class App extends Component {
state = {
counter: 0
}
handleClick = () => {
this.setState(state => {
return {
counter: state.counter + 1
}
PASS src/App.spec.js
✓ renders without crashing (2ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 0.097s, estimated 1s
Ran all test suites.
@christopherkade
christopherkade / test.spec.js
Created April 2, 2019 07:52
Unit testing example 05
// App.spec.js
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
@christopherkade
christopherkade / test.spec.js
Last active April 2, 2019 07:43
Unit testing example 04
// /src/setupTests.js
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });
@christopherkade
christopherkade / test.spec.js
Created April 2, 2019 07:40
Unit testing example 03
function add(x, y) {
// Check if the parameters are numbers
// If not, throw an error
if (isNaN(x) || isNaN(y)) {
throw new Error("Parameter is not a number !")
}
return x + y
}
describe("add method", () => {
@christopherkade
christopherkade / test.spec.js
Created April 2, 2019 07:39
Unit testing example 02
it("should return -2", () => {
expect(add(0, -2)).toBe(-2)
})