Skip to content

Instantly share code, notes, and snippets.

@syad9000
syad9000 / .htaccess
Last active April 21, 2023 15:09
Remove HTML/PHP extension from URL and then add a slash at the end
#########################
# Begin Rewrite Rules
#########################
#
# Turn on Rewrite Engine
RewriteEngine on
#
# Add a trailing slash at the end of URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
# How to Install Apache 2.4 & PHP 8.0 on Amazon Linux
[https://tecadmin.net/install-apache24-php7-on-amazon-linux/](https://tecadmin.net/install-apache24-php7-on-amazon-linux/
## Install Apache
```
sudo yum update -y
sudo yum install -y httpd httpd-tools mod_ssl
sudo systemctl enable httpd
sudo systemctl start httpd
```
@syad9000
syad9000 / JS Router
Last active March 24, 2023 12:42
Another version of thecreazy's JS router from: https://github.com/thecreazy/create-a-modern-javascript-router
function Router( config )
{
/**
* Default values unless they are set in the call to the constructor
*/
this.routes = [];
this.root = "/";
this.notFound = "/404/";
this.hash = "#"
function Util()
{
this.url = {
parse_search : function(s) {
var search = (!s) ? window.location.search.substring(1) : s;
return (!search) ? {} : JSON.parse('{"' + decodeURI(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}');
}
};
@syad9000
syad9000 / global-search-account.js
Created October 15, 2020 19:51
OmniUpdate sample code for using API to search all files in an account.
var search_account = {
apihost : location.protocol + '//' + location.host,
protocol : location.protocol,
version : location.pathname.replace(/\//gi, ''),
skin : location.hash.split("/")[0],
account : location.hash.split("/")[1],
site : location.hash.split("/")[2],
getElement : function(n, v, t){
n = document.createElement(n);
for (var p in v)
<?php
/**
* CORS for PHP allowing the Authorization header to be used with Javascript
*/
#
# Array holding allowed Origins
foreach ([
'(https://)?(www\.)?remotedomain\.com' // Remote Domain
] as $o) {
if (preg_match("#$o#", $_SERVER['HTTP_ORIGIN'])) {
function parse_url(url){
var a = url.split("/").filter(b => b),
p = a.shift(),
h = a.shift(),
t = a.join("/").split("?");
return {
protocol : p, host : h, port : h.split(":")[1] || null, path : t[0],
query : t[1] ? t[1].split("#")[0] : null,
hash : (t[1] ? t[1].split("#")[1] : null) || null
@syad9000
syad9000 / dateFormat.js
Created August 3, 2018 20:48
A simple date formatter without having to import moment.js
Date.prototype.format = function( format = 'Y-m-d' )
{
var LZ = function( x ){ return ( parseInt(x) < 10 ? '0' : '' ) + x };
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
var y = this.getFullYear().toString();
var M = this.getMonth()+1;
var d = this.getDate();
var E = this.getDay();
var H = this.getHours();