Skip to content

Instantly share code, notes, and snippets.

View lenkan's full-sized avatar

Daniel Lenksjö lenkan

  • Stockholm, Sweden
View GitHub Profile
#!/bin/bash
install_keri() {
if [[ ! -d .venv ]]; then
python3.12 -m venv .venv
fi
source .venv/bin/activate
pip install keri==1.2.4
console.log(`Hello Cygni!`);
@lenkan
lenkan / musicbrainz_client.js
Created September 19, 2020 13:18
Musicbrainz client
async function fetchJson(url) {
const response = await fetch(url);
if (!response.ok) {
throw new Error(
`GET ${url} ${response.status} - ${response.statusText} `,
);
}
return response.json();
}
@lenkan
lenkan / mock.ts
Created June 2, 2020 20:17
Typescript mock functions for deno
export type MockImplementation<T = any, Y extends any[] = any> = (
...args: Y
) => T;
export interface Mock<T = any, Y extends any[] = any> {
calls: Y[];
reset(): void;
setImplementation(impl: MockImplementation<T, Y>): Mock<T, Y>;
}
@lenkan
lenkan / deno_templates.ts
Last active January 11, 2020 11:39
Deno templates import error
// https://github.com/microsoft/TypeScript/issues/30878
// https://github.com/denoland/deno/issues/3089
console.log(`${"dummy string"}`)
console.log(`import { foo } from "./bar.ts"`)
const algolia = require("algoliasearch")
const client = algolia(ALGOLIA_APPLICATIONID, ALGOLIA_APIKEY)
async function run() {
const source = client.initIndex("test-index-from")
const target = client.initIndex("test-index-to")
const task = await client.copyIndex(source.indexName, target.indexName)
await source.waitTask(task.taskID)
}
@lenkan
lenkan / use-location.js
Created March 2, 2019 18:26
React hook that keeps up to date with the current location.
// @ts-check
import { useState, useEffect } from 'react'
function getCurrentLocation () {
return {
pathname: window.location.pathname,
search: window.location.search
}
}
@lenkan
lenkan / use-location.js
Created March 2, 2019 18:26
React hook that keeps up to date with the current location.
// @ts-check
import { useState, useEffect } from 'react'
function getCurrentLocation () {
return {
pathname: window.location.pathname,
search: window.location.search
}
}
@lenkan
lenkan / use-iterator.js
Created March 2, 2019 16:12
React hook get state from an iterator
// @ts-check
import { useState, useEffect } from 'react'
/**
* @param {() => AsyncIterableIterator<T>} iterator
* @param {T} [defaultValue]
* @returns {T}
* @template T
*/
export function useIterator (iterator, defaultValue) {
using NUnit.Framework;
using System.Collections.Generic;
using System.Linq;
namespace ClassLibrary2
{
[TestFixture]
public class TestFixture
{