Skip to content

Instantly share code, notes, and snippets.

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

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

🇮🇱
עם ישראל חי
View GitHub Profile
@bennypowers
bennypowers / paper-button.css
Last active September 27, 2016 12:51
paper-button image accessibility
/* Provide visual feedback of keyboard focus
* when paper-button has an image instead of a label
*/
paper-button {
--paper-button-flat-keyboard-focus: {
@apply(--shadow-elevation-2dp);
}
}
@bennypowers
bennypowers / serviceWorker-clicktoreload.js
Last active June 23, 2017 12:39
New Version Available. Click to Reload
// Polymer Starter Kit App
// my-app, in `ready` callback
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js')
.then((registration) => {
registration.onupdatefound = (event) => {
let installingWorker = registration.installing;
installingWorker.onstatechange = (event) => {
/**
* Author: Jason Farrell
* Author URI: http://useallfive.com/
*
* Description: Checks if a DOM element is truly visible.
* Package URL: https://github.com/UseAllFive/true-visibility
*/
function isVisible(node) {
'use strict';
@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
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 / 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() {
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 / 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])
@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 / 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)