Skip to content

Instantly share code, notes, and snippets.

Avatar
🌱
🅱enjick

Max Malm benjick

🌱
🅱enjick
View GitHub Profile
View Post.js
function Post({id}) {
const [post, setPost] = useState(null)
const [hasLiked, setHasLiked] = useState(false)
useEffect(() => {
const unsubscribe = db.collection('posts').doc(id).onSnapshot((doc) => {
const data = doc.data();
setPost(data);
setHasLiked(data.likedBy[myUserID] === true)
});
return () => unsubscribe()
View deploy-helm-pulumi.ts
import * as pulumi from '@pulumi/pulumi';
import * as awsx from '@pulumi/awsx';
import * as k8s from '@pulumi/kubernetes';
import * as docker from '@pulumi/docker';
// Get kubeconfig from main repository
const env = pulumi.getStack();
const cluster = new pulumi.StackReference(`user/infrastructure/${env}`);
const kubeconfig = cluster.getOutput('kubeconfig');
const baseDomain = cluster.getOutput('baseDomain');
@benjick
benjick / Dockerfile
Last active Jun 7, 2020
vue-storefront in Docker and Kubernetes
View Dockerfile
FROM mhart/alpine-node:12
EXPOSE 3000
ENV VS_ENV prod
WORKDIR /var/www
RUN apk add --no-cache make gcc g++ python links bash
COPY . .
RUN yarn install --no-cache
@benjick
benjick / cleanup-magento.sql
Last active May 14, 2020 — forked from mrkhoa99/Clean up database Magento 2
Clean up database Magento 2 for local enviroment
View cleanup-magento.sql
# Orders, Invoices, Shipments
DELETE FROM sales_order;
DELETE FROM sales_creditmemo_comment;
DELETE FROM sales_creditmemo_item;
DELETE FROM sales_creditmemo;
DELETE FROM sales_creditmemo_grid;
DELETE FROM sales_invoice_comment;
DELETE FROM sales_invoice_item;
DELETE FROM sales_invoice;
DELETE FROM sales_invoice_grid;
@benjick
benjick / beforeEach.ts
Created Jun 18, 2019
Wanted to intercept and force a storeCode in Vue Storefront
View beforeEach.ts
import { Route } from 'vue-router'
import store from '@vue-storefront/core/store'
import { isServer } from '@vue-storefront/core/helpers'
import { storeCodeFromRoute, localizedRoute } from '@vue-storefront/core/lib/multistore'
import Vue from 'vue'
export function beforeEach(to: Route, from: Route, next) {
if (isServer) {
const { storeViews } = store.state.config
const storeCode = storeCodeFromRoute(to)
View site.js
import React from 'react';
import Site from './models/Site';
export const Context = React.createContext();
export function useSite() {
return React.useContext(Context);
}
export function SiteWrapper(props) {
View mailer.js
const { send, text } = require('micro')
const post = require('micro-post')
const redirect = require('micro-redirect')
const qs = require('qs');
const mailgun = require('mailgun.js');
const fetch = require('node-fetch');
const cheerio = require('cheerio');
const domain = process.env.MAILGUN_DOMAIN;
const sender = process.env.MAILGUN_SENDER;
@benjick
benjick / router.js
Last active Jun 20, 2017
mobx router
View router.js
import Route from 'route-parser';
import {extendObservable, computed} from 'mobx';
class Router {
constructor(routes, notFound) {
extendObservable(this, {
routes: [],
currentPath: window.location.pathname,
notFound: null,
current: computed(() => this.computeCurrent()),
@benjick
benjick / persist.js
Created Jun 15, 2017
mobx-state-tree persist PoC
View persist.js
/* globals localStorage */
import { onSnapshot, applySnapshot } from 'mobx-state-tree';
import Storage from './storage';
export const persist = (name, store, options, schema = {}) => {
let hydrated = false;
let storage = options.storage;
if (typeof localStorage !== 'undefined' && localStorage === storage) {
View reactToFirebase.jsx
<input
type="file" onChange={(e) => {
const file = e.target.files[0];
const metadata = {
contentType: 'image/jpeg',
};
const imageRef = storageRef.child(`images/${file.name}`);
const uploadTask = imageRef.put(file, metadata);