Skip to content

Instantly share code, notes, and snippets.

@rajuyohannan
rajuyohannan / youtube_id_regex.php
Created December 6, 2023 09:52 — forked from ghalusa/youtube_id_regex.php
Extract the YouTube Video ID from a URL in PHP
<?php
// Here is a sample of the URLs this regex matches: (there can be more content after the given URL that will be ignored)
// http://youtu.be/dQw4w9WgXcQ
// http://www.youtube.com/embed/dQw4w9WgXcQ
// http://www.youtube.com/watch?v=dQw4w9WgXcQ
// http://www.youtube.com/?v=dQw4w9WgXcQ
// http://www.youtube.com/v/dQw4w9WgXcQ
// http://www.youtube.com/e/dQw4w9WgXcQ
// http://www.youtube.com/user/username#p/u/11/dQw4w9WgXcQ
@rajuyohannan
rajuyohannan / remove blank lines regex.md
Created February 19, 2021 09:42 — forked from fomightez/remove blank lines regex.md
remove all blank lines using regular expressions
@rajuyohannan
rajuyohannan / custom-post-type-in-author-archive
Created January 23, 2021 07:32 — forked from betojsx/custom-post-type-in-author-archive
Display Custom Post Type in Author Archive WordPress
// In functions.php, add:
<?php
function post_types_author_archives($query) {
if ($query->is_author)
// Add 'books' CPT and the default 'posts' to display in author's archive
$query->set( 'post_type', array('books', 'posts') );
remove_action( 'pre_get_posts', 'custom_post_author_archive' );
}
@rajuyohannan
rajuyohannan / apache-nginx-ftp
Created January 11, 2021 16:50 — forked from solancer/apache-nginx-ftp
Correct permissions for /var/www/html
// Adding current user to www-data
sudo adduser $USER www-data
//change ownership to user:www-data and
sudo chown $USER:www-data -R /var/www/html
sudo chmod u=rwX,g=srX,o=rX -R /var/www/html
// change file permissions of existing files and folders to 755/644
sudo find /var/www/html -type d -exec chmod g=rwxs "{}" \;
@rajuyohannan
rajuyohannan / download.php
Created October 20, 2020 11:49
Download Remote File to Server with PHP
<?php
file_put_contents("Tmpfile.zip", fopen("http://someurl/file.zip", 'r'));
// https://stackoverflow.com/questions/6348602/download-remote-file-to-server-with-php
@rajuyohannan
rajuyohannan / _spacing-helpers.scss
Created March 26, 2020 06:59 — forked from jacurtis/_spacing-helpers.scss
SASS Margin and Padding Helpers Loop. Generates .m-t-10 type helper classes.
/*
This .scss loop will create "margin helpers" and "padding helpers" for use in your web projects.
It will generate several classes such as:
.m-r-10 which gives margin-right 10 pixels.
.m-r-15 gives MARGIN to the RIGHT 15 pixels.
.m-t-15 gives MARGIN to the TOP 15 pixels and so on.
.p-b-5 gives PADDING to the BOTTOM of 5 pixels
.p-l-40 gives PADDING to the LEFT of 40 pixels
@rajuyohannan
rajuyohannan / .htaccess
Created March 6, 2020 10:22
Exclude Certain Folders from htaccess Rewrite Rules
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(folder1|folder2/.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
@rajuyohannan
rajuyohannan / .htaccess
Created March 6, 2020 10:22
Exclude Certain Folders from htaccess Rewrite Rules
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(folder1|folder2/.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
@rajuyohannan
rajuyohannan / php_error_reporting.php
Last active March 6, 2020 10:23
Show php errors
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
@rajuyohannan
rajuyohannan / functions.php
Created December 13, 2019 06:18 — forked from yratof/functions.php
ACF OEmbed with thumbnails
<?php
/* Pull apart OEmbed video link to get thumbnails out*/
function get_video_thumbnail_uri( $video_uri ) {
$thumbnail_uri = '';
// determine the type of video and the video id
$video = parse_video_uri( $video_uri );
// get youtube thumbnail