Skip to content

Instantly share code, notes, and snippets.

View pavelvlasov's full-sized avatar

Pavel Vlasov pavelvlasov

View GitHub Profile
@pavelvlasov
pavelvlasov / functions.js
Last active January 7, 2018 23:17
Composition for serverless.js config
module.exports = {
hello: {
handler: 'index.hello',
events: [
{
http: {
path: 'hello',
method: 'get'
}
}
@pavelvlasov
pavelvlasov / serverless.js
Last active January 7, 2018 23:18
Use cli parameters in serverless.js config
'use strict';
const program = require('commander');
program
.option('--stage <n>', 'stage')
.option('--region <n>', 'region')
.option('--bucket <n>', 'bucket')
.parse(process.argv);
@pavelvlasov
pavelvlasov / base-serverless.js
Last active January 7, 2018 23:18
Serverless.js inheritance example
'use strict';
module.exports = {
provider: {
name: 'aws',
runtime: 'nodejs6.10',
stage: '${opt:stage, "dev"}',
region: '${opt:region, "us-east-1"}',
memorySize: 128,
timeout: 10,
@pavelvlasov
pavelvlasov / tsconfig.json
Last active January 20, 2018 00:42
Github stats bot, part I, tsconfig
{
"compilerOptions": {
"baseUrl": "./",
"rootDir": "./",
"paths": {
"@/*": ["./app/*"]
},
"module": "commonjs",
"target": "es5",
"lib": ["es6", "esnext.asynciterable"],
@pavelvlasov
pavelvlasov / gs-stats.ts
Created January 20, 2018 00:43
github stats api
import * as request from "request-promise-native";
const BASE_URL = "https://api.github.com";
export interface Person {
login: string;
id: number;
avatar_url: string;
gravatar_id: string;
url: string;
@pavelvlasov
pavelvlasov / bar.ts
Created January 20, 2018 02:11
simple nivo component
import { Bar as NBar } from "@nivo/bar";
import * as React from "react";
import { render } from "react-dom";
interface Item {
author: string;
added: number;
deleted: number;
changed: number;
}
@pavelvlasov
pavelvlasov / bar.story.ts
Created January 20, 2018 02:13
sample story
import { Bars } from "@/shared/api/chart/bar"
import { storiesOf } from "@storybook/react"
import * as React from "react"
import data from "./bars.data"
storiesOf("bars chart", module).add("default", () => {
return (
<Bars data={data} />
)
})
@pavelvlasov
pavelvlasov / bar.ts
Last active January 20, 2018 05:03
use js dom to render react components in node.js
import { createDomForChart } from "../utils";
export default (data: Data, options: Options = {}): string => {
const { target, dom } = createDomForChart();
render(<Bars data={data} options={options} />, target);
return dom.serialize();
};
@pavelvlasov
pavelvlasov / webpack.config.ts
Created January 21, 2018 03:34
html-to-png webpack config
import * as CopyWebpackPlugin from "copy-webpack-plugin";
import * as path from "path";
import * as PermissionsOutputPlugin from "webpack-permissions-plugin";
import getBaseConfig from "../../webpack.dev";
const baseConfig = getBaseConfig(__dirname);
module.exports = Object.assign(
{
plugins: [
@pavelvlasov
pavelvlasov / index.ts
Created January 21, 2018 03:43
html to png validate body
interface Body {
html: string;
width: number;
height: number;
name: string;
}
const validateBody = (body: any): Body => {
if (typeof body.html !== "string") {
throw new Error("Unsupported html type");