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 get_unique(m:list): | |
c = {} | |
for i in m: | |
if c.get(i) is not None: | |
c.pop(i) | |
c[i] = i | |
return next(iter(c.values())) | |
assert get_unique([6,1,3,3,3,6,6]) == 1 | |
assert get_unique([13,19,13,13]) == 19 |
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
// A function that takes 2 arguments: an array and a value to search in the array | |
function binarySearch(arr, target) { | |
// make a copy of the array and sort it so that we can perform binary search | |
const sortedArray = [...arr]; | |
sortedArray.sort(); | |
let mid; | |
let start = 0; | |
let end = arr.length - 1; |
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
// A function that returns true if a number is prime | |
function isPrime(num) { | |
let numIsPrime = true; | |
if (num === 1) { | |
return false; | |
} | |
for (let i = 2; i < num; i++) { | |
if (num % i === 0) { | |
numIsPrime = false; | |
console.log(i); |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title>Star Wars</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css" | |
crossorigin="anonymous"> |
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 binascii | |
import socket | |
import struct | |
# Create a TCP/IP socket | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
server_address = ('localhost', 10000) | |
sock.connect(server_address) | |
values = (1, b'ab', 2.7) |
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 binascii | |
import socket | |
import struct | |
# Create a TCP/IP socket | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
server_address = ('localhost', 10000) | |
sock.bind(server_address) | |
sock.listen(1) |
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 socket | |
import struct | |
import sys | |
multicast_group = '224.10.10.10' | |
server_address = ('', 10000) | |
# Create the socket | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
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 socket | |
import struct | |
message = b'very important data' | |
multicast_group = ('224.10.10.10', 10000) | |
# Create the datagram socket | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
# Set a timeout so the socket does not block |
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 socket | |
import os | |
# Create a TCP/IP socket | |
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
server_address = './socket_file' | |
# Make sure file doesn't exist already | |
try: |
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 socket | |
import sys | |
# Create a TCP/IP socket | |
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
# Connect the socket to the port where the server is listening | |
server_address = './socket_file' | |
print('connecting to {}'.format(server_address)) |
NewerOlder