Skip to content

Instantly share code, notes, and snippets.

View achhunna's full-sized avatar

Achhunna M. achhunna

View GitHub Profile
@achhunna
achhunna / get-icons.js
Last active May 27, 2021 15:29
Batch SVG file download from Zeplin's styleguide components
const fs = require('fs');
const mkdirp = require('mkdirp');
const getDirName = require('path').dirname;
const axios = require('axios');
const styleguideId = process.argv.slice(2)[0]; // provide styleguideId ast 1st arg in command line
if (!styleguideId) {
throw Error('Please provide styleguideId as first arg');
}
@achhunna
achhunna / Svg-icon.vue
Last active April 18, 2021 08:56
Import svg inline and modify element to create icon
<script>
function recursivelyRemoveFill(el) {
if (!el) {
return;
}
el.removeAttribute('fill');
[].forEach.call(el.children, child => {
recursivelyRemoveFill(child);
});
}
@achhunna
achhunna / component.test.js
Created July 26, 2019 18:13
Additional beforeEach()
beforeEach(() => {
// do something
});
describe('1st block', () => {
test('1st test', () => {});
describe('2nd block', () => {
beforeEach(() => {
// do something again
});
@achhunna
achhunna / component.test.js
Last active July 22, 2019 22:14
DOM action events (keydown)
test('emit events when keydown.a pressed', () => {
wrapper.trigger('keydown', {
key: 'a'
});
expect(wrapper.emitted().aPressed.length).toBe(1);
});
@achhunna
achhunna / surfline-api.js
Last active May 7, 2021 15:21
`How's the surf` script using Surfline API
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: cyan; icon-glyph: swimmer;
// Checks surf height at Pacifica Lindmar beach
// Using Surfline's services API
const baseUrl = "https://services.surfline.com/kbyg/spots/forecasts"
const paramsList = [
{
type: 'wave',
query: [
@achhunna
achhunna / surfline-scraping.js
Last active May 7, 2021 15:20
`How's the surf` script scraping Surfline
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: cyan; icon-glyph: swimmer;
// Checks surf height at Pacifica Lindmar beach
const url = "https://www.surfline.com/surf-report/pacifica-lindamar/5842041f4e65fad6a7708976"
const webview = new WebView()
await webview.loadURL(url)
var getData = `
@achhunna
achhunna / component.test.js
Created May 19, 2019 22:06
Async callbacks
test('check async block', async() => {
await wrapper.vm.asyncFunction(); // where asyncFunction() has a resolved Promise or other async stuff
});
@achhunna
achhunna / component.test.js
Created May 19, 2019 21:27
Mocking modules
// used in component
<script>
import Constants from '../constants';
console.log(Constants.myConstant);
</script>
// in test file
jest.mock('../constants', () => ({
'myConstant': 'myValue',
@achhunna
achhunna / component.test.js
Last active May 19, 2019 18:05
Mocking methods
// using jest.fn() to mock action and mutation functions
beforeEach(() => {
actions = {
someAction: jest.fn(() => true)
};
mutations = {
someMutation: jest.fn(() => false)
};
state = {
key: {}
@achhunna
achhunna / component.test.js
Last active April 22, 2020 17:09
Factory function to mount component
let wrapper;
const factory = (computed = {}) => {
return shallowMount(Component, {
propsData: {},
mocks: {},
stubs: {},
methods: {},
computed,
});
};