Skip to content

Instantly share code, notes, and snippets.

Sock Merchant

  • When you need to count number of pairs in a given list, you can use a map (e.g. HashMap<Integer, Integer>) to put the unique items then increment the counter when the same item appears again. Use modulo after incrementing the count to determine if count is a pair (e.g. n % 2 == 0 then it is a pair). (the ‘Unique Tracker Technique’)

Counting Valleys

  • When you need to count something that requires a certain condition involving equilibrium (or a valley) then use an index. In this example, a valley usually will have an exit point of ‘up’ which will hit the index. With that condition, you can count the number of valleys based on that. (the ‘Breaking Condition’ technique)

Repeated String

  • Rather than scanning every character in a big string, you can divide the small string first then multiply the output to how many instances it should have appeared in the big string. (the ‘Divide and Conquer’ technique)
@abantej
abantej / singapore-family-tour-june-2018.md
Last active May 29, 2018 03:07
Singapore Family Tour June 2018

Singapore Family Tour June 2018

June 13, 2018 - Wednesday

  • 9PM - Departing MNL
  • 1AM - Arriving SG

June 14, 2018

June 15, 2018

What is DNS?

  • DNS is used to convert human-friendly domain names (abantej.github.io) into an internet protocol (185.199.108.153) address
  • IP addresses are used by computers to identify each other on the network. IP addresses commonly come in 2 different forms, IPv4 and IPv6

IPv4

  • 32 bit field with over 4 billion different addresses (4,294,967,296)

IPv6

  • 128 bit field with 340 undecillion addresses (340,282,366,920,938,463,463,374,607,431,768,211,456)

AWS Lambda

  • a compute service where you can upload your code and create a Lambda function
  • it take cares of provisioning and managing the servers that you use to run your code
  • you don't have to worry about your operating systems, patching, scaling, etc.

AWS Lambda Usage

  1. as an even-drivent compute service where AWS Lambda runs your code in response to events. these events could be changes to data in an Amazon S3 bucket or an Amazon DynamoDB table.
  2. as a compute service to run your code in response to HTTP requests using Amazon API Gateway or API calls made using AWS SDKs

Currently available Lambda triggers

Elastic Compute Cloud (EC2)

  • a web service that provide the resizable compute capacity in the cloud.
  • reduces the time required to obtain and boot new server instances to minutes, allowing you to scale capacity, both up and down, as your computing requirements change
  • allows you to pay only for capacity that you actually use
  • it provides developers the tools to build failure resilient applications and isolate themselves from common failure scenarios

EC2 Options

  • On Demand
  • allow you to pay a fixed rate by the hour with no commitment

Tree

  • a datastructure composed of nodes
  • each tree has a root node
  • the root node has zero or more child nodes
  • each child node has zero or more child nodes, and so on.
  • a tree cannot contain cycles
  • the nodes may or may not be in a particular order
  • the nodes can have any datatype as values
  • the nodes may or may not have links back to their parent nodes

EC2 - Elastic Cloud Compute (Virtual Machines aka Compute Instances)

IAM - Identity and Access Management used for creating and managing users and groups.

S3 - Simple Storage Service. Object-based storage. Universal namespace.

NAS - Network Attached Storage.

ARN - Amazon Resource Name.

@abantej
abantej / people.json
Created April 23, 2018 12:58
Example json format
{
"people": [
{
"name":"Brad",
"age":35
},
{
"name":"John",
"age":40
},
<!DOCTYPE html>
<html>
<head>
<title>Json</title>
</head>
<body>
<ul id="people"></ul>
<script>
/*
var person = {

Is Unique

Implement an algorithm to determine if a string has all unique characters.

boolean isUniqueChars(String str) {
    if (str.length() > 128) return false;
    boolean[] char_set = new boolean[128];
    for (int i = 0; i < str.length(); i++) {
 int val = str.charAt(i);