Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View vesse's full-sized avatar

Vesa Poikajärvi vesse

View GitHub Profile
@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 / login.jade
Last active May 24, 2023 15:41
stackoverflow#26403853
doctype html5
html
head
title Test Page
body
.error #{message}
form(action='/login' method='POST')
label Email
input(type='email' name='email')
@vesse
vesse / express-jwt.js
Last active April 11, 2023 16:43
Two Passport + JWT (JSON Web Token) examples
//
// Implementation using express-jwt middle
//
var express = require('express'),
ejwt = require('express-jwt'),
jwt = require('jsonwebtoken'),
passport = require('passport'),
bodyParser = require('body-parser'),
LocalStrategy = require('passport-local').Strategy,
BearerStrategy = require('passport-http-bearer').Strategy;
@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 / package.json
Created January 20, 2012 11:17
Stream live web cam video using Node.js and Gstreamer
{
"name": "streamingtest",
"version": "0.0.1",
"engines": {
"node": ">=0.6.0"
},
"dependencies": {
"express": "2.5.x",
"coffee-script": "1.2.x"
},
@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 / 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 / sid.coffee
Last active July 5, 2018 23:48
Convert binary buffer object SID to string
# Convert binary encoded object SID to a string
# (eg. S-1-5-21-1004336348-1177238915-682003330-512)
#
# SID format: https://technet.microsoft.com/en-us/library/cc962011.aspx
#
# ldapjs `searchEntry` has attribute `raw` that holds the raw
# values, including the `objectSid` buffer when one exists. Pass that
# buffer to get the string representation that can then be easily
# used in LDAP search filters, for example.
#
@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'
};