Skip to content

Instantly share code, notes, and snippets.

View aptiko's full-sized avatar

Antonis Christofides aptiko

View GitHub Profile
@aptiko
aptiko / mousepos.js
Last active June 19, 2017 10:04
OpenLayers 3 Mouse Position
mouse_position = new ol.control.MousePosition({
coordinateFormat: ol.coordinate.createStringXY(4),
projection: ‘EPSG:4326’
})
@aptiko
aptiko / keybase.md
Created May 17, 2018 05:15
keybase.io declaration

Keybase proof

I hereby claim:

  • I am aptiko on github.
  • I am aptiko (https://keybase.io/aptiko) on keybase.
  • I have a public key ASBD6_RbRJXGmepWnYO3o4T_r-jx8vISvrvHrAnQ0mIZIwo

To claim this, I am signing this object:

@aptiko
aptiko / gist:e898be41292c7c84ac891b45125ae187
Created April 14, 2020 13:27
TimescaleDB last date EXPLAIN ANALYZE
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sort (cost=81686.50..83123.40 rows=574762 width=12) (actual time=294.183..352.196 rows=564469 loops=1)
Sort Key: _hyper_1_1254_chunk."timestamp" DESC
Sort Method: external merge Disk: 14408kB
-> Append (cost=0.28..20948.68 rows=574762 width=12) (actual time=0.028..159.398 rows=564469 loops=1)
-> Index Only Scan Backward using "1254_1254_enhydris_timeseriesrecord_pk" on _hyper_1_1254_chunk (cost=0.28..2.50 rows=1 width=12) (actual time=0.010..0.010 rows=0 loops=1)
Index Cond: (timeseries_id = 6661)
Heap Fetches: 0
-> Index Scan using _hyper_1_1253_ch
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.28..2.50 rows=1 width=8) (actual time=0.119..0.119 rows=1 loops=1)
-> Custom Scan (ChunkAppend) on enhydris_timeseriesrecord (cost=0.28..2.50 rows=1 width=8) (actual time=0.118..0.118 rows=1 loops=1)
Order: enhydris_timeseriesrecord."timestamp" DESC
-> Index Only Scan Backward using "1254_1254_enhydris_timeseriesrecord_pk" on _hyper_1_1254_chunk (cost=0.28..2.50 rows=1 width=8) (actual time=0.039..0.039 rows=0 loops=1)
Index Cond: (timeseries_id = 6661)
Heap Fetches: 0
-> Index Only Scan Backward using "1253_1253_enhydris_timeseriesrecord_pk" on _hyper_1_1253
@aptiko
aptiko / failingtest.js
Last active May 17, 2021 16:41
Nuxt test that involves the store and does not work
import { mount } from '@vue/test-utils'
import Navbar from '@/components/Navbar.vue'
describe('Navbar', () => {
test('gets loggedOnUser from store', () => {
const wrapper = mount(Navbar)
wrapper.vm.$store.commit('setLoggedOnUser', 'alice')
expect(wrapper.vm.loggedOnUser).toBe('alice')
})
})
@aptiko
aptiko / maincode.js
Created May 17, 2021 16:44
Nuxt function that uses the store
export default {
computed: {
loggedOnUser() {
return this.$store.state.loggedOnUser
},
},
// ...
}
@aptiko
aptiko / testwithmock.js
Created May 17, 2021 16:45
Testing store-related Nuxt functionality with mocking
import { mount } from '@vue/test-utils'
import Navbar from '@/components/Navbar.vue'
describe('Navbar', () => {
test('gets loggedOnUser from store', () => {
const wrapper = mount(Navbar, {
mocks: {
$store: { state: { loggedOnUser: 'alice' } },
},
})
expect(wrapper.vm.loggedOnUser).toBe('alice')
@aptiko
aptiko / setupMsw.test.js
Created May 18, 2021 10:18
Setting up MSW with Jest
import { rest } from 'msw'
import { setupServer } from 'msw/node'
describe('LoginForm', () => {
let server
beforeAll(() => {
server = setupServer(
rest.post('/auth/login/', (request, response, context) => {
const username = request.body.username
@aptiko
aptiko / initializingaxios.test.js
Created May 18, 2021 11:14
Initializing Axios
import LoginForm from '@/components/LoginForm.vue'
import axios from 'axios'
describe('LoginForm', () => {
let wrapper
beforeAll(() => {
wrapper = mount(LoginForm, {
mocks: {
$axios: axios,
@aptiko
aptiko / LoginForm.vue
Created May 31, 2021 12:54
Component needing testing of an event
<template>
<div>
<b-modal @shown="focusUsername">
<b-form-input
ref="username"
v-model="username"
:placeholder="Username"
></b-form-input>
</b-modal>
</div>