Skip to content

Instantly share code, notes, and snippets.

View imvaskii's full-sized avatar
🎯
Focusing

Bhaskar imvaskii

🎯
Focusing
View GitHub Profile
@imvaskii
imvaskii / SimpleAuthServer.py
Created October 31, 2017 12:19 — forked from fxsjy/SimpleAuthServer.py
SimpleAuthServer: A SimpleHTTPServer with authentication
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
import sys
import base64
key = ""
class AuthHandler(SimpleHTTPRequestHandler):
''' Main class to present webpages and authentication. '''
def do_HEAD(self):
@imvaskii
imvaskii / fileupload.py
Last active October 7, 2019 07:26
Python script to upload file using curl
def upload_file(self, file_path, upload_url):
"""
Upload file using curl
based on https://github.com/Lispython/pycurl/blob/master/examples/file_upload.py
:param file_path:
:param upload_url:
:return: abs file url path of uploaded file.
"""
if file_path is None or not os.path.exists(file_path):
print("File '{}' cant be uploaded".format(file_path))
@imvaskii
imvaskii / gist:18472b788ac32c4b16524cf2c25a5d87
Created October 6, 2017 04:07 — forked from stuart11n/gist:9628955
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@imvaskii
imvaskii / limit-cront.php
Created July 19, 2017 01:02
Limitize WordPress default scheduled events.
<?php
add_filter( 'schedule_event', 'limit_cron_events' );
if ( ! funciton_exists( 'limit_cron_events' ) ) {
/**
* Limitize WordPress default scheduled tasks
* https://codex.wordpress.org/Plugin_API/Filter_Reference/schedule_event
*
* @param object $event event being scheduled
* @return void
@imvaskii
imvaskii / maybe_include_author_posts.php
Created July 5, 2017 05:18
WordPress search functionality to include authors' posts in search result if the search keyword matches authors' name.
<?php
if ( ! function_exists( 'cre_custom_search_query' ) ) {
/**
* Creates custom search query
* @param WP_Query object
* @return posts object
*/
add_action( 'pre_get_posts', 'cre_custom_search_query', 100 );
function cre_custom_search_query( $query ) {
@imvaskii
imvaskii / pre-commit.sh
Created July 3, 2017 01:47
Pre commit hook for git, for testing phpcs via composer
#!/bin/bash
#
# To enable this hook, rename this file to "pre-commit" and move it to .git/hooks/ in your project dir.
# For windows user, if you are using Git for windows (https://git-scm.com/download/win) then use following shebang
# #!C:/Program\ Files/Git/usr/bin/sh.exe
# For windows I prefer you use cygwin so that it supports bash script interpretation
# For windows if you are using https://git-scm.com/download/win then by default it uses cygwin.
# This script assumes the working directory already does have composer dependencies installed.
# @dependency: composer, phpcs, wpcs
@imvaskii
imvaskii / php_codesniffer_wp.sh
Created June 29, 2017 01:26
Runs php code sniffer via bash script
#!/bin/bash
set -e
set -u
set -o pipefail
# installs composer if required
function maybe_install_composer() {
# If composer exists then return
@imvaskii
imvaskii / array_unique_by_key.php
Last active June 21, 2017 05:05
Returns unique multidimensional array
<?php
if ( ! function_exists( 'twr_array_unique_by_key' ) ) {
/**
* Return unique multidimensional array filtered by given key.
*
* @param $array should be multidimensional array
* @param string $key
* @return array
*/
function twr_array_unique_by_key( $array, $key ) {
@imvaskii
imvaskii / post_duplicator.php
Created May 25, 2017 01:18
Post duplicator component
<?php
/**
* Post duplicator component.
*
* @author Bhaskar K C
* @since 24/05/2017
*/
class Component_post_duplicator extends Component {
/**
@imvaskii
imvaskii / get_singe_line.php
Created May 16, 2017 07:01
WordPress: Functions to fetch one liner content from post_content
<?php
if ( ! function_exists( 'twr_get_progressive_line') ) {
/**
* Returns proper line string from given $string content by progressively matching each line of the given html blob
* @param string $content
* @param integer $nth_line nth line to scan of given string
* @param integer $scanned_chars characters scanned
* @return mixed|null|string
*/