Skip to content

Instantly share code, notes, and snippets.

View shahzaibkhan's full-sized avatar

Shahzaib Khan shahzaibkhan

View GitHub Profile
# import the module you’ll use to simulate the computer’s choices:
import random
# take the user input
user_action = input("Enter a choice (rock, paper, scissors): ")
# Define the possible choices and let the computer choose one of them randomly
possible_actions = ["rock", "paper", "scissors"]
computer_action = random.choice(possible_actions)
# import the module you’ll use to simulate the computer’s choices:
import random
while True:
# take the user input
user_action = input("Enter a choice (rock, paper, scissors): ")
# Define the possible choices and let the computer choose one of them randomly
possible_actions = ["rock", "paper", "scissors"]
@shahzaibkhan
shahzaibkhan / functions.php
Last active July 4, 2022 17:16
set_post_views
<?php
// add this code within the function file
function set_post_views($postID) {
$count_key = ‘post_views_count’;
$count = get_post_meta($postID, $count_key, true);
if($count==”){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, ‘0’);
@shahzaibkhan
shahzaibkhan / function.php
Created July 4, 2022 17:17
track_post_views
<?php
function track_post_views ($post_id) {
if ( !is_single() ) return;
if ( empty ( $post_id) ) {
global $post;
$post_id = $post->ID;
}
set_post_views($post_id);
}
<?php
function get_post_views($postID){
$count_key = ‘post_views_count’;
$count = get_post_meta($postID, $count_key, true);
if($count==”){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, ‘0’);
return "0 View";
}
@shahzaibkhan
shahzaibkhan / curl.php
Created July 5, 2022 07:18
get_remote_data
<?php
function get_remote_data($url, $post_paramtrs = false) {
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
if ($post_paramtrs) {
curl_setopt($c, CURLOPT_POST, TRUE);
curl_setopt($c, CURLOPT_POSTFIELDS, "var1=bla&" . $post_paramtrs);
} curl_setopt($c, CURLOPT_SSL_VERIFYHOST, false);
<?php
function callAPI($method, $url, $data){
$curl = curl_init();
switch ($method){
case "POST":
curl_setopt($curl, CURLOPT_POST, 1);
if ($data)
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;
from spellchecker import SpellChecker
spell = SpellChecker()
word = input("Enter your Word : ")
if word in spell:
print("Correct Spelling")
else:
print("Incorrect Spelling")
@shahzaibkhan
shahzaibkhan / functions.php
Created July 13, 2022 09:48
numeric_posts_nav
function numeric_posts_nav() {
if( is_singular() )
return;
global $wp_query;
/** Stop execution if there's only 1 page */
if( $wp_query->max_num_pages <= 1 )
return;
@shahzaibkhan
shahzaibkhan / style.css
Created July 13, 2022 09:48
Styling for Numeric Pagination
.navigation li a,
.navigation li a:hover,
.navigation li.active a,
.navigation li.disabled {
color: #fff;
text-decoration:none;
}
.navigation li {
display: inline;