Skip to content

Instantly share code, notes, and snippets.

View vesse's full-sized avatar

Vesa Poikajärvi vesse

View GitHub Profile
@vesse
vesse / app.ts
Last active November 9, 2021 14:19
Fastify + TypeBox fully typed
import { Static, Type } from '@sinclair/typebox'
import fastify, { FastifyInstance, FastifyPluginAsync } from 'fastify'
import type { RouteGenericInterface, RouteHandler } from 'fastify/types/route'
const port = 8080
const requestBodySchema = Type.Object({
email: Type.Readonly(Type.String({ format: 'email' })),
})
@vesse
vesse / main.tsx
Created August 27, 2020 13:55
@react-google-maps/api 1.9
export const Main: React.FunctionComponent = () => {
const [ markers, setMarkers ] = React.useState<ReadonlyArray<Marker>>([]);
// Need to be in separate files for lazy loading, otherwise using window.google.maps
// in the actual map component will throw
return (
<LoadScript googleMapsApiKey={apiKey}>
<Map markers={markers} />
</LoadScript>
);
@vesse
vesse / postal-code-geometries.ts
Last active August 11, 2020 04:50
Finnish postal number geometries download (postinumeroalueet)
/**
* Convert postal number geometries to WGS84 coordinates for geocoding
*/
import axios from 'axios';
import * as proj4 from 'proj4';
import * as turf from '@turf/turf';
import { promisify } from 'util';
import * as fs from 'fs';
const writeFile = promisify(fs.writeFile);
@vesse
vesse / jest-mocked-class.test.ts
Last active April 9, 2024 10:49
Mock 3rd party class with Jest in Typescript
import routeHandler from '../src/routeHandler';
import { mockResponse, mockRequest } from './test-helpers';
jest.mock('@googlemaps/google-maps-services-js');
import { Client } from '@googlemaps/google-maps-services-js';
const mockClient = {
geocode: jest.fn(),
};
@vesse
vesse / wfs.ts
Last active July 13, 2020 19:48
Finnish postal codes by intersection
import axios from 'axios';
import * as proj4 from 'proj4';
interface Result {
readonly features: ReadonlyArray<{
readonly properties: {
readonly posti_alue: string;
};
}>;
}
@vesse
vesse / checkout-api-hmac.js
Last active May 14, 2018 06:04
Checkout API HMAC example
const crypto = require('crypto');
const ACCOUNT = '375917';
const SECRET = 'SAIPPUAKAUPPIAS';
const headers = {
'checkout-account': ACCOUNT,
'checkout-algorithm': 'sha256',
'checkout-method': 'POST'
};
@vesse
vesse / geoserver-setup.md
Last active January 24, 2017 18:45
GeoServer test setup

US Counties on GeoServer

Just a test and a note to self.

Data

wget http://www2.census.gov/geo/tiger/GENZ2015/kml/cb_2015_us_county_500k.zip
unzip cb_2015_us_county_500k.zip
var chai = require('chai'),
should = chai.should(),
expect = chai.expect(),
assert = chai.assert,
supertest = require('supertest-as-promised'),
api = supertest('http://localhost:3000');
describe('Pictures', function () {
it('should add a picture', function (done) {
api.post('/api/v1/pictures')
<!DOCTYPE html>
<html>
<head>
<script src='http://localhost:3000/socket.io/socket.io.js'></script>
<script>
var socket = io.connect('http://localhost:3000/nsa');
socket.emit('request', {
msg : 'appA user is requesting something'
});
socket.on('incoming-request', function(data) {
var express = require('express'),
bodyParser = require('body-parser'),
passport = require('passport'),
LocalStrategy = require('passport-local').Strategy;
var app = express();
passport.use(new LocalStrategy(function (username, password, cb) {
cb(null, false, {message: 'This can never succeed'});
}));