Skip to content

Instantly share code, notes, and snippets.

View cmandesign's full-sized avatar

Soroosh Khodami cmandesign

View GitHub Profile
@cmandesign
cmandesign / split & grep file in file.md
Last active January 15, 2020 09:04
Find common records between two large files with grep

Here is the command to search records in the first file inside of the second file :

grep -f firstFile.csv SecondFile.csv > FoundRecords.csv

But if there are more thant 100k records on each file, you must split them into 100K line to prevent the command get killed or become not responding. Here is the command to split the file :

@cmandesign
cmandesign / flask_basic_logger_config.py
Created November 11, 2019 19:39
Flask Basic Logger Config
import os
from logging.config import dictConfig
# Import Log Base Path From Config File
# The output should be something like this
# log_base_path = "/var/log/"
log_base_path = your_config.LOG_BASE_PATH
logging_dict = {
@cmandesign
cmandesign / flask_log_request_response.py
Last active November 11, 2019 19:41
Flask Log Request/Responses
@app.after_request
def after_request(response):
""" Logging all of the requests in JSON Per Line Format. """
inbound_request_logger = logging.getLogger('inbound_requests')
inbound_requests_logger.info({
"datetime": datetime.datetime.now().isoformat(),
"client_ip": request.remote_addr,
"method": request.method,
"request_url": request.path,

How to Add Rich Snippet to Wordpress Themes Manually Using Yoast + WP-PostRatings

In this piece we will learn how we can easily add rich snippets to our Wordpress theme manually without headache or using complex plugins.

Requirements

  • You should be familiar with Wordpress & Yoast SEO
  • A little knowledge of PHP to understand and make few edits in my codes based on your requirement
  • Patience to read this article carefully, you should know that I am lazy as you are and I don't want to be talkative! I'm just writing the important things to make sure you know what we are doing here.

Story

<?php
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'img_post' );
// img_post is name of my thumbnail size ( I've added my own in functions.php )
$focuskw = get_post_meta(get_the_ID(), ‘_yoast_wpseo_focuskw’, true);
// It's focus keyword that you enter in Yoast Metabox in post edit page, it's really important
$primary_cat = get_post_meta(get_the_ID(), ‘_yoast_wpseo_primary_category’, true);
// Primary Category is important, for permalink format and meta keywords
if($primary_cat == NULL && $primary_cat == ''){
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Article",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://google.com/article"
},
"headline": "Post Headline",
"alternativeHeadline": "Meta Description or any other format you want to add",
<?php get_header(); ?>
<div id="content" class="narrowcolumn">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<!-- START OF LOOP -->
<div class="post">
<h2 id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>