Skip to content

Instantly share code, notes, and snippets.

View lmammino's full-sized avatar
🦁
Roar!

Luciano Mammino lmammino

🦁
Roar!
View GitHub Profile
@lmammino
lmammino / app-bundle.js
Created April 12, 2018 18:16
A sample webpacked bundle from http://poo.loige.co
This file has been truncated, but you can view the full file.
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
@lmammino
lmammino / gen_dkim.py
Created March 3, 2018 17:52
Generate dkim keys and a TXT record file for AWS Route 53
#!/usr/bin/env python
# Usage
# ./gen_dkim.py mail.yourdomain.tld
import sys
from subprocess import call
from os import devnull
if len(sys.argv) < 2:
@lmammino
lmammino / example.json
Created November 6, 2017 16:00
A sample message coming from SQS with a payload coming from SNS
{
"Messages": [
{
"Body": "{\n \"Type\" : \"Notification\",\n \"MessageId\" : \"abcdef01-2345-6789-0abc-defg123456783\",\n \"TopicArn\" : \"arn:aws:sns:eu-west-1:123456789012:ticketless-ticketPurchased\",\n \"Message\" : \"{\\\"ticket\\\":{\\\"id\\\":\\\"abcdef01-2345-6789-0abc-defg123456784\\\",\\\"createdAt\\\":1509980177897,\\\"name\\\":\\\"Alex Smith\\\",\\\"email\\\":\\\"email@example.com\\\",\\\"gig\\\":\\\"nirvana-cork-1991\\\"},\\\"gig\\\":{\\\"capacity\\\":2300,\\\"collectionPoint\\\":\\\"29 South Main Street, Centre, Cork City, Co. Cork, Ireland\\\",\\\"collectionTime\\\":\\\"13:00\\\",\\\"slug\\\":\\\"nirvana-cork-1991\\\",\\\"originalDate\\\":\\\"1991-08-20\\\",\\\"venue\\\":\\\"Cavern Club\\\",\\\"bandName\\\":\\\"Nirvana\\\",\\\"city\\\":\\\"Cork\\\",\\\"date\\\":\\\"2019-06-21\\\",\\\"image\\\":\\\"nirvana.jpg\\\",\\\"year\\\":\\\"1991\\\",\\\"collectionPointMap\\\":\\\"map-nirvana-cork-1991.png\\\",\\\"description\\\":\\\"Lorem Ipsum\\\",\\\"price\\\":\\\"1666.60\\\"}}\",\n \"
@lmammino
lmammino / README.md
Created October 10, 2017 21:19
Automated SMS notifications with AWS Lambda and Twilio APIs — Commented code

This is the code used the article Automated SMS notifications with AWS Lambda and Twilio APIs published on Twilio's blog

Here follows a detailed description of every part of the code:

  1. The first thing we do is to import the request-promise-native library.
  2. Then we declare our handler function by respecting the expected signature with event, context and callback as described previously.
  3. Inside the handler, we define some constants that we will use as configuration in the rest of the code. Be sure to fill in all the values that are specific to your account.
  4. At this point we are ready to perform the first API request to get the exchange rate from Fixer.io.
  5. Since request-promise-native returns a promise, we have to write a then and a catch method to handle the asynchronous control flow. Inside the then we have get the response data from the API call and we can use it to extract the current exchange rate. We also log the result, which is a go
@lmammino
lmammino / index.js
Last active July 19, 2017 20:02
Javascript getters/setters quick demo - expanded from Node.js Design Patterns (Second Edition) - https://www.nodejsdesignpatterns.com/
const person = {
name: 'George',
surname: 'Boole',
get fullname () {
console.log('** getting fullname')
return this.name + ' ' + this.surname
},
set fullname (fullname) {
console.log('** setting fullname to', fullname)
let parts = fullname.split(' ')
@lmammino
lmammino / .npmrc-switch
Last active December 17, 2019 17:08
Simple bash script to switch from an NPM user login (profile) to another by using symlinks
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
profile=$1
[ -z "$profile" ] && printf "\nERROR: missing profile name.\n\nUsage:\n\n '$0 <profileName>'\n" && exit 1
[ ! -f "$DIR/.npmrc-profiles/$profile" ] && printf "\nERROR: profile '$profile' not found\n" && exit 1
cd $DIR && ln -sf .npmrc-profiles/$profile .npmrc
/**
* Copyright (C) 2014 PONTON GmbH
*/
package org.efetnet.uti;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.regex.Pattern;
@lmammino
lmammino / RandomWebToken.java
Last active June 26, 2026 13:16
A sample Java class that generates a URL safe random token
import java.security.SecureRandom;
import java.util.Base64;
import java.util.Base64.Encoder;
public class RandomWebToken
{
public static void main(String[] args)
{
SecureRandom random = new SecureRandom();
byte bytes[] = new byte[128];
@lmammino
lmammino / example.js
Created February 6, 2016 17:56
Read only event emitter in Node
"use strict";
const ticker = require('./ticker');
ticker.on('tick', (tickCount) => console.log(tickCount, 'TICK'));
// ticker.emit('something', {}); <-- This will fail