Skip to content

Instantly share code, notes, and snippets.

View bennypowers's full-sized avatar
🇮🇱
עם ישראל חי

Benny Powers - עם ישראל חי! bennypowers

🇮🇱
עם ישראל חי
View GitHub Profile
@bennypowers
bennypowers / am-yisrael-hai.html
Last active October 10, 2023 13:55
Am Yisrael Hai Web Component
<am-yisrael-hai>
<template shadowrootmode="open">
<!-- @license public domain -->
<!-- @author bennypowers.dev -->
<style>
:host {
display: contents;
text-align: center;
font-size: 150%;
}
@bennypowers
bennypowers / process.js
Last active July 11, 2023 14:55
Transform a specific instance of shadow CSS to a light dom sheet, with private knowledge of the shadow dom
import postcss from 'postcss';
import { readFile } from 'node:fs/promises';
// load up the shadow dom css sheet,
// taken from the rhds git repo
const content = await readFile(new URL('./rh-cta.css', import.meta.url), 'utf-8');
const HOST_ARGS = /:host\((?<hostArg>[^)]*)\)/g;
const SLOTTED_ARGS = /::slotted\((?<slottedArg>[^)]*)\)/gm;
function setScoreTo(num: number) {
serial.writeValue("score", num)
if (num >= 4) {
win()
} else if (num < 0) {
lose()
} else {
last = rounded
rope = num
rounded = Math.round(rope)
@bennypowers
bennypowers / cheatsheet.md
Created May 22, 2022 16:02
nvim mappings cheatsheet

🔭 Telescope Mappings

Mapping Action
<C-n>/<Down> Next item
<C-p>/<Up> Previous item
j/k Next/previous (in normal mode)
H/M/L Select High/Middle/Low (in normal mode)
@bennypowers
bennypowers / Spec.hs
Created May 24, 2021 09:46
Unit testing with QuickCheck
module Main where
import Data.Sort
import Test.Hspec
import Test.QuickCheck
prop_abs :: Int -> Bool
prop_abs n = abs n == n || 0 - abs n == n
prop_min :: [Int] -> Bool
@bennypowers
bennypowers / starman-improved.hs
Created April 19, 2021 12:46
Starman game from Functional Programming in Haskell Course at U of Glasgow, Slightly Improved
import System.IO
import System.Random
-- The game
check :: String -> String -> Char -> (Bool,String)
check word display c =
(c `elem` word,
[if x == c then c else y | (x, y) <- zip word display])
function getParentPiercingShadowRoots(node: Node): Node {
return (
node instanceof ShadowRoot ? node.host
: (node instanceof Element && node.assignedSlot || node)?.parentNode
);
}
@customElement('elevated-card')
export class ElevatedCard extends LitElement {
static readonly styles = [style];
@bennypowers
bennypowers / graphql-result-accessors.js
Created June 20, 2019 04:10
Using crocks' getPathOr to build accessors for GraphQL query results
import { ApolloQuery, html, customElement } from '@apollo-elements/lit-apollo';
import query from './awesome-rob.graphql'; //use a build transform
import getPathOr from 'crocks/helpers/getPathOr';
const getUserBestFriend = getPathOr({}, ['me', 'friends', 0]);
@customElement('awesome-rob)
class AwesomeRob extends ApolloQuery {
query = query;
render() {
async _registerServiceWorker() {
// Instructions on how to toast the user when necessary. 🍾
const toast = () => this.$.swtoast.open();
// Listen for changes on a new worker, toast when installed. 🍞
const track = (sw) => sw.onstatechange = () => (sw.state === 'installed') && toast();
// Register the service worker
const scope = Polymer.rootPath;
let reg;
try {
reg = await navigator.serviceWorker.register('/service-worker.js', {scope});
@bennypowers
bennypowers / singleton-mixin.html
Created October 3, 2017 21:30
Polymer Singleton Mixin
<link rel="import" href="../../bower_components/polymer/polymer-element.html">
<script>
/**
* @polymer
* @mixinFunction
* @param {class} superClass
* @return {class}
*
* Polymer.SingletonMixin consumers must be defined with a constructor which