Skip to content

Instantly share code, notes, and snippets.

View lindskogen's full-sized avatar
🏃‍♂️

Johan Lindskogen lindskogen

🏃‍♂️
View GitHub Profile
@lindskogen
lindskogen / bufferTime.ts
Created September 16, 2022 17:09
BufferTime higher order saga
import { ActionMatchingPattern } from '@redux-saga/types';
import { ActionPattern, delay, fork, race, take } from 'redux-saga/effects';
export const bufferTime = <P extends ActionPattern, A extends ActionMatchingPattern<P>>(
ms: number,
pattern: P,
worker: (action: A) => any,
mergeFn: (a1: A, a2: A) => A,
) =>
fork(function* () {
@lindskogen
lindskogen / cb.ts
Created May 12, 2021 15:22
Create branch from azure devops assigned tasks
#!/usr/bin/env deno run --quiet --no-check --allow-net=dev.azure.com --allow-run --allow-env=AZURE_DEVOPS_READ_WORK_ITEMS_TOKEN
import * as Colors from "https://deno.land/std@0.96.0/fmt/colors.ts";
import { DOMParser } from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";
const prefix = Deno.args[0] ?? "feature";
const ids_query =
"SELECT [System.Id] FROM workitems WHERE [System.TeamProject] = @project AND [System.State] <> 'Ready for test' AND [System.State] <> 'Parked' AND [System.State] <> 'Removed' AND [System.State] <> 'Tested OK' AND [System.State] <> 'Done' AND [System.AssignedTo] = @me";
const organizationName = "x";
@lindskogen
lindskogen / pollen.1h.py
Last active March 22, 2021 09:43
pollen.1h.py
#!/usr/bin/env LC_ALL=en_US.UTF-8 /usr/local/bin/python3
#
# <bitbar.title>Pollenkoll</bitbar.title>
# <bitbar.version>v0.2</bitbar.version>
# <bitbar.author>lindskogen</bitbar.author>
# <bitbar.author.github>lindskogen</bitbar.author.github>
# <bitbar.desc></bitbar.desc>
# <bitbar.image></bitbar.image>
# <bitbar.dependencies>python</bitbar.dependencies>
@lindskogen
lindskogen / pickbyvaluetype.ts
Last active September 18, 2020 20:54
Typescript Pick by value type
type ExtractKeysByValueType<O, V> = {
[P in keyof O]: O[P] extends V ? P : never;
}[keyof O]
type PickByValueType<O, V> = Pick<O, ExtractKeysByValueType<O, V>>
type OmitByValueType<O, V> = Omit<O, ExtractKeysByValueType<O, V>>
// Usage:
@lindskogen
lindskogen / BluetoothCentral.swift
Last active June 17, 2019 09:40
Sketch of a BindableObject for finding friends by local PTP
//
// BluetoothCentral.swift
//
// Created by Johan Lindskogen on 2019-06-16.
// Copyright © 2019 Johan Lindskogen. All rights reserved.
//
import SwiftUI
import CoreBluetooth
import Combine
@lindskogen
lindskogen / ActivityIndicator.swift
Created June 12, 2019 21:01
SwiftUI Wrapper for UIActivityIndicator
import SwiftUI
import UIKit
struct ActivityIndicator : UIViewRepresentable {
var animating: Bool
var hidesWhenStopped = true
var style: UIActivityIndicatorView.Style = UIActivityIndicatorView.Style.medium
func makeUIView(context: Context) -> UIActivityIndicatorView {
let control = UIActivityIndicatorView()
@lindskogen
lindskogen / fix_steam.sh
Created August 9, 2017 16:29
Steam case-sensitivity macOS
#!/bin/bash
## Try to use following solution.
## ------------------------------------
USER=$(whoami)
cd /Users/$USER/Library/Application\ Support/Steam/Steam.AppBundle/Steam/Contents/MacOS/public; ls *.res | while read line ; do file=$(echo $line | tr '[:upper:]' '[:lower:]'); mv $line $file; done
cd /Users/$USER/Library/Application\ Support/Steam/Steam.AppBundle/Steam/Contents/MacOS/steam/cached/; ls *.res | while read line ; do file=$(echo $line | tr '[:upper:]' '[:lower:]'); mv $line $file; done
cd /Users/$USER/Library/Application\ Support/Steam/Steam.AppBundle/Steam/Contents/MacOS/friends; ls *.res | while read line ; do file=$(echo $line | tr '[:upper:]' '[:lower:]'); mv $line $file; done
cd /Users/$USER/Library/Application\ Support/Steam/Steam.AppBundle/Steam/Contents/MacOS/graphics; ls *.res | while read line ; do file=$(echo $line | tr '[:upper:]' '[:lower:]'); mv $line $file; done
cd /Users/$USER/Library/Application\ Support/Steam/Steam.AppBundle/Steam/Contents/MacOS/servers; ls *.res | while read l
@lindskogen
lindskogen / find_circles.py
Created June 26, 2017 16:32
ML circle detection
# Standard imports
import cv2
import numpy as np
# Read image
img = cv2.imread("IMG_20170624_152655.jpg", 0)
img = cv2.medianBlur(img, 5)
cimg = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
# Set up the detector with default parameters.
@lindskogen
lindskogen / checkbox.js
Created June 26, 2017 14:59
Accessible checkbox in react
import React, { PureComponent } from 'react';
import cx from 'classnames';
import './checkbox.styl';
const SPACE_KEY = 32;
const filterSpacePressed = (event, callback) => {
if (event.which === SPACE_KEY) {
event.preventDefault();
@lindskogen
lindskogen / convertDraftToHTML.js
Created May 23, 2017 09:00
Convert DraftJS ContentState to html (only plaintext and mentions)
// @flow
import { RawDraftContentState } from 'draft-js'
type Mention = {
link: string,
name: string,
fullName: ?string,
id: number,
avatar: string
}