Skip to content

Instantly share code, notes, and snippets.

View MEGApixel23's full-sized avatar
🌴

Igor Omelchenko MEGApixel23

🌴
View GitHub Profile
const upload (url) => {
const parts = url.split('?');
const extractedFilename = parts[parts.length - 2];
const filename = extractedFilename ? `${i}_${extractedFilename}` : `${i}.pdf`;
const key = `document-groups-documents/${docFolder}/${filename}`;
const response = await axios({
url,
method: 'get',
responseType: 'stream',
});
@MEGApixel23
MEGApixel23 / S3-Static-Sites.md
Created January 2, 2020 14:31 — forked from bradwestfall/S3-Static-Sites.md
Use S3 and CloudFront to host Static Single Page Apps (SPAs) with HTTPs and www-redirects. Also covers deployments.

S3 Static Sites

What this will cover

  • Host a static website at S3
  • Redirect www.website.com to website.com
  • Website can be an SPA (requiring all requests to return index.html)
  • Free AWS SSL certs
  • Deployment with CDN invalidation

Resources

@MEGApixel23
MEGApixel23 / dynamodb_replicate_table.py
Created December 16, 2019 10:40 — forked from Dineshkarthik/dynamodb_replicate_table.py
Copy dynamoDB table to another region using python, boto3. This script creates an exact replica of the table with same key schema and attribute definitions.
# Copyright (C) 2018 Dineshkarthik Raveendran
from __future__ import print_function # Python 2/3 compatibility
import boto3
import argparse
def replicate(table_name, existing_region, new_region, new_table_name):
"""
Replicate table in new region.
@MEGApixel23
MEGApixel23 / stream-file-upload-s3-nodejs.js
Created January 8, 2019 08:26 — forked from schempy/stream-file-upload-s3-nodejs.js
Streaming File Uploads To Amazon S3 With Node.js
var http = require('http');
var router = require('routes')();
var Busboy = require('busboy');
var AWS = require('aws-sdk');
var inspect = require('util').inspect;
var port = 5000;
// Define s3-upload-stream with S3 credentials.
var s3Stream = require('s3-upload-stream')(new AWS.S3({
accessKeyId: '',
@MEGApixel23
MEGApixel23 / render.js
Last active November 28, 2018 09:37
The real example which was used in AWS Lambda backend. The use case was PFD generation from HTML template. In order to use something light and fast Mustache library was picked. Handlebars doc says that it is largely compatible with Mustache templates. So the same should work with Handlebars, though JS part needs to be changed a bit.
const mustache = require('mustache');
/**
* @param html
* @param data has the following structure:
* {
* pages: [
* {
* packages: {
* dspName: String,
@MEGApixel23
MEGApixel23 / import_sql_to_docker_mysql.sh
Created June 14, 2017 07:34
cli tool for importing sql file to MySQL database inside docker container
#!/usr/bin/env bash
read -p "Container name: " container_name
read -p "username: " username
read -p "password: " password
read -p "database: " database
read -p ".sql path: " sql_file
script=exec docker exec -i $container_name mysql -u$username -p$password $database < $sql_file
@MEGApixel23
MEGApixel23 / PageNumbersForPDF.js
Created May 23, 2017 13:23
Getting number of pages in PDF file from remote source. PDFJS is used http://mozilla.github.io/pdf.js/getting_started/#download
const fileLink = 'https://link-to-remote-file.pdf';
PDFJS.workerSrc = '/path/to/pdf.worker.js';
PDFJS.getDocument(fileLink)
.then(function (doc) {
// A lots of valuable information in `doc` variable
return doc.pdfInfo.numPages;
});
@MEGApixel23
MEGApixel23 / .travis.yml
Created May 12, 2017 15:56
Travis config for testing on several versions of Laravel (or any other composer package if needed)
language: php
php:
- 5.6
- 7.0
- 7.1
cache:
directories:
- $HOME/.composer
@MEGApixel23
MEGApixel23 / Partial_mock_laravel_example.php
Last active May 7, 2017 15:50
Example of a partial class mock (only needed method will be mocked, others stays unchanged).
<?php
$mock = Mockery::mock(ClassYouWantToMock::class)->makePartial();
$mock->shouldReceive('methodNameToMock')->andReturn($returnVariable);
$this->app->instance(ClassYouWantToMock::class, $mock);
@MEGApixel23
MEGApixel23 / package.json
Created April 10, 2017 15:52
PHPStorm debug for NPM packages
{
"name": "SomeName",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"local:onboard": "node $NODE_DEBUG_OPTION /usr/bin/lambda-local -f index -e _onboard_event.json -t 300",
"local:refresh": "node $NODE_DEBUG_OPTION /usr/bin/lambda-local -f index -e _refresh_event.json -t 300"
},
"license": "ISC",