Skip to content

Instantly share code, notes, and snippets.

View medatech's full-sized avatar

Martin Adams medatech

View GitHub Profile
@medatech
medatech / gulpfile.js
Created September 24, 2014 10:49
An example of code coverage with Gulp
var gulp = require('gulp');
var istanbul = require('gulp-istanbul');
var mocha = require('gulp-mocha');
gulp.task('test', function (cb) {
gulp.src(['lib/**/*.js', 'web.js', 'api.js'])
.pipe(istanbul()) // Covering files
.on('finish', function () {
gulp.src(['test/**/*.js'])
.pipe(mocha())
const co = require('co');
const Benchmark = require('benchmark');
function asyncOp () {
return new Promise((fulfill, reject) => {
fulfill('ok');
});
}
function yieldAction () {
@medatech
medatech / useEnsureOnScreen.js
Created May 14, 2020 11:15
Ensure that an element is always on screen
import { useEffect } from "react"
/**
* This hook takes an element and ensures that it does not go outside the bounds of the viewport. It is useful
* for things like a context menu where you don't want the menu to appear off screen.
*
* The only requriements for the DOM reference passed in is that it is absolutely positioned.
* To prevent it flickering in the original place and then moving with the correction, set the visibility CSS attribute
* of the DOM element to 'hidden'. This hook will set it to 'visible' when it has computed the corrected position
*
@medatech
medatech / ReachComponent.code-snippets
Last active May 30, 2020 05:58
React Component Rich Snippet
{
"Styled Component": {
"scope": "javascript",
"prefix": [
"styled",
"styled-component"
],
"body": [
"import React from \"react\"",
"import PropTypes from \"prop-types\"",
---
apiVersion: "v1"
kind: "Service"
metadata:
name: "nginx-hello-world"
labels:
app: "hello-world"
annotations:
load-balancer.hetzner.cloud/name: "devopslb"
load-balancer.hetzner.cloud/health-check-port: "10254"