Skip to content

Instantly share code, notes, and snippets.

View bozdoz's full-sized avatar
☠️
I may be dead

bozdoz bozdoz

☠️
I may be dead
View GitHub Profile
@bozdoz
bozdoz / exclusive_enums.go
Created November 6, 2022 14:57
exclusive_enums.go
package main
type dessert int
const (
ICE_CREAM dessert = iota
CUP_CAKES
GUMMY_WORMS
)
@bozdoz
bozdoz / remote-diverged.sh
Last active August 1, 2023 13:47
find remote branches that have diverged by some amount of commits
git ls-remote --heads origin | while read sha ref; do
behind=`git rev-list $sha..master --count`
if [ $behind -ge 1000 ]; then
echo "$ref $behind";
fi
done
[alias]
rebase-since = !sh -c 'git rebase -i $(git merge-base --fork-point \"${1:-master}\" HEAD)' -
graph = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue) <%an>%Creset' --abbrev-commit --date=relative
@bozdoz
bozdoz / getElemByText.js
Created April 25, 2021 03:57
JavaScript document XPath text selector
function getElemByText(text) {
return document.evaluate(
`//*[contains(translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '${text}')]`,
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue;
}
@bozdoz
bozdoz / defaultProps.d.ts
Last active April 19, 2021 16:53
Defining DefaultProps with HOC
import React from 'react';
const withTheme = <P extends {}>(Comp: React.ComponentType<P>) => {
return Comp as any as React.ForwardRefExoticComponent<
React.PropsWithoutRef<P> &
React.RefAttributes<any>
> & {
defaultProps: typeof Comp['defaultProps'];
};
}
@bozdoz
bozdoz / masterpiece.js
Created March 8, 2021 04:46
Masterpiece JS
var readyToGo;
function prep_load () {
var enclosed,
data = 'function setSavedScenario () {' +
'return function () {' +
'readyToGo = function () {' +
'window.setTimeout(function () {' +
// this is just to show that the code "works"
'document.body.className = "blue";' +
@bozdoz
bozdoz / addLongTouch.ts
Last active February 26, 2021 03:39
Add mobile equivalent for contextmenu event; User touches element for a given length of time
/**
* Add mobile equivalent for contextmenu event.
* User touches element for a given length of time
*/
const addLongTouch = (
elem: HTMLElement,
callback: (event: TouchEvent) => void,
delay = 650
): (() => void) => {
let timeout: number;
@bozdoz
bozdoz / typedObjectKeys.ts
Created February 12, 2021 18:39
Typed Object Keys
/** Gets a typed array from Object.keys */
function typedObjectKeys<T extends Record<string, any>>(a: T) {
return Object.keys(a) as (keyof T)[];
}
export default typedObjectKeys;
@bozdoz
bozdoz / types.d.ts
Last active February 23, 2021 02:59
types.d.ts
// https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgILIN4ChnLgIwQC5kQBXAW32h2QBMIYSBnMKUAc1o4AtgTyVGrgBWAawA2JAEoQEAeyh0APK3YgOAGlKVqUAHy0KIeQN3QA2gF0sAXyxYA9ACpnyAPIgJAT2QcIYMgADlDyQdBgwBDMyDChFMgAKsgA7jzQKABucBJkKMAx8jDIYN7hyADSyM6OWKXlnj7KidoV+sgAvMgACsAIYs3a2LgW3cigyGIQ3kVJViSJo1bIEAAekCB0MVUA-D3IAhCZNLYWUzPFiVaGTo7IEsAUwIFg8sjyXr6CesGh4VCRaJ1MooABCnQ8n2UqG032gNwUIFYJWiYBI4K6wzwhBIAEYAEwAZk03D4JAALABWABsJPsQA
/** Only get properties from T where value is of type K */
type Only<T, K> = Pick<T, {
[P in keyof T]: T[P] extends K ? P : never
}[keyof T]>
//
// Writable properties from an interface
//
@bozdoz
bozdoz / robots.txt
Created November 10, 2020 04:05
robots.txt for nofollow noindex
User-agent: *
Disallow: /