Skip to content

Instantly share code, notes, and snippets.

View CaptainN's full-sized avatar

Kevin Newman CaptainN

View GitHub Profile
@CaptainN
CaptainN / just-prefix.js
Created June 4, 2012 23:02
Gets proprietary CSS prefix for current browser - reduced from StyleFix
/**
* prefix method reduced from StyleFix 1.0.2
* @author Lea Verou
* MIT license
*/
var prefix = (function() {
if (!window.getComputedStyle) return '';
var prefixes = {},
properties = [],
@CaptainN
CaptainN / backfill.MarkerImage.js
Created June 28, 2013 16:51
a backfill for the deprecated google.maps.MarkerImage
// Backfill deprecated MarkerImage
function MarkerImage(url, size, origin, anchor, scaledSize)
{
if (console && console.warn)
console.warn("google.maps.MarkerImage is deprecated. Use a vanilla JS Object.");
this.anchor = anchor;
this.origin = origin;
this.scaledSize = scaledSize;
this.size = size;
this.url = url;
@CaptainN
CaptainN / reset.css
Last active December 6, 2017 18:25
Simple CSS Reset
/*---------------/
/ simple reset /
/---------------*/
html, body, ul, ol, li, form, fieldset, legend {
margin: 0;
padding: 0;
}
li { list-style: none; }
body {
@CaptainN
CaptainN / variable.css
Created June 21, 2018 23:41
variable web font with cascade
@font-face {
font-family: 'Avenir Variable';
src: url('/anv/anv-roman-var.woff2') format('woff2-variations');
src: url('/anv/anv-roman-var.woff2') format('woff2' supports variations);
font-weight: 1 999;
}
@font-face {
font-family: 'Avenir Static';
src: url('/anv/anv-medium.woff') format('woff');
@CaptainN
CaptainN / meteor-hook-examples.jsx
Last active January 2, 2020 06:20
example code for meteor hook
// Hook, basic use, everything in one component
const MyAccount = () => {
const { user, isLoggedIn } = useTracker(() => {
const user = Meteor.user()
const userId = Meteor.userId()
return {
user,
userId,
isLoggedIn: !!userId
}
@CaptainN
CaptainN / Meteor Containers from Hooks.jsx
Last active January 28, 2020 20:48
Meteor Containers from Hooks
import { useTracker } from 'meteor/react-meteor-data'
// We can easily make old style HOCs out of the hooks
const withUser = (Component) => (props) => {
const accountProps = useAccount()
return <Component {...props} {...accountProps} />
}
const withPage = (Component) => (props) => (
const pageProps = usePage(props.pageId)
return <Component {...props} {...pageProps} />
@CaptainN
CaptainN / Meteor Prefab Hook.jsx
Last active January 28, 2020 20:48
Meteor Prefab Hook
import { useTracker } from 'meteor/react-meteor-data'
// Create a reusable hook
const usePage = (pageId) => useTracker(() => {
// The publication must also be secure
const subscription = Meteor.subscribe('page', pageId)
const page = Pages.findOne({ _id: pageId })
return {
page,
isLoading: !subscription.ready()
@CaptainN
CaptainN / Meteor Containers.jsx
Last active January 28, 2020 20:49
Meteor Containers
import { withTracker } from 'meteor/react-meteor-data'
// Create a reusable hook
const withAccount = withTracker((props) => {
const user = Meteor.user()
const userId = Meteor.userId()
return {
user,
userId,
isLoggedIn: !!userId
@CaptainN
CaptainN / Meteor Robust Prefab Hooks.jsx
Last active January 31, 2020 18:15
Meteor Robust Prefab Hooks
import { useTracker } from 'meteor/react-meteor-data'
// Create a reusable hook
const useAccount = () => useTracker(() => {
const user = Meteor.user()
const userId = Meteor.userId()
return {
user,
userId,
isLoggedIn: !!userId
@CaptainN
CaptainN / Meteor Robust useTracker.jsx
Last active March 12, 2020 21:33
Meteor Robust useTracker
import { useTracker } from 'meteor/react-meteor-data'
// Hook, basic use, everything in one component
const MyProtectedPage = (pageId) => {
const { user, isLoggedIn, page } = useTracker(() => {
// The publication must also be secure
const subscription = Meteor.subscribe('page', pageId)
const page = Pages.findOne({ _id: pageId })
const user = Meteor.user()
const userId = Meteor.userId()