Skip to content

Instantly share code, notes, and snippets.

🙃
Focusing

Vaibhav Vishal vaibhavhrt

🙃
Focusing
Block or report user

Report or block vaibhavhrt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@vaibhavhrt
vaibhavhrt / dict-of-lists-to-json.py
Last active Aug 17, 2018
[Python] Get json string from a python dict containing one or more list of strings into json, all list must be of same size
View dict-of-lists-to-json.py
""" 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 = []
@vaibhavhrt
vaibhavhrt / .gitignore
Created Jun 9, 2018
Various .gitignore
View .gitignore
# Common gitignore #
# Will keep updating it
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
@vaibhavhrt
vaibhavhrt / most-frequent-word.js
Created Apr 21, 2018
Challenge: analyze a most frequent word program
View most-frequent-word.js
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
@vaibhavhrt
vaibhavhrt / select-one-row-from-mySql-db.php
Last active Apr 27, 2018
php function to query and get one row from a mysql database
View select-one-row-from-mySql-db.php
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());
}
View random-token.php.php
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
@vaibhavhrt
vaibhavhrt / get-html-from-any-webpage.php
Last active Apr 14, 2018
code to get text, href, etc data from any webpage using simple_html_dom in php
View get-html-from-any-webpage.php
<?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:
You can’t perform that action at this time.