Skip to content

Instantly share code, notes, and snippets.

@Alexander-Pop
Alexander-Pop / Install Composer to use MAMP's PHP.md
Created July 25, 2023 13:33 — forked from kkirsche/Install Composer to use MAMP's PHP.md
How to install Composer globally using MAMP's PHP

##Create an alias to MAMP's PHP installation

To do this, we can simply create an alias for our bash profile. We'll be doing this is nano, though you can do it in vim or a number of other editors as well.

Within the terminal, run:

nano ~/.bash_profile

This will open nano with the contents, at the top in a blank line add the following line:

@Alexander-Pop
Alexander-Pop / rename-file.php
Last active February 1, 2019 16:56 — forked from thagxt/rename-file.php
Quickly rename a file name with PHP. w/ error handling #php #file
<?php
$oldname = "index.html";
$newname = "index.php";
// checking if file exist or not.
if ( file_exists($oldname) && ( (!file_exists($newname))|| is_writable($newname) ) ) {
$renameResult = rename($oldname, $newname);
die($oldname . " renamed to " . $newname);
} else {
die('nothing to rename.');
@Alexander-Pop
Alexander-Pop / url-check.php
Last active February 1, 2019 16:56 — forked from thagxt/url-check.php
php check headers status going thru all page statuses #php #url
<?php
/* @ http://stackoverflow.com/a/12628971 */
function getHttpResponseCode_using_getheaders($url, $followredirects = true){
// returns string responsecode, or false if no responsecode found in headers (or url does not exist)
// NOTE: could potentially take up to 0-30 seconds , blocking further code execution (more or less depending on connection, target site, and local timeout settings))
// if $followredirects == false: return the FIRST known httpcode (ignore redirects)
// if $followredirects == true : return the LAST known httpcode (when redirected)
if(! $url || ! is_string($url)){
return false;
@Alexander-Pop
Alexander-Pop / check-if-valid-url.php
Last active February 1, 2019 16:55 — forked from thagxt/check-if-valid-url.php
check if url is valid #php #url
<?php
/* @ http://stackoverflow.com/a/12628971 */
function isValidUrl($url){
// first do some quick sanity checks:
if(!$url || !is_string($url)){
return false;
}
// quick check url is roughly a valid http request: ( http://blah/... )
if( ! preg_match('/^http(s)?:\/\/[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(\/.*)?$/i', $url) ){
return false;
@Alexander-Pop
Alexander-Pop / csv-as-html-table.php
Created June 28, 2017 22:10 — forked from thagxt/csv-as-html-table.php
Display CSV file as HTML Table with first 2 columns clickable
<?php
$file = "releases.csv"; // your csv file name
$directory = $_SERVER['DOCUMENT_ROOT']."/var/releases/".$file; // path to file
$row = 1; // horizontal
if (($handle = fopen($directory, "r")) !== FALSE) {
echo '<table id="releases-calendar">';
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) { // change ";" if your csv delimiter is different...
@Alexander-Pop
Alexander-Pop / functions.php
Last active June 28, 2019 14:10 — forked from thagxt/functions.php
WP - Function to add a class to all your "POST" images in WordPress and get them ready for lazyload. #wp
<?php
function lazyload_filter_content($content) {
global $post; // getting The whole post objects
$content = $post->post_content;
if( is_singular() && is_main_query() ) {
//Renaming images for lazy loader!!!
@Alexander-Pop
Alexander-Pop / home.php
Last active February 1, 2019 16:54 — forked from thagxt/home.php
Limit WordPress' the_excerpt to the first full stop / period #wp
<?php
// Limit WordPress' the_excerpt to the first full stop / period
$strings = preg_split('/(\.|!|\?)\s/', strip_tags($post->post_content), 2, PREG_SPLIT_DELIM_CAPTURE);
$excerpt = apply_filters('the_excerpt', $strings[0] . $strings[1]);
echo $excerpt;
?>
@Alexander-Pop
Alexander-Pop / login.php
Last active February 1, 2019 16:54 — forked from thagxt/login.php
simple PHP login without a database #php #form
<?php
session_start();
// ***************************************** //
// ********** DECLARE VARIABLES ********** //
// ***************************************** //
$username = 'username';
$password = 'password';
@Alexander-Pop
Alexander-Pop / recently-updated-feed.php
Last active February 1, 2019 16:53 — forked from thagxt/recently-updated-feed.php
Custom RSS feed for WordPress with the latest updated posts. #feed #wp
<?php
/**
* Template Name: RSS - Recently Updated
*/
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'orderby' => 'modified',
'order' => 'DESC',
@Alexander-Pop
Alexander-Pop / strip-https
Last active February 1, 2019 16:53 — forked from thagxt/strip-https
Remove both http:// & https:// from URL #php
<?php
$url = "https://example.com/";
$url = preg_replace('/^https?:\/\//', '', $url);
// output: example.com/
?>