Skip to content

Instantly share code, notes, and snippets.

@ericzakariasson
ericzakariasson / customQueryString.js
Last active August 23, 2018 07:06
Custom query string formatter for use in input fields
/* Declare shortcuts and types */
const fieldMap = {
a: {
name: 'address',
type: String
},
s: {
name: 'approved',
type: Boolean,
relation: {
@font-face {
font-family: 'Karmilla';
src: local('Karmilla'), url('./fonts/karmilla-bold-016-webfont.woff2') format('woff2');
font-weight: 700;
font-style: normal;
}
@font-face {
font-family: 'Karmilla';
src: local('Karmilla'), url('./fonts/karmilla-regular-016-webfont.woff2') format('woff2');
@ericzakariasson
ericzakariasson / representation.js
Last active August 14, 2019 11:09
Skatteverket Representation
const getSumOfTaxPerPerson = ({ rate, peopleCount, primary, secondary}) => ((primary / (primary + secondary)) * 300 * peopleCount * rate)
const getDeductableNotFika = ({
peopleCount,
tax12,
tax25,
}) => {
const tax12_exVat = tax12 / 1.12;
const tax25_exVat = tax25 / 1.25;
function useLocalStorage() {
const get = key => localStorage.getItem(key);
const set = (key, value) = localStorage.setItem(key, value);
return [get, set];
}
const Example = () => {
const [getLocalStorage, setLocalStorage] = useLocalStorage();
/*
Guven an island with the shape of this:
__
__|__| __
__ |__|__| __ __|__|
|__| __|__|__|__|__| |__|__|__
|__|__|__|__|__|__|__|__ __ |__|__|__|__
__|__|__|__|__|__|__|__|__|__|__|__|__|__|__|__|
[0, 3, 1, 2, 4, 5, 2, 3, 1, 0, 1, 0, 3, 4, 2, 1] => 18
import React, { useCallback, useEffect, useRef, useState } from 'react'
// Types to be shared with frontend and backend
interface ApiResponseInfo {
code: number
message: string
[key: string]: unknown
}
interface ApiResponseCommon {
def matrix_multiplication(a, b):
if len(b) == 0 or len(a) == 0:
return []
c = []
for i in range(len(a)):
c.append([])
for j in range(len(b[0])):
c[-1].append(0.0)
import { act, renderHook } from "@testing-library/react-hooks";
import { useArray } from "./useArray";
describe("useArray", () => {
describe("props", () => {
it("should have initial state", () => {
const { result } = renderHook(() =>
useArray({
initialState: ["a", "b", "c"],
class InternalError extends Error {}
type Predicate<T> = (item: T) => boolean;
function single<T>(array: T[], predicate?: Predicate<T>) {
const items = predicate ? array.filter(predicate) : array;
if (items.length !== 1) {
throw new InternalError("Array does not contain exactly one item");
}
@ericzakariasson
ericzakariasson / sql.helper.ts
Last active December 1, 2021 15:26
SQL helper
export enum TextInputTypes {
Raw,
Parameter,
}
export type Primitive = string | number | boolean;
export interface TextInputObject<Type extends TextInputTypes> {
type: Type;
value: Primitive;