Skip to content

Instantly share code, notes, and snippets.

View lyquix-owner's full-sized avatar

Lyquix lyquix-owner

View GitHub Profile
@lyquix-owner
lyquix-owner / .htaccess
Created August 29, 2017 11:08
Prevent execution of scripts in directory
<FilesMatch "\.(php|php2|php3|php4|php5|pl|py|jsp|asp|phtm|phtml|shtml|sh|cgi)$">
deny from all
SetHandler none
</FilesMatch>
@lyquix-owner
lyquix-owner / lamp-ubuntu16.sh
Last active March 5, 2023 14:20
Bash script to setup LAMP server on Ubuntu 16.04
#!/bin/bash
# Check if script is being run by root
if [[ $EUID -ne 0 ]]; then
printf "This script must be run as root!\n"
exit 1
fi
DIVIDER="\n***************************************\n\n"
@lyquix-owner
lyquix-owner / ip-check-allowed.php
Last active March 11, 2023 07:17
PHP function to check if it matches allowed IP addresses and subnets
<?php
// IP to check
$ip_check = $_SERVER['REMOTE_ADDR'];
// Array of allowed IPs and subnets, both IPv4 and IPv6
$ips_allowed = array(
'192.30.252.0/22'
'2620:112:3000::/44'
'192.168.16.104'
);
@lyquix-owner
lyquix-owner / .htaccess
Created January 23, 2017 21:01
Password protect a directory. Create your .htpasswd file using http://www.htaccesstools.com/htpasswd-generator/
# Password Protect Directory #
AuthType Basic
AuthUserFile /srv/www/example.com/.htpasswd
AuthName "Enter username and password"
require valid-user
@lyquix-owner
lyquix-owner / .gitignore
Last active July 10, 2020 13:17
Sample .gitignore for Lyquix projects in WordPress and Joomla
# Operating system files
.DS_Store
Desktop.ini
Thumbs.db
# Common files and directories
/.htaccess
.npmignore
.project
.revision
@lyquix-owner
lyquix-owner / lamp-ubuntu14.sh
Last active April 25, 2017 14:29
Bash script to setup LAMP server on Ubuntu 14.04
#!/bin/bash
# Check if script is being run by root
if [[ $EUID -ne 0 ]]; then
printf "This script must be run as root!\n"
exit 1
fi
DIVIDER="\n***************************************\n\n"
@lyquix-owner
lyquix-owner / cleanhtml.php
Last active August 14, 2023 12:30
PHP script to automatically clean dirty HTML. Removes unnecessary attributes (e.g. style, id, dir), replaces deprecated tags with valid ones (e.g. <b> to <strong>), and strips undesirable tags (e.g <font>). We have used this script to safely clean hundreds of blog posts that were littered with inline styling.
<?php
// List of tags to be replaced and their replacement
$replace_tags = [
'i' => 'em',
'b' => 'strong'
];
// List of tags to be stripped. Text and children tags will be preserved.
$remove_tags = [
@lyquix-owner
lyquix-owner / drag-n-drop.html
Last active October 5, 2016 20:59
Pure Javascript drag-n-drop functionality
<html>
<head>
<style>
#my-container {
width: 320px;
position: relative;
height: 320px;
margin: auto;
background: black;
}
@lyquix-owner
lyquix-owner / getos.js
Last active September 1, 2016 13:02
getOS: function that returns the name and version of the operating system
// returns the os name, type and version, and sets body classes
// detects major desktop and mobile os: Windows, Windows Phone, Mac, iOS, Android, Ubuntu, Fedora, ChromeOS
// based on bowser: https://github.com/ded/bowser
// list of user agent strings: http://www.webapps-online.com/online-tools/user-agent-strings/dv
function getOS() {
var ua = navigator.userAgent, os;
// helper functions to deal with common regex
function getFirstMatch(regex) {
var match = ua.match(regex);
@lyquix-owner
lyquix-owner / getbrowser.js
Last active September 10, 2023 04:24
getBrowser: function that returns the name, version and type of browser based on browser user agent
// returns the browser name, type and version, and sets body classes
// detects major browsers: IE, Edge, Firefox, Chrome, Safari, Opera, Android
// based on: https://github.com/ded/bowser
// list of user agen strings: http://www.webapps-online.com/online-tools/user-agent-strings/dv
function getBrowser(){
var ua = navigator.userAgent, browser;
// helper functions to deal with common regex
function getFirstMatch(regex) {
var match = ua.match(regex);