This file contains 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
""" Get json string from a python dict containing lists of same size, see example at bottom of code """ | |
import pyperclip | |
def dict_to_json(lists, cont=False, start_from=0): | |
""" convert a list of strings to json """ | |
if cont: | |
json = '' | |
else: | |
json = '{\n' | |
keys = [] |
This file contains 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
function getTokens(rawString) { | |
// NB: `.filter(Boolean)` removes any falsy items from an array | |
return rawString.toLowerCase().split(/[ ,!.";:-]+/).filter(Boolean).sort(); | |
//split() splits the paragraph into words using regular expression | |
} | |
function mostFrequentWord(text) { | |
var words = getTokens(text); //use getTokens to get an array of words from the paragraoh text | |
var wordFrequencies = {}; //defing an object to save frequency of every word | |
for (var i = 0; i <= words.length; i++) { //loop to iterate through the array of words |
This file contains 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
define('DB_SERVER', 'localhost'); | |
define('DB_USERNAME', 'username'); | |
define('DB_PASSWORD', 'password'); | |
define('DB_NAME', 'database_name'); | |
$con = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME); | |
// Check connection | |
if($con === false){ | |
die("ERROR: Could not connect. " . mysqli_connect_error()); | |
} |
This file contains 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
function crypto_rand_secure($min, $max) { | |
$range = $max - $min; | |
if ($range < 0) return $min; // not so random... | |
$log = log($range, 2); | |
$bytes = (int) ($log / 8) + 1; // length in bytes | |
$bits = (int) $log + 1; // length in bits | |
$filter = (int) (1 << $bits) - 1; // set all lower bits to 1 | |
do { | |
$rnd = hexdec(bin2hex(openssl_random_pseudo_bytes($bytes))); | |
$rnd = $rnd & $filter; // discard irrelevant bits |
This file contains 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
<?php | |
$pageURL = "http://www.google.com"; //replace with the url of page you wanna access | |
require("simple_html_dom.php"); //download simple_html_dom parser from here: "http://simplehtmldom.sourceforge.net/" and put it in the same location as this .php file | |
$html = file_get_html($pageURL); | |
foreach($html->find('a[class=xyz]') as $element){ //replace a[class=xyz] with the elemets you want to get, read here for more info: http://simplehtmldom.sourceforge.net/manual.htm | |
echo $element->href . '<br>'; //display the href just for testing purposes | |
} //$element is an object with all the attributes of all matching elements according to your selector, do whatever you want with it. | |
// if getting this error: Warning: file_get_contents(): stream does not support seeking in simple_html_dom.php on line 76, | |
//On line 76 of simple_html_dom.php: |