Skip to content

Instantly share code, notes, and snippets.

View Torthu's full-sized avatar

Torstein Thune Torthu

View GitHub Profile
@Torthu
Torthu / srmToRgbMap.ts
Created December 18, 2023 08:09
Tabell for omregning fra SRM til RGB
interface SRMtoRGBMap {
[key: string]: string;
}
const srmToRgbMap: SRMtoRGBMap = {
"0.1": "248,248,230",
"0.2": "248,248,220",
"0.3": "247,247,199",
"0.4": "244,249,185",
"0.5": "247,249,180",
@Torthu
Torthu / mock.ts
Created October 18, 2022 10:14
Mock styled-components with jest
jest.mock('styled-components', () => {
const domElements = [
'a',
'abbr',
'address',
'area',
'article',
'aside',
'audio',
'b',
@Torthu
Torthu / Easing.ts
Created February 16, 2021 09:57
Typescript Class exposing Easing curves as static methods
// Adapted from EASING EQUATIONS by Robert Penner
// @see https://easings.net/
// TERMS OF USE - EASING EQUATIONS
//
// Open source under the BSD License.
//
// Copyright © 2001 Robert Penner
// All rights reserved.
//
@Torthu
Torthu / setStylesheetDynamically.ts
Created January 18, 2021 10:04
Set stylesheet from css
/**
* Appends a stylesheet to document.body (<link rel="stylesheet" type="text/css" href="some-url" />)
* @param stylesheetUrl String URL to stylesheet
* @param cacheBust Function Rand-function that creates a string that will be appended to the stylesheet url to bust browser caching
* @return void
*/
const setStylesheetDynamically = (stylesheetUrl: string, cacheBust?: () => string): void => {
const stylesheet = document.createElement("link");
stylesheet.setAttribute("rel", "stylesheet");
@Torthu
Torthu / CircleProgress.tsx
Last active February 16, 2021 09:33
Circular Progress Bar in SVG/React without CSS
import React from "react";
interface CircleProgressProps {
progress: number;
diameter?: number;
strokeWidth?: number;
className?: string;
progressBackgroundColor?: string;
progressBarColor?: string;
rotation?: number;
@Torthu
Torthu / isUuid.ts
Created December 4, 2020 11:42
Quick UUIDv4 regex/type guard
type UUID = string;
function isUuid(uuid: string): uuid is UUID {
return (
uuid.match(/^[0-9A-Fa-f]{8}(?:-[0-9A-Fa-f]{4}){3}-[0-9A-Fa-f]{12}$/)
?.length > 0
);
}
export default UUID;
@Torthu
Torthu / Babelfish.ts
Last active November 7, 2019 09:37
Quick and dirty i18n lib
let i18nStrings: Object, currentLanguage: string;
// Replace ${var} with {var: 'This Value'}
function simpleStrReplace(str, replace = {}, failWithThrow = false) {
return str.replace(/\$\{(.*?)\}/g, (match) => {
match = match.substring(2, match.length - 1);
return replace[match] || `??[${match}]??`;
});
}
@Torthu
Torthu / PetterYouAreSafe.coffee
Last active December 1, 2020 14:21
Easter egg left for Sixty guys to find
__b = window
__z = [115, 101, 116, 84, 105, 109, 101, 111, 117, 116].map((i) -> return String.fromCharCode(i))
sa = 'UGV0dGVyLCB5b'
__rnd = (z, x, y, r) ->
if not (y? or r?) then return (~~(Math.random() * (x - z + 1)) + z) else return sa + r + Math.random().toString(36)
cnonce = __rnd(1 + (50 >> 7), -1 * (50 >> 7) + 1)
a = (49 << cnonce) + 1
b = (223 >> cnonce)
x = (115 >> 1) * 2 + cnonce
xsa = __rnd(a, x, sa, cnonce)
@Torthu
Torthu / gist:d20ece8488849ae09bb3126e8b21fa25
Created July 6, 2017 11:17
Disable SSL cert checks in Chrome on Mac OS
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --ignore-certificate-errors &> /dev/null &
@Torthu
Torthu / tohtml.md
Created February 15, 2017 15:58
chm to html

$ brew install chmlib $ extract_chm infile outfile