Skip to content

Instantly share code, notes, and snippets.

@wtask
wtask / functional-options.go
Last active June 17, 2022 22:48
Golang functional options pattern by Dave Cheney with little improvments due to practice.
// optionsptrn - inspired by https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis
package optionsptrn
import (
"errors"
"time"
// ...
)
// service - to implement SomeInterface.
@getify
getify / 1.js
Last active June 2, 2020 11:07
multiple-field sorter
var data = [
{ a: 4, b: 12, c: "elderberry" },
{ a: 2, b: 10, c: "cherry", d: 4 },
{ a: 4, b: 12, c: "durian" },
{ a: 2, b: 10, c: "cherry", },
{ a: 3, b: 12, c: "durian" },
{ a: 1, b: 10, c: "apple", },
{ a: 1, b: 11, c: "apple", },
{ a: 1, b: 11, c: "banana", },
{ a: 2, b: 10, c: "banana", },
@tbranyen
tbranyen / events.js
Last active May 10, 2024 14:54
Rethinking events using ES6 (https://tbranyen.com/events)
const bus = {};
const get = e => (bus[e] = bus[e] || new Set());
export const listeners = new Proxy(bus, { get });
export const emit = (e, ...args) => listeners[e].forEach(fn => fn(...args));

Some Recommended Kotlin Resources

Books

Kotlin Programming: The Big Nerd Ranch Guide
Josh Skeen, David Greenhalgh
First on the list for a reason.

This is the most well-rounded Kotlin book I have come across. It was written by teachers, has exercises at the end of chapters, recommendations for clean/idiomatic code, and doesn't lend on prior Java knowledge. Additionally it was released in 2018 so it includes more of the recent language features.
Safari

@jessamynwest
jessamynwest / peacefuleasygmail.css
Last active April 23, 2024 18:35
Slightly calmer gmail
@-moz-document url-prefix("https://mail.google.com/mail/") {
/*
*****
This style is based off of Nicer New Gmail but it's really more of a slash and burn approach.
NO COLORS except tiny bit of red and yellow and some blue I can't get rid of.
I know just enough CSS to be dangerous and not enough to really make things work correctly. Some things it
chokes on:
- tabs! I don't use them so who cares what they look like
- hangout/chat tab - I disabled this as soon as they added it, maybe it's blue, I don't know
@bradwilson
bradwilson / ConvertTo-MP3.ps1
Last active March 9, 2020 18:33
Converts FLAC/MP3 input, resamples down to ReplayGain levels, and converts to MP3. Requires on the path: flac, metaflac, ffmpeg, mogrify
param(
[string][Parameter(Mandatory=$true)]$InputFile,
[string][Parameter(Mandatory=$true)]$OutputFile,
[int]$SampleRate = 44100,
[string]$BitRate = "160k"
)
$ErrorActionPreference = "Stop"
$InputFile = [System.IO.Path]::Combine((Get-Location), $InputFile)
@xt0rted
xt0rted / 2017.vsconfig
Last active October 19, 2022 18:12
Boxstarter script for setting up my dev environment
{
"version": "1.0",
"components": [
"Microsoft.VisualStudio.Component.CoreEditor",
"Microsoft.VisualStudio.Workload.CoreEditor",
"Microsoft.VisualStudio.Component.Roslyn.Compiler",
"Microsoft.Component.MSBuild",
"Microsoft.VisualStudio.Component.Static.Analysis.Tools",
"Microsoft.VisualStudio.Component.Roslyn.LanguageServices",
"Microsoft.VisualStudio.Component.PortableLibrary",

Strings

String.prototype.*

None of the string methods modify this – they always return fresh strings.

  • charAt(pos: number): string ES1

    Returns the character at index pos, as a string (JavaScript does not have a datatype for characters). str[i] is equivalent to str.charAt(i) and more concise (caveat: may not work on old engines).

@bradwilson
bradwilson / docker-clean.ps1
Created February 7, 2018 00:36
Docker Cleanup
(& docker images --all --quiet --filter 'dangling=true') | Foreach-Object {
& docker rmi $_ | out-null
}
(& docker ps --quiet --filter 'status=exited' ) | Foreach-Object {
& docker rm $_ | out-null
}
// MIT License
//
// Copyright (c) 2018 Kristian Hellang
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: