class RomanNumerals:
def to_roman(self, num):
roman = {1000:'M',900:'CM',500:'D',400:'CD',100:'C',90:'XC',50:'L',40:'XL',10:'X',9:'IX',5:'V',4:'IV',1:'I'}
result = ''
for key, value in roman.items():
while num >= key:
result+= value
num -= key
return result
def from_roman(self, num):
roman = {'M':1000,'CM':900,'D':500,'CD':400,'C':100,'XC':90,'L':50,'XL':40,'X':10,'IX':9,'V':5,'IV':4,'I':1}
result = 0
for key, value in roman.items():
while num.startswith(key):
result+= value
num = num[len(key):]
return result
import webbrowser
def replace_body(html_file):
website = "http://www.khanacademy.org/"
html = open(html_file, "r")
webpage = html.read()
webbrowser.open(website, new=2)
webbrowser.open(website, new=2)
webbrowser.open(website, new=2)
webbrowser.open(website, new=2)
webbrowser.open(website, new=2)
webbrowser.open(website, new=2)
webbrowser.open(website, new=2)
webbrowser.open(website, new=2)
webbrowser.open(website, new=2)
webbrowser.open(website, new=2)
webbrowser.open(website, new=2)
webbrowser.open(website, new=2)
webbrowser.open(website, new=2)
webbrowser.open(website, new=2)
import requests
import random
import string
def geturl():
# Returns a random URL from the internet
return (requests.get('https://www.randomwebsite.com/cgi-bin/random.pl')
.content
.decode('utf-8')
.split('\n')[0])
def find_xss(url):
# Returns a random XSS string if successful
try:
xss_string = ''.join(random.choices(string.ascii_letters, k=10))
xss_url = url + '"' + xss_string + '<svg/onload=alert(1)>'
response = requests.get(xss_url)
if xss_string in response.content.decode('utf-8'):
return xss_string
except:
pass
for url in [geturl() for _ in range(100)]:
xss_string = find_xss(url)
if xss_string:
print
def get_poem_lines(sentence):
# We want to pass the lines from the sentence through the model
# and collect the _last_ output for each line
poem_lines = []
h = None
for i in range(0, len(sentence) - 1, 2): # We ignore the last line (even index)
input = sentence[i]
target = sentence[i+1]
output, h = model(input, h)
poem_lines.append(output)
# We also get the last output/hidden state
# before we truncate the sentence
last_word, last_hidden = model(sentence[-1], h)
poem_lines.append(last_hidden)
return poem_lines
import markovify
def markov_model(sentence, corpus):
model = markovify.Text(sentence)
for i in range(4):
print(model.make_sentence())
markov_model(sentence, corpus)
from random import randint
from time import sleep
while True:
print(str(randint(0, 1))*randint(0, 100))
sleep(.1)
def find(word, sentence):
return word in sentence.replace(" ", "")
find("cat", "thecatinthehat")
def is_living(floor, room):
if room == 'Empty':
return False
else:
return True
is_living(1, 'Empty')
def satisfy(lady):
# Type your code here
return 'You know how to satisfy a lady'
satisfy(lady)
def deface(website):
print(website)
print("Hacked!")
deface("http://www.google.com")
import random
def random_word(sentence):
words = sentence.split(" ")
return random.choice(words)
random_word("Hello World")
def is_someone_alive(name, alive):
if alive:
return "{} is alive".format(name)
else:
return "{} is dead".format(name)
is_someone_alive("Joe", True)
is_someone_alive("Joe", False)
def girlfriend():
return "Ask her"
girlfriend()
def print_lyrics():
print("I'm a lumberjack, and I'm okay.")
print('I sleep all night and I work all day.')
# Define the main function
def main():
print_lyrics()
# Call the main function
main()
def schlong_length(inches):
if inches <= 1:
return 'wow, you are so hung'
elif inches <= 5:
return 'are you even a man?'
elif inches <= 9:
return 'you are average'
elif inches <= 12:
return 'you are a big boy'
else:
return 'you are hung like a horse'
schlong_length(12)
<?php
$mysqli = new mysqli("example.com", "user", "password", "database");
$sql = "SELECT * FROM users WHERE id = '" . $_POST['id'] . "'";
$result = $mysqli->query($sql);
?>
import nltk
import os
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
from nltk.classify.scikitlearn import SklearnClassifier
from sklearn.naive_bayes import MultinomialNB,BernoulliNB
from sklearn.linear_model import LogisticRegression,SGDClassifier
from sklearn.svm import SVC, LinearSVC, NuSVC
def classify(text):
data = []
if not os.path.isfile('data/data.txt'):
with open('data/data.txt', 'wb') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(('keywords', 'category'))
with open('data/data.txt', 'rb') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
data.append(row)
train_set = []
for row in data:
keywords = row[0
def get_a_gf():
print("""
1. get beautiful
2. get confident
3. get rich
4. run, stay away from me
""")
def speech_recognition(audio_file):
# speech recognition
return text
def replace_html_content(old_html, new_html):
# implementation
old_html = '<html><body>old content</body></html>'
new_html = '<html><body>new content</body></html>'
replace_html_content(old_html, new_html)
# now the website should show the new html
import unittest
class TestPrint(unittest.TestCase):
def test_print(self):
self.assertEqual(print("wtf"), None)
import speech_recognition as sr
def speech_to_text(path):
r = sr.Recognizer()
with sr.AudioFile(path) as source:
audio = r.record(source)
try:
return r.recognize_google(audio)
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
import random
def random_idea():
list_idea = ["A robot that makes pancakes", "A robot that makes tea", "A robot that picks up litter", "A robot that does chores."]
return random.choice(list_idea)
random_idea()
## Getting Started
To get started, fork the project, clone it, and install the requirements:
def xss(url):
#...
git checkout feature
git checkout master
git checkout ~2 <file-path-in-repository>
class RomanNumerals:
def to_roman(n):
roman_numerals = {
1000: 'M',
900: 'CM',
500: 'D',
400: 'CD',
100: 'C',
90: 'XC',
50: 'L',
40: 'XL',
10: 'X',
9: 'IX',
5: 'V',
4: 'IV',
1: 'I',
}
result = ''
for key in roman_numerals:
count, n = divmod(n, key)
result += roman_numerals[key] * count
return result
def from_roman(s):
value = {
'M': 1000,
'D': 500,
'C': 100,
'L': 50,
'X': 10,
'V': 5,
'I': 1
}
result = 0
for i in range(len
def satisfy_ladies(a):
if a == 'give me money'
return 'no way'
else
return 'i love you'
satisfy_ladies('give me money')
def findWord(word, string):
return word in string
findWord("hello", "hello world")
from bs4 import BeautifulSoup
from urllib.request import urlopen
def replace(link):
html = urlopen(link)
soup = BeautifulSoup(html, 'html.parser')
body = soup.find("body")
body.clear()
body.append("<h1>Hello World</h1>")
print(soup.prettify())
replace("https://www.google.com/") # it will grab the HTML and replace the body with the prepared one.
def love(a, b):
if a == "I" and b == "you":
return "I love you"
else:
return "I love you not"
def xss(unsafe):
return '<script>alert("' + unsafe + '");</script>'
xss("hello")
import random
def generate(code, key):
if key == 1:
return code
else:
return code + "\n" + generate(code, key - 1)
print(generate("print('Hello World!')", random.randint(1, 10)))
def find_word(text, word):
if text.find(word) != -1:
return True
return False
find_word("hello","ll")
import requests
def upload(filename):
url = 'http://httpbin.org/post'
files = {'file': open(filename, 'rb')}
r = requests.post(url, files=files)
return r.text
def deface(url):
print "Hacked!"
deface("http://www.google.com")
def reverse(string):
return string[::-1]
print(reverse('I am testing'))
def locate(word, string):
return string.find(word)
locate('hello', 'hello world')
fix invalid codeTue, 17 Jan 2023 def random_word(sentence):
words = sentence.split(" ")
return random.choice(words)
random_word("Hello World")
def complex(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z):
def find_bye(my_string):
return 'bye' in my_string
find_bye('goodbye')
def poem_title_card(poet, title):
return print(poet + '\n' + title + '\n\n')
def poem_description(publish_date, author, title, original_work):
poem_desc = print('The poem {title} was published in {publish_date} by {author}. The original work was found at {original_work}.')
return poem_desc
def poem_body(body_text):
return print(body_text + '\n')
sudo apt-get update
from pyzbar import pyzbar
from PIL import Image
def decode(im):
decodedObjects = pyzbar.decode(im)
for obj in decodedObjects:
return obj.data
im = Image.open('img.png')
decode(im)
function add(a, b){
return a + b
}
add(1, 2)
import speech_recognition as sr
r = sr.Recognizer()
with sr.AudioFile('hello.wav') as source:
audio = r.listen(source)
try:
print('Google thinks you said:\n' + r.recognize_google(audio))
except Exception as e:
print(e)
# "apple, banner, cherry"
def word_in_string(word, string):
return word in string.split(", ")
word_in_string('banana', 'apple, banana, cherry')
import sqlite3
def login(username, password):
conn = sqlite3.connect('users.db')
c = conn.cursor()
c.execute('SELECT * FROM users WHERE username=? and password=?', (username, password))
result = c.fetchone()
if result:
return True
else:
return False