Skip to content

Instantly share code, notes, and snippets.

🌱
🅱enjick

Max Malm benjick

🌱
🅱enjick
Block or report user

Report or block benjick

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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);
View slack.js
import fetch from 'node-fetch';
const channel = 'C03T4C7MS';
const channelInfoUrl = `https://slack.com/api/channels.info?token=${token}&channel=${channel}`;
const userListUrl = `https://slack.com/api/users.list?token=${token}`;
async function fetchUsers() {
try {
let usersInChannel = await fetch(channelInfoUrl).then(res => res.json());
usersInChannel = usersInChannel.channel.members;
View js.js
User.defineStatic('validate', async function validateUser(email, password) {
const user = await User.getAll(email, { index: 'email' }).run();
if (user.length !== 1) {
throw new Error('No user found');
}
if (!compare(password, user[0].password)) {
throw new Error('Wrong password');
}
return true;
});
View express.js
app.post('/upload', multipartMiddleware, (req, res) => { // multipartMiddleware is for multipart forms
console.log(req.body);
res.json({
foo: 'bar',
});
});
View Main.elm
import Html exposing (li, text, ul)
import Html.Attributes exposing (class, href)
{-| This snippet uses the <ul> and <li> tags to create an unorderd
list of French grocery items. Notice that all occurrences of 'ul'
and 'li' are followed by two lists. The first list is for any HTML
attributes, and the second list is all the HTML nodes inside the
tag.
You can’t perform that action at this time.