Skip to content

Instantly share code, notes, and snippets.

View ivanji's full-sized avatar
🎯
Focusing

Ivan J ivanji

🎯
Focusing
View GitHub Profile
@ivanji
ivanji / AWS Instance Bootstrap
Last active August 4, 2016 05:08 — forked from mikepfeiffer/gist:4d9386afdcceaf29493a
EC2 UserData script to install CodeDeploy agent
#!/bin/bash
yum update -y
yum install -y httpd24 php56
cd /home/ec2-user/
aws s3 cp 's3://aws-codedeploy-us-west-2/latest/codedeploy-agent.noarch.rpm' . --region us-west-2
yum -y install codedeploy-agent.noarch.rpm
chown -R root:www /var/www
chmod 2775 /var/www
@ivanji
ivanji / cloudformation-dynamoDB.yml
Created January 4, 2019 04:44 — forked from DavidWells/cloudformation-dynamoDB.yml
Example of dynamo cloudformation with GSI and LSI
---
AWSTemplateFormatVersion: '2010-09-09'
Resources:
myDynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: Album
AttributeType: S
- AttributeName: Artist
function humanReadable(seconds) {
var readable = ["00", "00", "00"];
// TODO
if (seconds > 359999 || seconds < 0) {
console.log("exiting...")
return;
}
var min = 60; //* 60 = 1 hour
var hour = 3600; //* 24 = 1 day
var day = 86400; //
function order(words){
/**
* Your task is to sort a given string.
* Each word in the string will contain a single number.
* This number is the position the word should have in the result.
* Note: Numbers can be from 1 to 9. So 1 will be the first word (not 0).
* If the input string is empty, return an empty string. The words in the input String will only contain valid consecutive numbers.
*
@ivanji
ivanji / permutations.js
Created February 12, 2019 21:45
Create String Permutations
// create all permutations of an input string and remove duplicates, if present
function permutations(string) {
var nums = Array.from(string);
var permutations = [];
function swap(a, b) {
var tmp = nums[a];
nums[a] = nums[b];
@ivanji
ivanji / onlyDuplicates.js
Created February 12, 2019 21:49
Provide only duplicates within text
/**
Given a string, remove any characters that are unique from the string.
Example:
input: "abccdefee"
output: "cceee"
*/
@ivanji
ivanji / countingDuplicates.js
Created February 12, 2019 21:53
Create a function that will return the count of distinct case-insensitive alphabetic characters and numeric digits that occur more than once in the input string. The input string can be assumed to contain only alphabets (both uppercase and lowercase) and numeric digits.
/**
abcde" -> 0 # no characters repeats more than once
"aabbcde" -> 2 # 'a' and 'b'
"aabBcde" -> 2 # 'a' occurs twice and 'b' twice (`b` and `B`)
"indivisibility" -> 1 # 'i' occurs six times
"Indivisibilities" -> 2 # 'i' occurs seven times and 's' occurs twice
"aA11" -> 2 # 'a' and '1'
"ABBA" -> 2 # 'A' and 'B' each occur twice
*/
@ivanji
ivanji / getCognitoUserAttributes.md
Created February 21, 2019 08:14
Getting Cognito users attributes from Lambda

/**

  • Get cognito user attributes in Lambda
  • Need to grant permission to Lambda through an IAM role:

*/

serverless.yml:

 iamRoleStatements:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">