This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def binary_search(arr, x): | |
low = 0 | |
high = len(arr) - 1 | |
mid = 0 | |
while low <= high: | |
mid = (high + low) // 2 | |
# Check if x is present at mid | |
if arr[mid] < x: | |
low = mid + 1 | |
# If x is greater, ignore left half |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cd ~/certs/ | |
# cloud_user@ip-10-0-1-101:~/certs$ ls | |
# ca-cert ca-key | |
# Generate a client certificate. Choose a password for the client keystore when prompted. | |
keytool -keystore client.keystore.jks -alias kafkauser -validity 365 -genkey -keyalg RSA -dname "CN=kafkauser, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown" | |
# Sign the key, then import the certificate authority and signed key into the keystore. When asked for the password to the ca-key, enter the password AllTheKeys: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## ACL Authorization | |
# Create a test topic. | |
kafka-topics --bootstrap-server zoo1:9092 --create --topic acl-test --partitions 1 --replication-factor 1 | |
# On all three brokers, enable ACL authorization in server.properties. | |
sudo vi /etc/kafka/server.properties | |
# Add the following lines. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Create Some Test Data | |
# To begin, create a test topic with some data that you can read at the end for testing. | |
kafka-topics --bootstrap-server localhost:9092 --create --topic tls-test --partitions 1 --replication-factor 1 | |
# Produce some data to the tls-test topic. | |
kafka-console-producer --broker-list localhost:9092 --topic tls-test | |
## Generate Certificate Files |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Basics | |
# Create the topic using the kafka-topics command | |
kafka-topics --create --bootstrap-server localhost:9092 --replication-factor 3 --partitions 6 --topic inventory_purchases | |
# list all topics that we have in Kafka (so we can observe the internal topics) | |
kafka-topics --list --zookeeper localhost:2181 | |
# Start a command line producer | |
kafka-console-producer --broker-list localhost:9092 --topic inventory_purchases |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ListNode(object): | |
def __init__(self, x): | |
self.val = x | |
self.next = None | |
class Solution(object): | |
def addTwoNumbers(self, l1, l2): | |
temp = [] | |
carry = 0 | |
while(not l1.val is None or not l2.val is None): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node(object): | |
def __init__(self, value): | |
self.value = value | |
self.left = None | |
self.right = None | |
class BinaryTree(object): | |
def __init__(self, root): | |
self.root = Node(root) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import libraries | |
import torch | |
import numpy as np | |
################################# | |
## Load and Visualize the Data ## | |
################################# | |
from torchvision import datasets | |
import torchvision.transforms as transforms | |
from torch.utils.data.sampler import SubsetRandomSampler |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import numpy as np | |
from PIL import Image | |
import torch.optim as optim | |
import matplotlib.pyplot as plt | |
from torchvision import transforms, models | |
############### | |
## Functions ## | |
############### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################### | |
## Test for CUDA ## | |
################### | |
import torch | |
import numpy as np | |
# check if CUDA is available | |
train_on_gpu = torch.cuda.is_available() | |
if not train_on_gpu: |
NewerOlder