Skip to content

Instantly share code, notes, and snippets.

View ieatfood's full-sized avatar
🐈‍⬛
Is a cat

Kuba Holuj ieatfood

🐈‍⬛
Is a cat
View GitHub Profile
/**
* Returns an array of the specified enum type with values that are the
* intersection of the array and enum type.
*
* Example:
* convertArrayToEnumType(["VISA", "CARTES_BANCAIRES"], AllowedCardNetworks)
* => ["VISA"]
*/
export function convertArrayToEnumType<S, T extends string>(arr: Array<S>, type: Record<T, T>): Array<T> {
return arr.filter((k) => Object.keys(type).includes((k as unknown) as T)).map((k) => (k as unknown) as T);
@ieatfood
ieatfood / Connect Airpods.applescript
Last active February 18, 2024 22:25 — forked from jaredmoody/Connect Airpods.applescript
An Applescript to connect bluetooth devices, such as Airpods. Nice when paired with an alfred trigger.
# Taken from https://www.reddit.com/r/MacOS/comments/i4czgu/big_sur_airpods_script/gck3gz3/
# by https://github.com/smithumble
use framework "IOBluetooth"
use scripting additions
set AirPodsName to "AirPods"
on getFirstMatchingDevice(deviceName)
repeat with device in (current application's IOBluetoothDevice's pairedDevices() as list)
@ieatfood
ieatfood / tmsource.js
Created July 19, 2017 20:42
Set Theatre Manager's `tmsource` cookie based on `tmsource` or `utm_source` query parameters.
(setTimeout(function () {
var TM_PARAM_NAME = 'tmsource';
var UTM_PARAMS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content'];
var COOKIE_NAME = 'tmsource';
var COOKIE_EXPIRES_DAYS = 60;
var LOCATION = window.location;
var URL = LOCATION.href;
var COOKIE_DOMAIN = LOCATION.hostname.replace(/^www\./, '');
function getParameterByName(name) {
@ieatfood
ieatfood / Grafana_Tooltip_Sort_Bookmarklet.js
Last active March 27, 2017 22:25
Grafana Tooltip Sort Bookmarklet
/**
* Minified with http://ted.mielczarek.org/code/mozilla/bookmarklet.html
*/
javascript:(function(){function observe(){var observer=new MutationObserver(sortTooltip);observer.observe(document.body,{childList:true});}function sortTooltip(){var tooltip=$('#tooltip');if(!tooltip.length){return;}var items=$('#tooltip > .graph-tooltip-list-item');items.sort((a,b)=>strToNum($('.graph-tooltip-value',a).text())>strToNum($('.graph-tooltip-value',b).text())?-1:1);items.detach().appendTo(tooltip);}function strToNum(str){var num=parseFloat(str);if(isNaN(num)){return-1;}if(str.indexOf('K')>-1){return num*1000;}if(str.indexOf('Mil')>-1){return num*1000000;}if(str.indexOf('min')>-1){return num*60000;}if(str.indexOf('ms')>-1){return num*1;}if(str.indexOf('s')>-1){return num*1000;}return parseFloat(str);}observe();})();
/**
* Unminified:
*/
function observe () {