Skip to content

Instantly share code, notes, and snippets.

@kilgarenone
kilgarenone / pushLocalToGithub.txt
Created September 5, 2018 09:50
push an existing local folder to a github repo
echo "# matisa-serverless" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/kilgarenone/matisa-serverless.git
git push -u origin master
@kilgarenone
kilgarenone / axiosServerless.js
Created September 5, 2018 12:29
axios serverless with third-party API
const axios = require("axios");
const mailChimp = {
preLaunchListId: "ff8c031f0e", // you can find yours in your mailchimp dashboard
apiUrl: "https://us2.api.mailchimp.com/3.0/" // this too
};
module.exports.addToBetaUserList = function(event, context, callback) {
const body = JSON.parse(event.body); // accessing the POST body payload. yours might have different structure and names
const auth = {
@kilgarenone
kilgarenone / webpackBabelServerless.js
Created September 13, 2018 07:41
webpack babel in serverless
const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');
module.exports = {
entry: slsw.lib.entries,
target: 'node',
// Generate sourcemaps for proper error messages
devtool: 'source-map',
// Since 'aws-sdk' is not compatible with webpack,
// we exclude all node dependencies
@kilgarenone
kilgarenone / babelrcServerless.js
Last active September 13, 2018 08:55
babelrc to enable es6/es7 webpack4 in serverless
{
"plugins": ["source-map-support"],
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "8.10"
}
}
@kilgarenone
kilgarenone / icons.js
Created October 23, 2018 08:09
Store SVG Icon's path data here
const ICONS = {
CLOSE:
"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z",
ARROW_RIGHT:
"m 13.706875,17.707 5,-5 c 0.391,-0.39 0.391,-1.024 0,-1.414 l -5,-4.9999998 c -0.391,-0.391 -1.024,-0.391 -1.414,0 -0.39,0.391 -0.391,1.024 0,1.414 L 15.585875,11 H 5.9998748 c -0.552,0 -1,0.448 -1,1 0,0.552 0.448,1 1,1 h 9.5860002 l -3.293,3.293 c -0.195,0.195 -0.293,0.451 -0.293,0.707 0,0.256 0.098,0.512 0.293,0.707 0.391,0.391 1.024,0.391 1.414,0 z"
};
export default ICONS;
import React from "react";
import { css, cx } from "react-emotion";
const defaultSvgCss = css`
position: relative;
display: inline-block;
vertical-align: middle;
`;
function Icon({ icon, color, size = 24, className }) {
@kilgarenone
kilgarenone / reactRenderProps.js
Last active November 25, 2018 04:17
react render props
// Function as children pattern
// Notice below that the body/children of <Hello /> is a anonymous function definition!
<Hello>
{ (foo) => (<World foo={foo} />) }
</Hello>
/*
And then we execute the function - this.props.children(),
while passing it the 'foo' data as an argument to the function above-
(foo) => (<World foo={foo} />), giving us whatever view is rendered inside the <World />!
@kilgarenone
kilgarenone / exporesAPI.js
Last active November 25, 2018 04:32
render props exposes API
class Hello extends React.Component {
state = { isSubmitting: false }
handleThisClick = () => {
/* do your thing here */
}
handleFormSubmit = async event => {
event.preventDefault();
@kilgarenone
kilgarenone / consumeRenderProps.js
Last active November 25, 2018 04:33
consume render props
// destructure the object given when called in the <Hello />,
// then pass those properties to our <CustomComponent /> to be consumed.
// The 'isSubmitting' value will be toggled and consumed accordingly too!
<Hello>
{({
handleThisClick,
handleFormSubmit,
isSubmitting
}) => (
<CustomComponent
@kilgarenone
kilgarenone / fontello.css
Last active December 9, 2018 06:20
fontello
@font-face {
font-family: "fontello";
src: url("./font/fontello.woff2") format("woff2"),
url("./font/fontello.woff") format("woff"),
url("./font/fontello.ttf") format("truetype"),
url("./font/fontello.svg") format("svg");
font-weight: normal;
font-style: normal;
}