Skip to content

Instantly share code, notes, and snippets.

View test.ino
/*
This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
@Kamshak
Kamshak / undiscriminate.ts
Created Mar 3, 2020
Undiscriminiate in Typescript
View undiscriminate.ts
type DiscriminateMessageType<
A,
T extends BookingMessageNotification['bookingMessageType']
> = A extends BookingMessageNotification ?
T extends A['bookingMessageType'] ? A : never
: never;
asMsg<T extends BookingMessageNotification['bookingMessageType']>(type: T): DiscriminateMessageType<BookingMessageNotification, T> {
return this._entry as any;
@Kamshak
Kamshak / README.md
Created Dec 7, 2019 — forked from peak-load/README.md
Headless A2DP Audio Streaming on Raspbian Stretch
View README.md

About

This gist will show how to setup Raspbian Stretch as a headless Bluetooth A2DP audio sink. This will allow your phone, laptop or other Bluetooth device to play audio wirelessly through a Rasperry Pi.

Motivation

A quick search will turn up a plethora of tutorials on setting up A2DP on the Raspberry Pi. However, I felt this gist was necessary because this solution is:

  • Automatic & Headless - Once setup, the system is entirely automatic. No user iteration is required to pair, connect or start playback. Therefore the Raspberry Pi can be run headless.
  • Simple - This solution has few dependencies, readily available packages and minimal configuration.
  • Up to date - As of December 2017. Written for Raspbian Stretch & Bluez 5.43

Prerequisites

@Kamshak
Kamshak / README.md
Last active Dec 7, 2019 — forked from peak-load/README.md
Headless A2DP Audio Streaming on Raspbian Stretch
View README.md

About

This gist will show how to setup Raspbian Stretch as a headless Bluetooth A2DP audio sink. This will allow your phone, laptop or other Bluetooth device to play audio wirelessly through a Rasperry Pi.

Motivation

A quick search will turn up a plethora of tutorials on setting up A2DP on the Raspberry Pi. However, I felt this gist was necessary because this solution is:

  • Automatic & Headless - Once setup, the system is entirely automatic. No user iteration is required to pair, connect or start playback. Therefore the Raspberry Pi can be run headless.
  • Simple - This solution has few dependencies, readily available packages and minimal configuration.
  • Up to date - As of December 2017. Written for Raspbian Stretch & Bluez 5.43

Prerequisites

@Kamshak
Kamshak / retry.ts
Created Aug 8, 2019
Retry rate limited request on node using bluebird-retry
View retry.ts
import * as retry from 'bluebird-retry';
function isRateLimitOrTempError(err: Error & { statusCode?: number }) {
return err.statusCode && (
err.statusCode == 429 // Rate Limit
|| err.statusCode == 502 // Temporary error, retry again
);
}
function retryOnRateLimited<T>(request: () => Promise<T>): Promise<T> {
return retry(request, {
@Kamshak
Kamshak / discriminate.ts
Created Apr 9, 2019
discriminated union discriminate out
View discriminate.ts
export type Discriminate<
Union,
Prop extends keyof Union,
Discriminator extends Union[Prop],
> = Union extends { [T in Prop]: Extract<Union[Prop], Discriminator> } ? Union : never;
export type DiscriminateByType<
Union extends { type: any },
D extends Union['type']
> = Discriminate<Union, 'type', D>;
@Kamshak
Kamshak / README.md
Created Jan 18, 2019
Fixes SVG Gradients for Safari by changing fill URLs to the current pathname. Also fixes xlink:href URLs.
View README.md

Snippet to fix SVG issues in Angular (2+) with Safari, Firefox and Chrome

This listens to Angular route changes and on route change does the following:

  1. Replaces the link in <use xlink:href="#some-id"></use> by a path prefixed version
  2. Replaces the fill property in referenced SVGs by a path prefixed version
  3. Replaces the style in <svg style="fill: url(#gradient)"> with a prefixed version

Adapted from Gist by Leon Derijke

View border.html
<html>
<head>
<style>
.rounded-corners-gradient-borders {
width: 300px;
height: 80px;
border: double 2px transparent;
border-radius: 80px;
background-image: linear-gradient(white, white), radial-gradient(circle at top left, #f00,#3020ff);
background-origin: border-box;
@Kamshak
Kamshak / SketchSystems.spec
Last active Sep 28, 2018
Draft Email Flow
View SketchSystems.spec
Draft Email Flow
Clicked CTA
No action for one hour? -> Aborted Creation
Create Draft -> Initial Creation
Draft Created
Publish Trip -> Draft Published
Initial Creation*
Change Trip -> Initial Creation
No action for 1 hour? -> Active
Active
@Kamshak
Kamshak / Add New Button.md
Last active Jun 13, 2018
Pointshop 2 - Add external menu button
View Add New Button.md

Adding a button to the PS2 Inventory section

It's easy to add a button that opens another menu. Here a report menu button was added:

img

Create a new file in garrysmod/lua/autorun/ps2_extrabuttons.lua with the following contents:

AddCSLuaFile()
Pointshop2:AddInventoryButton( "Report Menu", "pointshop2/warning8.png", function( )
  -- Run console command to open the report menu