Skip to content

Instantly share code, notes, and snippets.

View peerhenry's full-sized avatar

peerhenry

View GitHub Profile
@peerhenry
peerhenry / index.ts
Created October 4, 2021 13:16
Gekke type-shit in Typescript
// Gekke type-shit in Typescript
// duck typing
// interface IFoo {
// toString: () => string
// }
type ToStringable = { myToString: () => string }
function loggo<T extends ToStringable>(x: T) {
@peerhenry
peerhenry / settings.json
Created March 1, 2019 21:31
italics for vscode
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"name": "Comment",
"scope": [
"comment",
"punctuation.definition.comment"
],
"settings": {
"fontStyle": "italic",
@peerhenry
peerhenry / setupApiCall.js
Created February 22, 2019 12:44
infi vuex blogpost refactor 4
const validOption = (options, key) => options && options[key] && typeof options[key] === 'function'
const formatOptions = options => {
let result = { }
result.mapPayload = validOption(options, 'handleError') ? options.mapPayload : (context, payload) => payload
result.formatUrl = validOption(options, 'formatUrl') ? options.formatUrl : (context, payload, url) => url
result.handleResponse = validOption(options, 'handleResponse') ? options.handleResponse : _ => _
result.handleError = validOption(options, 'handleError') ? options.handleError : _ => _
return result
}
@peerhenry
peerhenry / customerModule.js
Created February 22, 2019 12:43
infi vuex blogpost refactor 3
setupApiCall(
customerModule,
'fetchCustomer',
fetchCustomerUrl,
axios.get,
{
formatUrl: (url, payload) => (fetchCustomerUrl + '?ID=' + payload.customerId),
handleResponse: (context, response) => { context.commit('setCustomer', response.data) }
}
)
@peerhenry
peerhenry / customerModule.js
Last active February 22, 2019 12:41
infi vuex blogpost refactor 2
const customerModule = {
state: { customer: undefined },
getters: {
customer(state) { return state.customer }
},
mutations: {
setCustomer(state, customer) { state.customer = customer }
},
actions: {}
}
@peerhenry
peerhenry / customerModule.js
Created February 22, 2019 12:40
infi vuex blogpost
function fetchCustomer(context, payload) {
context.commit('setFetchCustomerPending', true)
context.commit('setFetchCustomerError', undefined)
const url = fetchCustomerUrl + '?ID=' + payload.customerId
axios.get(url).then(
(response) => {
context.commit('setFetchCustomerPending', false)
context.commit('setCustomer', response.data)
},
(error) => {
@peerhenry
peerhenry / customerModule.js
Created February 22, 2019 12:38
infi vuex boilerplate blogpost
const initialState = {
customer: undefined,
fetchCustomerPending: false,
fetchCustomerError: undefined,
updateCustomerPending: false,
updateCustomerError: undefined,
}
const getters = {
customer(state) {
const initialState = {
client: undefined,
fetchClientPending: false,
fetchClientError: undefined,
updateClientPending: false,
updateClientError: undefined,
}
const getters = {
client(state) {
@peerhenry
peerhenry / mock.auto.ts
Created January 21, 2019 15:25
a script that provides easy mocking of components, pipes and services
import { Type, Component, Pipe, EventEmitter } from '@angular/core';
const ANNOTATIONS = '__annotations__';
const PARAMETERS = '__parameters__';
const PROP_METADATA = '__prop__metadata__';
export type Mocked<T> = { [P in keyof T]: T[P] };
type Constructor<T> = Function & { prototype: T };
export function mockType<T>(type: Constructor<T>, overrides: Partial<T> = {}): Constructor<Mocked<T>> {
@peerhenry
peerhenry / main.rs
Created January 1, 2019 01:31
Taking ownership: copy versus move.
/*
This program outputs:
Bonjour 5
Hello 5
Bonjour 7
Bonjour 11
Hello 11
*/