Skip to content

Instantly share code, notes, and snippets.

View imvaskii's full-sized avatar
🎯
Focusing

Bhaskar imvaskii

🎯
Focusing
View GitHub Profile
@imvaskii
imvaskii / wpdb-get-max-id.php
Created June 25, 2018 05:37
An example of simple wpdb query script.
<?php
/**
* Returns max ID of the source wp_posts table.
*
* @return int
*/
public function get_source_max_article_id() {
$in_source_post_statuses = [ 'publish', 'draft', 'pending', 'private', 'trash', 'inherit' ];
$post_status_placeholders = implode( ', ', array_fill( 0, count( $in_source_post_statuses ), '%s' ) );
@imvaskii
imvaskii / sqlwithcase.sql
Created June 18, 2018 05:29
SQL with case
select u.user_login as login, u.user_email as email, u.display_name as fullname, c.meta_value as capability, (CASE WHEN (l.meta_value='1') THEN 'Yes' ELSE 'No' END ) as is_restricted from wp_users as u
INNER JOIN wp_usermeta as c ON c.user_id = u.ID
INNER JOIN wp_usermeta as l ON l.user_id = u.ID
WHERE c.meta_key = 'wp_capabilities' AND l.meta_key='is_login_restricted';
@imvaskii
imvaskii / noip-dyndns-update.py
Last active December 30, 2024 12:09
A python (python3) script to update no-ip (https://www.noip.com) dynamic dns ip.
#!/usr/bin/env python
import requests, socket
username = ""
password = ""
hostname = "" # your domain name hosted in no-ip.com
# Gets the current public IP of the host machine.
myip = requests.get('http://api.ipify.org').text
@imvaskii
imvaskii / tmux.cheat
Created May 15, 2018 13:03 — forked from afair/tmux.cheat
Tmux Quick Reference & Cheat sheet - 2 column format for less scrolling!
========================================== ==========================================
TMUX COMMAND WINDOW (TAB)
========================================== ==========================================
List tmux ls List ^b w
New -s <session> Create ^b c
Attach att -t <session> Rename ^b , <name>
Rename rename-session -t <old> <new> Last ^b l (lower-L)
Kill kill-session -t <session> Close ^b &

Problem

In Arch Linux mkinitcpio -p linux

shows

Possibly missing firmware for module: aic94xx
 Possibly missing firmware for module: wd719x
@imvaskii
imvaskii / convert_post_label_to_article.php
Last active March 21, 2018 09:38
Rename posts label to "Articles"
<?php
// Alters post type labels.
add_action( 'registered_post_type', 'change_post_type_labels', 10, 2 );
// Posts menu label change to articles.
add_action( 'admin_menu', 'rename_post_menu_item_label' );
/**
* Replace Posts label to Articles in post edit admin page
@imvaskii
imvaskii / docker-rm.sh
Created December 21, 2017 00:38
Remove docker containers and images
#!/bin/bash
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)
@imvaskii
imvaskii / maybe_convert_arraykeys_lcfirst.php
Last active November 23, 2017 06:01
Converts first char of array keys to lowercase
<?php
/**
* Converts first char of array keys to lowercase
*
* @param $multd_array
*
* @return array
*/
function maybe_convert_arraykeys_lcfirst( $multd_array ) {
$result = [];
@imvaskii
imvaskii / safeurl_base64_decode.php
Created November 22, 2017 00:11
Decode a string with URL-safe Base64.
<?php
/**
* Decode a string with URL-safe Base64.
*
* @param string $input A Base64 encoded string
*
* @return string A decoded string
*/
public static function urlsafeB64Decode( $input ) {
$remainder = strlen( $input ) % 4;
@imvaskii
imvaskii / diskusage.sh
Created November 17, 2017 10:06
Disk usage on specific path/location -linux/unix
#!/bin/sh
# Default path is root (/)
path="/"
# if string is not null
if [ -n "$1" ]; then
path="$1"
fi