Skip to content

Instantly share code, notes, and snippets.

View mrl22's full-sized avatar
πŸ’­
Always coding

Richard Leishman mrl22

πŸ’­
Always coding
View GitHub Profile
@mrl22
mrl22 / pagination.php
Last active June 30, 2017 07:49
Pagination that can be used on any website in bootstrap format
/**
* @param int $total Total number of records
* @param int $per_page How many records to display per page
* @param int $current_page Current page number
* @param string $link sprintf formatted string for page links $1 = page number
* @return string in html ul-li format
*/
function pagination($total, $per_page, $current_page, $link)
{
$boundry = 3; // How many pages to show around the current page
@mrl22
mrl22 / letmc_properties.php
Created May 26, 2017 09:03
Get LetMC Properties
$clientid = '{0000-0000-0000-0000}';
function letmc_call($action, $xml) {
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
@mrl22
mrl22 / curl2json.php
Last active June 26, 2017 10:21
Cached cURL Request
function curl2json($url, $header_opts=array(), $cache_life=300) {
$cache_file = md5($url.json_encode($header_opts)).'.txt';
if (!file_exists($cache_file) || (time() - filemtime($cache_file)) >= $cache_life) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_FOLLOWLOCATION => FALSE,
CURLOPT_RETURNTRANSFER => 1,
@mrl22
mrl22 / msh
Last active July 8, 2017 22:14
Run command on multiple servers, written for Proxmox but will work on others
#!/bin/bash
if [[ -z "$@" ]] ; then
echo "You must enter a command. Example: msh \"cat /etc/fstab\""
exit 1;
fi
for ip_addr in $(cat /etc/hosts | grep 10.0.100 | cut -f 1 -d " "); do
ssh ${ip_addr} $@ | while read line; do echo "[$ip_addr] $line"; done
echo ""
@mrl22
mrl22 / bbcode.php
Created August 5, 2017 14:10
Interesting snippet of code that could come in useful at some point.
<?php
//This function let convert BBcode to HTML
function bbcode_to_html($text)
{
$text = nl2br(htmlentities($text, ENT_QUOTES, 'UTF-8'));
$in = array(
'#\[b\](.*)\[/b\]#Usi',
'#\[i\](.*)\[/i\]#Usi',
'#\[u\](.*)\[/u\]#Usi',
'#\[s\](.*)\[/s\]#Usi',
@mrl22
mrl22 / zamzar_convert.php
Last active August 24, 2017 10:40
Zamzar file convert and download. Example is XLS to CSV
$apiKey = ''; // Zamzar API
$url = ''; // Source URL to excel file
$tmp_file = sys_get_temp_dir() . '/zamzar_' . time().'.csv'; // Where we are saving the converted file on the server
// Start a conversion job
$job = zamzar_job_create($url, 'xls', 'csv');
if (count($job['errors'])) die('There was an issue creating the job at zamzar.');
@mrl22
mrl22 / ftp-mirror.sh
Last active November 20, 2017 11:24
Download entire website from FTP
USER=""
PASS=""
HOST=""
wget -m -nH ftp://$USER:$PASS@$HOST/public_html/ -P public_html --cut-dirs=1
@mrl22
mrl22 / functions.php
Created September 12, 2017 13:38
Add Featherlight JS to WordPress posts the_content
// Featherlight - Add Featherlight JS to WordPress posts the_content
add_filter('the_content', 'my_addfeatherlightrel');
function my_addfeatherlightrel($content) {
global $post;
$pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
$replacement = '<a$1href=$2$3.$4$5 data-featherlight="$3.$4" title="'.$post->post_title.'"$6>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
@mrl22
mrl22 / extract.sh
Created September 20, 2017 17:59
Extract .asar file
for file in `asar l app.asar`; do file=`echo $file|cut -c 2-`; echo "$file"; asar ef app.asar "$file"; mkdir -p `dirname $file`; mv `basename $file` `dirname $file`; done;
@mrl22
mrl22 / .htaccess
Created September 29, 2017 10:32
HTTPS and WWW redirect
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=301,L,NE]