Compare commits
7 Commits
Author | SHA1 | Date |
---|---|---|
EmaMaker | 4e7bdd9625 | |
EmaMaker | 900e7cda49 | |
EmaMaker | 0d5c6e9416 | |
EmaMaker | 3f8c4921a0 | |
EmaMaker | 114a17b276 | |
EmaMaker | b115c0dfd5 | |
EmaMaker | a8323fde5b |
|
@ -1,4 +1,2 @@
|
|||
Code Samples
|
||||
|
||||
Code in this branch are useful in every language and can be easily translated in other languages.
|
||||
Just read the concept, not the code
|
||||
Every language-specific code is in the language branch.
|
||||
For algorithms that can be used in every language, look in the generic branch
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
'''
|
||||
PYTHON CODE BRUTEFORCES WORDS FROM GIVEN CHAR LIST.
|
||||
ENDLESS WORD LIST CAN BE GENERATED, UNTIL PROGRAM STOPPED
|
||||
EVERY 100 WORDS GENERATED THEY ARE SAVED ON FILE
|
||||
'''
|
||||
|
||||
|
||||
lPossibleChars = ("a", "b", "c", "d", "e", "f")
|
||||
sWord = ""
|
||||
sFileName = "words.txt"
|
||||
lGenWords = []
|
||||
dWordsForSave = 100
|
||||
|
||||
def bruteforce(index):
|
||||
global sWord, lPossibleChars
|
||||
|
||||
#generates only if the index to change is less than currrent word length
|
||||
if index < len(sWord):
|
||||
for i in range(len(lPossibleChars)):
|
||||
|
||||
#makes the word a list
|
||||
lWord = list(sWord)
|
||||
#changes the index
|
||||
lWord[index] = lPossibleChars[i]
|
||||
#makes the list back a word
|
||||
sWord = ''.join(lWord)
|
||||
|
||||
print(sWord)
|
||||
#adds to the list
|
||||
lGenWords.append(sWord)
|
||||
|
||||
#goes on for the next index
|
||||
bruteforce(index + 1)
|
||||
|
||||
|
||||
while True:
|
||||
#saves word on file (append mode) and cleares the list
|
||||
if len(lGenWords) >= dWordsForSave:
|
||||
f = open(sFileName, "a")
|
||||
|
||||
for s in lGenWords:
|
||||
f.write(s + "\n")
|
||||
|
||||
lGenWords[:] = []
|
||||
f.close()
|
||||
|
||||
#starts bruteforcing the word and adds a new character when ended
|
||||
if len(sWord) > 0:
|
||||
bruteforce(0)
|
||||
sWord += lPossibleChars[0]
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
|
||||
/*
|
||||
* SHOWING IMAGE GIVEN FROM URL *
|
||||
*/
|
||||
|
||||
$url = 'http://www.google.com/doodle4google/images/d4g_logo_global.jpg';
|
||||
$allow = ['gif', 'jpg', 'png']; // allowed extensions
|
||||
$img = file_get_contents($url);
|
||||
$url_info = pathinfo($url);
|
||||
|
||||
// if allowed extension
|
||||
if(in_array($url_info['extension'], $allow)) {
|
||||
// Format the image SRC: data:{mime};base64,{img_data_base64};
|
||||
$src = 'data:image/'. $url_info['extension'] .';base64,'. base64_encode($img);
|
||||
|
||||
// add the base64 image into a <img> to display it
|
||||
$re = '<img src="'. $src .'" alt="'. $url_info['basename'] .'" />';
|
||||
}
|
||||
else $re = 'Invalid extension: '. $url_info['extension'];
|
||||
|
||||
echo $re; // output $re data
|
||||
|
||||
?>
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
//ESCAPE CHARACTERS IN PHP-HTML
|
||||
|
||||
$word = "ciao";
|
||||
echo "<pre>\n" . $word . "</pre>";
|
||||
echo "<pre>\n\tciao2</pre>";
|
||||
|
||||
|
||||
?>
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* RANDOM WEB PAGE GENERATOR, WITH RANDOM TEXT AND SINGLE IMAGE
|
||||
*/
|
||||
|
||||
//first of all makes all the things for the image and sames it into $re
|
||||
$url = 'http://www.google.com/doodle4google/images/d4g_logo_global.jpg';
|
||||
$allow = ['gif', 'jpg', 'png']; // allowed extensions
|
||||
$img = file_get_contents($url);
|
||||
$url_info = pathinfo($url);
|
||||
|
||||
// if allowed extension
|
||||
if (in_array($url_info['extension'], $allow)) {
|
||||
// Format the image SRC: data:{mime};base64,{img_data_base64};
|
||||
$src = 'data:image/' . $url_info['extension'] . ';base64,' . base64_encode($img);
|
||||
|
||||
// add the base64 image into a <img> to display it
|
||||
$re = '<img src="' . $src . '" alt="' . $url_info['basename'] . '"style="width:406px;height:109px;" />';
|
||||
} else $re = 'Invalid extension: ' . $url_info['extension'];
|
||||
|
||||
$chars = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM<>,;.:-_ÒÀÙÈ+Ç°§É*òàùè+{}#[]@1234567890'ì?^\|!£$%&/()=?^\"";
|
||||
|
||||
for ($i = 0; $i < random_int(40, 50); $i++) {
|
||||
$word = "";
|
||||
for ($j = 0; $j < random_int(1,4); $j++) {
|
||||
|
||||
$word .= substr($chars, random_int(0,strlen($chars) / 2), random_int(strlen($chars) / 2, strlen($chars)));
|
||||
}
|
||||
echo "<pre>\n" . $word . "</pre>";
|
||||
|
||||
if (random_int(0, 10) <= 1) {
|
||||
echo "<pre>\n" . $re . "</pre>";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
|
||||
/*
|
||||
* THIS CODE SLOWS DOWN THE BROWSER, CALCULATING THE MD5 HASH OF THE
|
||||
* MILLISECONDS OF THE THE CURRENT SECONDS AND PRINTING THEM IN VARIABLE-LENGTH LINES
|
||||
* ONYL TESTED ON LOCAL MACHINE: I DON'T WHAT HAPPENS IF EXECUTED FROM A REMOTE HOST
|
||||
*/
|
||||
|
||||
header('Content-type: text/plain');
|
||||
|
||||
|
||||
for ($i = 0; $i < 20; $i++) {
|
||||
|
||||
for ($j = 0; j < random_int(10, 15); $j++) {
|
||||
$rand = substr(md5(microtime()), 0, random_int(25, 50));
|
||||
print $rand . " ";
|
||||
}
|
||||
|
||||
|
||||
print "\n";
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue