Skip to content

Instantly share code, notes, and snippets.

View lenkan's full-sized avatar

Daniel Lenksjö lenkan

  • Stockholm, Sweden
View GitHub Profile
@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 / 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 / JsonContent.cs
Created October 30, 2016 14:20
A System.Net.Http.HttpContent for json data
using System.Net.Http;
using System.Text;
using Newtonsoft.Json;
namespace Lenkan.StrengthLog.Data.Couch
{
public class JsonContent : StringContent
{
public JsonContent(string s) : base(s, Encoding.UTF8, "application/json")
{ }
@earthgecko
earthgecko / bash.generate.random.alphanumeric.string.sh
Last active November 9, 2024 08:57
shell/bash generate random alphanumeric string
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1
@mathewbyrne
mathewbyrne / slugify.js
Created October 12, 2011 04:34
Javascript Slugify
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}