Skip to content

Instantly share code, notes, and snippets.

@J-L
J-L / gist:bea5b454fd0a8e2eb2381d1540520aca
Last active June 29, 2018 22:42
Python SigV4 Auth for AWS- Simple
# Key derivation functions. See:
# http://docs.aws.amazon.com/general/latest/gr/signature-v4-examples.html#signature-v4-examples-python
def sign(key, msg):
return hmac.new(key, msg.encode('utf-8'), hashlib.sha256).digest()
def getSignatureKey(key, dateStamp, regionName, serviceName):
kDate = sign(('AWS4' + key).encode('utf-8'), dateStamp)
kRegion = sign(kDate, regionName)
kService = sign(kRegion, serviceName)
@J-L
J-L / luhnAlgorithm.swift
Last active January 31, 2017 16:46
Swift Implementation of Luhn Algorithm
//: Playground - noun: a place where people can play
/*
From wikipedia:
From the rightmost digit, which is the check digit, moving left, double the value of every second digit; if the product of this doubling operation is greater than 9 (e.g., 8 × 2 = 16), then sum the digits of the products (e.g., 16: 1 + 6 = 7, 18: 1 + 8 = 9).
Take the sum of all the digits.
If the total modulo 10 is equal to 0 (if the total ends in zero) then the number is valid according to the Luhn formula; else it is not valid.
*/
import UIKit