Skip to content

Instantly share code, notes, and snippets.

@khaledsaikat
khaledsaikat / gcd_lcm_list.py
Last active July 13, 2018 21:54
GCD and LCM in python for list
#!/usr/bin/env python3
from math import gcd
from functools import reduce
def lcm(a, b):
"""lowest common multiple of a and b"""
return int(a * b / gcd(a, b))
def gcd_from_list(arr):
"""Calculate greatest common divisor from list"""
@khaledsaikat
khaledsaikat / nginx_location.txt
Last active April 7, 2017 19:31
Some nginx config inside server block: Using subdirectory, Server from another directory, Autoindex file listing, Using basic auth
##
# Some nginx config inside server block
#
# Examples of:
# * Using subdirectory
# * Server from another directory
# * Autoindex file listing
# * Using basic auth
#
# Install and using of htpasswd tools:
@khaledsaikat
khaledsaikat / user_meta_field_display
Created July 29, 2016 09:50
Replace label and input order
add_filter('user_meta_field_display', function ($html) {
// Get label html
preg_match("/<label.*>.*<\/label>/", $html, $matches);
$label = $matches[0];
// Get input html
preg_match("/<input.*\/>/", $html, $matches);
$input = $matches[0];
// Create new html
@khaledsaikat
khaledsaikat / wp_Error_example.php
Created November 23, 2015 23:28
Example of WP_Error class
<?php
/**
* Creating instance of error class
*/
$error = new WP_Error( 'not_found', 'Page Not Found', 'Page Data' );
/**
* Add new error to object
*/
@khaledsaikat
khaledsaikat / sub_category_dropdown.php
Last active January 30, 2018 05:12
Frontend AJAX Sub-Category Dropdown (Load sub-category dropdown based on parent category by ajax call)
<?php
/*
Plugin Name: Frontend AJAX Sub-Category Dropdown
Plugin URI: http://khaledsaikat.com
Description: Load sub-category dropdown based on parent category by ajax call
Version: 0.1
Author: Khaled Hossain
Author URI: http://khaledsaikat.com
*/
@khaledsaikat
khaledsaikat / Meta value as options
Last active August 29, 2015 14:06
Use custom field values as options in a dropdown or checkbox
add_filter( 'user_meta_field_config', 'user_meta_field_config_populate_options', 10, 4 );
function user_meta_field_config_populate_options( $field, $fieldID, $formName, $userID ){
if( $fieldID != 'Your_Field_ID' ) // Put your desired field id here
return $field;
$metaKeys = array( 'key1', 'key2', 'key3' );
$output = null;
foreach( $metaKeys as $key ):
@khaledsaikat
khaledsaikat / fetch_concurrently.go
Last active August 29, 2015 14:04
An example of concurrency in Go programming
package main
import (
"fmt"
"time"
"net/http"
)
var urls = []string{
"http://google.com",
@khaledsaikat
khaledsaikat / opencvVideoWrite.cpp
Last active December 29, 2015 15:39
OpenCV video write to disk. (VideoCapture.read() method is not somehow working so using CvCapture)
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main(int argc, char* argv[])
{
CvCapture *camCapture;