Skip to content

Instantly share code, notes, and snippets.

View Gomah's full-sized avatar
⚗️

Thomas Marrec Gomah

⚗️
View GitHub Profile
@Gomah
Gomah / 1. useResponsiveVariant.ts
Last active April 3, 2024 22:13
Responsive Variants with CVA, class-variance-authority
import { useMediaQuery } from 'usehooks-ts'
import { useMemo } from 'react';
import resolveConfig from 'tailwindcss/resolveConfig';
import tailwindConfig from '../../tailwind.config';
const fullConfig = resolveConfig(tailwindConfig);
const { screens } = fullConfig.theme;
type Breakpoints = keyof typeof screens;
type ResponsiveValue<T> = T extends boolean ? boolean : T extends string ? T : keyof T;
@Gomah
Gomah / netlify-lambda-vue.js
Created July 10, 2018 23:30
Build & serve Netlify lambda functions with Vue
import buildLambda from 'netlify-lambda/lib/build';
export default async function({ service: { commands, projectOptions } }) {
const { build, serve } = commands;
const buildFn = build.fn;
const serveFn = serve.fn;
build.fn = async (...args) => {
try {
const res = await buildFn(...args);
@Gomah
Gomah / nuxt-apollo-client.js
Created May 16, 2018 13:24
Nuxt apollo client, restore cache on client & optimize SSR
import { ApolloLink } from 'apollo-link';
import { HttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory';
export default ctx => {
const httpLink = new HttpLink({
uri: process.env.PROJECT_GRAPHQL_SERVER,
});
const cache = new InMemoryCache();
<template>
<form>
<p>
<label>
Your Name: <input type="text" name="name" v-model="form.name" />
</label>
</p>
<p>
<label>
Your Email: <input type="email" name="email" v-model="form.email" />
@Gomah
Gomah / Dockerfile
Last active March 23, 2021 14:33
Nuxt.js Dockerfile :: Now.sh
FROM node:10-alpine
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json /usr/src/app/
COPY yarn.lock /usr/src/app/
RUN yarn install
@Gomah
Gomah / raf-polyfill.js
Created October 22, 2017 13:21
requestAnimationFrame polyfill
(() => {
let lastTime = 0;
const vendors = ['ms', 'moz', 'webkit', 'o'];
for (let x = 0; x < vendors.length && !window.requestAnimationFrame; x += 1) {
window.requestAnimationFrame = window[`${vendors[x]}RequestAnimationFrame`];
window.cancelAnimationFrame =
window[`${vendors[x]}CancelAnimationFrame`] ||
window[`${vendors[x]}CancelRequestAnimationFrame`];
}
@Gomah
Gomah / actions.helpers.js
Created September 20, 2017 07:32
Unit testing for vuex actions using jest
const testAction = (action, payload, state, expectedMutations, done) => {
let count = 0;
// mock commit
const commit = (type, payload) => {
const mutation = expectedMutations[count];
try {
expect(mutation.type).toEqual(type);
if (payload) {
@Gomah
Gomah / uploaded.net.js
Created August 27, 2017 00:59
Login support for uploaded.net
import axios from 'axios';
import axiosCookieJarSupport from '@3846masa/axios-cookiejar-support';
import tough from 'tough-cookie';
import FormData from 'form-data';
// Add cookie support for axios
axiosCookieJarSupport(axios);
class Uploaded {
constructor(options) {
export class GraphModel {
/**
* @param {Object} attrs Attributes on the GraphModel.
*/
constructor(attrs) {
Object.defineProperty(this, 'attrs', { value: attrs, enumerable: false });
Object.keys(this.attrs).filter(key => !(key in this)).forEach(key => {
let descriptor;
if (attrs[key] === null) {
descriptor = {
@Gomah
Gomah / lambda-edge-prerender.js
Created July 25, 2017 23:46
Return pre-rendered html files for non-supported browsers
const whitelist = ['chrome', 'crios', 'firefox', 'fxios', 'googlebot'];
const isSupportedBrowser = uas => {
if (uas && Array.isArray(uas) && uas.length > 0) {
return uas.some(ua =>
whitelist.some(w => ua.value.toLowerCase().includes(w))
);
}
return false;
};