Skip to content

Instantly share code, notes, and snippets.

View jxxe's full-sized avatar

Jerome Paulos jxxe

View GitHub Profile
@jxxe
jxxe / memecitations.php
Created May 30, 2020 16:56
MemeCitations Instagram Fix
<?php
header('Content-Type: application/json');
if(!empty($_POST)) {
$post = $_POST;
$post = json_decode($post, true);
$data = file_get_contents('https://api.instagram.com/oembed/?url=' . $post['url']);
$data = json_decode($data, true);

Jerome Paulos

@jxxe
jxxe / remove-meta-wordpress.php
Created June 10, 2020 06:33 — forked from nbeers22/remove-meta-wordpress.php
Remove all the extra bloat of meta tags that WordPress adds to the <head> and disables the JSON API
<?php
// remove some meta tags from WordPress
remove_action('wp_head', 'wp_generator');
function remove_dns_prefetch( $hints, $relation_type ) {
if ( 'dns-prefetch' === $relation_type ) {
return array_diff( wp_dependencies_unique_hosts(), $hints );
}
return $hints;
}
@jxxe
jxxe / degrees-to-cardinal.php
Last active June 4, 2022 13:25 — forked from RobertSudwarts/deg_to_cardinal.py
[PHP] Convert degrees to cardinal directions
function degreesToCardinal($degrees) {
$directions = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW'];
$index = ($degrees + 11.25) / 22.5;
return $directions[$index % 16];
}
@jxxe
jxxe / PHP Templates.md
Created September 23, 2020 03:20
PHP Templates

This is just a proof of concept for PHP-enabled HTML files. Instead of <?php and ?> tags in a PHP file, you could use {} in an HTML file. This would allow you to create static HTML templates that use PHP functions. I'm not sure why you would want to do this instead of using normal PHP, but you could!

Sample HTML:

<p>Today's date is { date('F j, Y') }</p>

And uh..that's the only use I can think of.

@jxxe
jxxe / mysqli-fix.php
Last active September 25, 2020 21:21
Not all servers run the latest version of PHP or have enabled all the packages. This small replacement saved me a lot of frustration with my web host.
<?php
// Replace
$data = $query->fetch_all(MYSQLI_ASSOC);
// With
$rows = [];
while ( $row = mysqli_fetch_assoc($query) ) {
$rows[] = $row;
}
$data = $rows;
@jxxe
jxxe / Cache.php
Last active January 6, 2024 12:15
A quick and dirty PHP class to cache JSON data
<?php
const MONTH = "Y-m"; // 2000-01
const DAY = "Y-m-d"; // 2000-01-01
const HALF_DAY = "Y-m-d-A"; // 2000-01-01-AM
const HOUR = "Y-m-d-H"; // 2000-01-01-24
const MINUTE = "Y-m-d-H-i"; // 2000-01-01-24-60
class Cache {
@jxxe
jxxe / hide_emails.html
Last active September 23, 2021 20:57
Hide email addresses from crawlers
<a email="ZW5jb2RlZEBlbWFpbC5jb20=">Enable JavaScript to view this email address</a>
<a email="YW5vdGhlckBlbWFpbC5jb20=">Enable JavaScript to view this email address</a>
<script>
document.querySelectorAll('[email]').forEach(email => {
let decodedEmail = atob(email.getAttribute('email'));
email.innerText = decodedEmail;
email.href = 'mailto:'+decodedEmail;
email.removeAttribute('email');
})
// ==UserScript==
// @name Laravel Documentation Redirect
// @match https://laravel.com/docs/*
// @version 1.0
// @author Jerome Paulos
// @description Automatically redirect to the latest Laravel documentation
// ==/UserScript==
(() => {
const latestUrl = document.querySelector('#version-switcher option[value*="/master/"] + option').value;
type SmoothAnimationOptions = {
condition: boolean,
addClass?: (node: HTMLElement) => void,
removeClass?: (node: HTMLElement) => void,
animationClass?: string
}
export function smoothAnimation(node: HTMLElement, { condition, addClass, removeClass, animationClass }: SmoothAnimationOptions) {
if(animationClass) {
if(!removeClass) removeClass = () => node.classList.remove(animationClass);