Skip to content

Instantly share code, notes, and snippets.

View maoosi's full-sized avatar

Sylvain maoosi

View GitHub Profile
@bponomarenko
bponomarenko / main.js
Last active April 7, 2023 13:47
Custom implementation of the missing onAbort hooks in vue-router
import Vue from 'vue';
import VueRouter from 'vue-router';
import applyOnRouterAbortShim from './on-router-abort-shim';
Vue.use(VueRouter);
const router = new VueRouter(...);
applyOnRouterAbortShim(router);
@dtelaroli
dtelaroli / lambda-get-identity-id.js
Created August 4, 2020 17:18
How to get identity id from cognito with jwt token
// npm install await-to-js
const { to } = require("await-to-js");
const { CognitoIdentity } = require("aws-sdk");
const identity = new CognitoIdentity();
const IDENTITY_POOL_ID = "<your identity pool id>";
exports.handler = async (event) => {
const { issuer } = event.identity;
@archisgore
archisgore / aws-cdk-s3-notification-from-existing-bucket.ts
Last active June 17, 2021 12:44
AWS CDK add notification from existing S3 bucket to SQS queue
import * as cr from '@aws-cdk/custom-resources';
import * as logs from '@aws-cdk/aws-logs';
import * as s3 from '@aws-cdk/aws-s3';
import * as sqs from '@aws-cdk/aws-sqs';
import * as iam from '@aws-cdk/aws-iam';
import {Construct} from '@aws-cdk/core';
// You can drop this construct anywhere, and in your stack, invoke it like this:
// const s3ToSQSNotification = new S3NotificationToSQSCustomResource(this, 's3ToSQSNotification', existingBucket, queue);
@DavidWells
DavidWells / conditional-resources.yml
Last active June 28, 2021 15:46
Using conditional "Fn::Equals" for cloudformation resources. From https://github.com/KlickMarketing/demo-site/blob/master/serverless.yml#L55 including no value
resources:
Description: Demo Site
Conditions:
isProd: {"Fn::Equals" : ["${self:custom.stageFlag}", "prod"]}
isRC: {"Fn::Equals" : ["${self:custom.stageFlag}", "rc"]}
isDev: {"Fn::Equals" : ["${self:custom.stageFlag}", "dev"]}
isProdOrRC: {"Fn::Or": [{"Condition": "isProd"}, {"Condition": "isRC" }]}
Resources:
ProxyEntry:
Type: 'Custom::MarketingStackProxyEntry'
@furkan3ayraktar
furkan3ayraktar / CloudFrontMetadataInject.js
Last active October 5, 2023 16:38
Complete Lambda@Edge function to inject metadata.
const path = require('path');
const https = require('https');
const zlib = require('zlib');
const downloadContent = (url, callback) => {
https.get(url, (res) => {
let response;
let body = '';
if (res.headers['content-encoding'] === 'gzip') {
@lizrice
lizrice / vpc-fargate.yaml
Created January 23, 2018 18:01
Cloudformation template for setting up VPC and subnets for Fargate
# Usage:
# aws cloudformation --region <region> create-stack --stack-name <stack name> --template-body file://vpc-fargate.yaml
# This template will:
# Create a VPC with:
# 2 Public Subnets
# 2 Private Subnets
# An Internet Gateway (with routes to it for Public Subnets)
# A NAT Gateway for outbound access (with routes from Private Subnets set to use it)
#
@NigelEarle
NigelEarle / Knex-Migrations-Seeding.md
Last active June 19, 2024 14:20
Migration and seeding instructions using Knex.js!

Migrations & Seeding

What are migrations??

Migrations are a way to make database changes or updates, like creating or dropping tables, as well as updating a table with new columns with constraints via generated scripts. We can build these scripts via the command line using knex command line tool.

To learn more about migrations, check out this article on the different types of database migrations!

Creating/Dropping Tables

@Gomah
Gomah / lambda-edge-prerender.js
Created July 25, 2017 23:46
Return pre-rendered html files for non-supported browsers
const whitelist = ['chrome', 'crios', 'firefox', 'fxios', 'googlebot'];
const isSupportedBrowser = uas => {
if (uas && Array.isArray(uas) && uas.length > 0) {
return uas.some(ua =>
whitelist.some(w => ua.value.toLowerCase().includes(w))
);
}
return false;
};
@0x263b
0x263b / colors.md
Last active July 13, 2024 19:15
Random color from string in javascript

Random color from string in javascript

Consider a list of strings you need to permanently assign a random color.

First you should turn the string into a hash.

var string = "string"
var hash = 0
@tscheepers
tscheepers / GeoSpatialThingController.php
Last active August 11, 2021 04:45
Geospatial sort by distance using Laravel and MySQL. I'm using a point column named geolocation in a table called things.
<?php
class GeoSpatialThingController extends \BaseController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()