Skip to content

Instantly share code, notes, and snippets.

View PatrickJS's full-sized avatar

PatrickJS PatrickJS

View GitHub Profile
@alexcasalboni
alexcasalboni / aws-lambda-edge.md
Last active September 8, 2023 08:44
Serve dynamically generated, minimized and compressed HTML pages with AWS Lambda@Edge.

AWS Lambda@Edge Experiment

Requirements

  • AWS Lambda@Edge (enabled Preview)
  • One Amazon CloudFront Distribution (origin doesn't matter)
  • IAM role (basic execution is enough)
  • npm to install Node.js dependencies
@PatrickJS
PatrickJS / 00.script-async-attr-support-plugin.js
Last active August 25, 2018 19:21 — forked from mzgoddard/00.script-async-attr-support-plugin.js
Plugin brainstorm to support async attribute use on script tags with webpack.
function ScriptAsyncAttrSupportPlugin() {}
module.exports = ScriptAsyncAttrSupportPlugin;
ScriptAsyncAttrSupportPlugin.prototype.apply = function(compiler) {
compiler.plugin('this-compilation', function(compilation) {
compilation.mainTemplate.plugin('bootstrap', function(source) {
return this.asString([
source,
'',
@mzgoddard
mzgoddard / 00.script-async-attr-support-plugin.js
Created November 16, 2016 19:34
Plugin brainstorm to support async attribute use on script tags with webpack.
function ScriptAsyncAttrSupportPlugin() {}
module.exports = ScriptAsyncAttrSupportPlugin;
ScriptAsyncAttrSupportPlugin.prototype.apply = function(compiler) {
compiler.plugin('this-compilation', function(compilation) {
compilation.mainTemplate.plugin('bootstrap', function(source) {
return this.asString([
source,
'',
@PatrickJS
PatrickJS / api.service.ts
Last active September 18, 2017 18:07
Universal Cache
// Something like this. I haven't tested this file
@Injectable()
export class ApiService {
constructor(public _http: Http, public _cache: Cache) {
}
// whatever domain/feature method name
getModel(url) {
// you want to return the cache if there is a response in it. This would cache the first response so if your API isn't idempotent you probably want to remove the item from the cache after you use it. LRU of 1
@toddmotto
toddmotto / *.js
Created September 19, 2016 19:41
Angular function arguments
(function(A,n,g,u,l,a,r){A.GoogleAnalyticsObject=r;A[l]=A[l]||function(){
(A[l].q=A[l].q||[]).push(arguments)},A[l].l=1*new Date();a=n.createElement(g),
r=n.getElementsByTagName(g)[0];a.async=1;a.src=u;r.parentNode.insertBefore(a,r)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-XX', 'auto');
ga('send', 'pageview');
@Hendrixer
Hendrixer / angular-2.sublime-syntax
Last active July 30, 2016 12:25
angular 2 syntax for sublime
%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: Angular 2
file_extensions:
- ts
scope: source.ts
contexts:
main:
- include: expression
@PatrickJS
PatrickJS / index.html
Last active May 5, 2017 15:24
How to build your own Angular Universal integrations for Angular 2
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>index as a string</title>
</head>
<body>
<app>
Loading...

How to setup AWS lambda function to talk to the internet and VPC

I'm going to walk you through the steps for setting up a AWS Lambda to talk to the internet and a VPC. Let's dive in.

So it might be really unintuitive at first but lambda functions have three states.

  1. No VPC, where it can talk openly to the web, but can't talk to any of your AWS services.
  2. VPC, the default setting where the lambda function can talk to your AWS services but can't talk to the web.
  3. VPC with NAT, The best of both worlds, AWS services and web.
@antonycourtney
antonycourtney / FunPix.hs
Created March 4, 2016 23:47
Layout thought of as an attribute grammar, encoded in Haskell
--
-- Some experiments with a Picture type based on an attribute-grammar
-- model of Layout
module FunPic where
import Haven
-- A type for representing the dimensions of a rectangle, as (width,height)
type Dimension = (Double,Double)
@robertknight
robertknight / Build.md
Last active July 8, 2022 01:32
Minimal Webpack DllPlugin example

Compile with:

webpack --config vendor.webpack.config.js
webpack --config app.webpack.config.js

Use with the following index.html