Skip to content

Instantly share code, notes, and snippets.

@adnan360
adnan360 / python-invert.sh
Created January 6, 2019 09:29
Toggles a python script running (terminates if already running, runs otherwise)
#!/bin/bash
# This bash script (1) runs a python script if not already running
# or (2) kills the script if already running. Easily put, it inverts
# the running state of the script. Great for toggling GUI scripts.
# Run chmod +x python-invert.sh and then run this with the python
# script path as parameter: ./python-invert.sh path/to/script.py
script_name=${1}
@adnan360
adnan360 / handle-server.sh
Last active January 2, 2019 10:48
Start or stop Apache server + Mysql server on different distros and setups
#!/bin/bash
# Arch Linux and Debian has different names for Apache service.
# Some people may like Mysql over Mariadb, which has different service
# names.
# This script detects which service is available and starts or stops it.
# So it basically lets you start or stop the server in one command.
# This is great for maintaining one piece of code that can be used on
# different distros.
# To use it, place the code below on your ~/.bashrc or if you have it,
@adnan360
adnan360 / sass-tabbed-generate.sh
Last active November 30, 2018 05:22
For generating tabbed Sass output
#!/bin/bash
sassc -t expanded style.scss > style.css
sed -i -e 's/ / /g' style.css
# Save as .sh file on the same directory as the css. e.g. generate.sh
# chmod +x generate.sh
# ./generate.sh
# This method requires no tools, no hacks, no code edits etc. Easy and simple!
@adnan360
adnan360 / yaost-primary-category.php
Last active November 7, 2018 05:27
Get Yoast SEO primary category
<?php
/**
* Gets Yoast SEO primary category.
*
* @param int $post_id ID of the product to get category of.
* @return string
*/
public function get_primary_cat( $post_id ) {
$cat_name = '';
if ( class_exists( 'WPSEO_Primary_Term' ) ) {
@adnan360
adnan360 / lampp-on-debian.md
Last active February 23, 2024 04:30
How to Install LAMPP Stack on Debian/Ubuntu [Experimental]

How to Install LAMPP Stack on Debian/Ubuntu [Experimental]

Ubuntu is based on Debian so it should apply to Ubuntu as well. I have tested this on latest Debian Testing (on SparkyLinux). I usually use WordPress and CakePHP on my localhost so I included instructions at the end to make them work perfectly.

Warning: This config is not designed with security in mind, only for convenience of desktop users. If you are setting up for server, please refer to proper manuals.

Note: This config is experimental. There might be better way to do some aspects. But it does work for my specific needs so I made it available. Please use carefully.

Step 1: Install stuff

@adnan360
adnan360 / power.sh
Created August 8, 2018 11:43
Simple script to create a selection menu for shutdown, reboot etc. based on rofi in dmenu mode
#!/bin/bash
# Simple script to handle a DIY shutdown menu. When run you should see a bunch of options (shutdown, reboot etc.)
#
# Requirements:
# - rofi
# - systemd, but you can replace the commands for OpenRC or anything else
#
# Instructions:
# - Save this file as power.sh or anything
@adnan360
adnan360 / README.md
Last active January 24, 2025 05:49
Automatically adds the first 6 fastest VPNGate vpn connections to Network Manager

VPNGate Auto Setup Script for OpenVPN on Linux

VPNGate is a an excellent VPN for beginners. But one of the problems is that older ovpn connections stop connecting after a few days. I can easily add them manually, but downloading the ovpn files and adding them every week is a mess! This script easily adds up to date 6 connections from VPNGate records.

Requirements

  • Only supports Linux
  • Requires network-manager-openvpn & network-manager-openvpn-gnome to be installed
  • Python 2 or 3

Instructions

require_once( dirname( MPLUS_CE ) . '/vendor/PHPWord/Template.php' );
class Mplus_PHPWord_Template extends PHPWord_Template
{
private $page_xml;
public function __construct( $strFilename ){
parent::__construct( $strFilename );
$this->page_xml = file_get_contents(dirname( MPLUS_CE ) . '/assets/page.txt');
}
for ( $i = 0; $i < $no_of_pages; $i++) {
// Adds a page to put the data in.
$document->add_page();
// Goes through each label (for each item).
for ( $j = 0; $j < $labels_per_page; $j++ ) {
/*
* Some variables to be used later.
* The values will be put later.
*/
$index2 = $j + 1;
$labels_per_page = 14;
$no_of_pages = ceil( count( $expiring_members ) / $labels_per_page );
$index = 0;
$template_file = dirname( MPLUS_CE ) . '/assets/template.docx';
$upload_dir = wp_get_upload_dir();
$save_path = $upload_dir[ 'basedir' ] . '/expiring_memberships.docx';
$save_url = $upload_dir[ 'baseurl' ] . '/expiring_memberships.docx';
$document = new Mplus_PHPWord_Template( $template_file );
$countries = WC()->countries->get_countries();