Skip to content

Instantly share code, notes, and snippets.

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
# 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:
## 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.
## 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
@kafagy
kafagy / kafka.sh
Last active January 3, 2020 20:41
## 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
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):
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)
# 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
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 ##
###############
@kafagy
kafagy / CNN.py
Last active December 18, 2018 20:31
###################
## 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: