Skip to content

Instantly share code, notes, and snippets.

View loopdream's full-sized avatar

Dom Geargeoura loopdream

View GitHub Profile
@loopdream
loopdream / react-feature-flags.js
Created January 11, 2024 14:29 — forked from sergiodxa/react-feature-flags.js
React feature flags context, custom hook, hoc and render prop
import React from "react";
const FeatureFlags = React.createContext(null);
export function FeatureProvider({ features = null, children }) {
if (features === null || typeof features !== "object") {
throw new TypeError("The features prop must be an object or an array.");
}
return (
<FeatureFlags.Provider value={features}>{children}</FeatureFlags.Provider>
/**
* This component comes from https://github.com/tj/react-click-outside.
*
* It was copied and converted to use hooks and TypeScript
*/
import React, { useEffect, useRef } from "react";
export interface Props {
@loopdream
loopdream / gist:4a94bed1c7a63982419b6806c32e3870
Last active March 22, 2018 17:59
Destructured promise All with fetch
async function getTheThings(urls) {
return await Promise.all(urls.map(url => fetch(url)));
}
// usage
const [post, comments] = getTheThings(['/post', '/comments']);
@loopdream
loopdream / translate3d-mixin.scss
Last active March 21, 2018 09:46
Mixin for translate3d support with translate fallback
// Translate3d uses GPU acceleration for increased performance with translate fallback
@mixin translate-x($value) {
will-change: transform
transform: translateX($value);
@supports (transform: translate3d($value, 0, 0)) {
transform: none;
transform: translate3d($value, 0, 0);
}
}
@loopdream
loopdream / type-factory.scss
Last active March 14, 2018 14:49
Type Factory
/*
* a mixin for easy generation of type styles with RTL and Breakpoint support
* uses x-rem: https://gist.github.com/webgefrickel/4530526
* uses Bootstrap media breakpoint mixin - could swap out for your own
* uses RTL mixin: https://gist.github.com/loopdream/ad7b77bd4b88c68afdc74bc0ec58f34b
* Usage:
h5 {
@include type-factory(
@mixin rtl() {
// sass-lint:disable force-attribute-nesting no-qualifying-elements
html[dir='rtl'] & {
@content;
}
// sass-lint:enable force-attribute-nesting no-qualifying-elements
}
# credit: http://www.freytag.org.uk/html/web/gaehttpauth.html
# app engine auth handler class
# The script handler collects the requests for the static HTML and does the HTTP Auth.
# If it is OK, it reads the file off the GAE disk and sends it back.
# This is the same code as the rationalpie blog post, but modified for webapp2 and to include file reading:
# to be used in conjuction with https://gist.github.com/loopdream/7403c12109ddc8d6ca66cafe80616899
"""
auth.py
"""
@loopdream
loopdream / app.yml
Last active January 24, 2017 11:39
# http://www.freytag.org.uk/html/web/gaehttpauth.html
# app engine handlers for serving static files behind basic auth
- url: /your_static_dir/.*.html
script: auth.application
- url: /your_static_dir
static_dir: /your_static_dir
application_readable: true
@loopdream
loopdream / auth.py
Last active January 20, 2017 14:06
App engine python script for only letting certain users view a static site build
from google.appengine.api import users
from base import handlers
class RootHandler(handlers.BaseHandler):
def get(self, path):
email = users.get_current_user().email()
is_google = email.endswith('@somedomain.com')
is_rga = email.endswith('@someotherdomain.com')
is_admin = users.is_current_user_admin()
@loopdream
loopdream / urlHelper.js
Last active October 10, 2015 17:40
Url helper
/**
* Url helper functions
* http://jamesallardice.com/urlutils-a-little-set-of-javascript-url-utility-methods/
*/
urlUtils = {
getParam: function(name) {
var regex = new RegExp('[?&]' + name + '=([^&#]*)'),
results = regex.exec(window.location.href);
if(results) {
return results[1];