Skip to content

Instantly share code, notes, and snippets.

@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 / form_key_checks.txt
Last active February 1, 2019 16:50 — forked from drobinson/form_key_checks.txt
Magento - form key validation #magento
List (and command that generated it) of places that form key validation has been added in 1.13.1
Controllers that have added form key validation:
$ git grep --files-with-matches "this->_validateFormKey())" <core_sources_update_commit_hash>
<core_sources_update_commit_hash>:app/code/core/Enterprise/Checkout/controllers/CartController.php
<core_sources_update_commit_hash>:app/code/core/Enterprise/GiftRegistry/controllers/IndexController.php
<core_sources_update_commit_hash>:app/code/core/Enterprise/GiftRegistry/controllers/ViewController.php
<core_sources_update_commit_hash>:app/code/core/Enterprise/Reward/controllers/CustomerController.php
<core_sources_update_commit_hash>:app/code/core/Enterprise/Wishlist/controllers/SearchController.php
<core_sources_update_commit_hash>:app/code/core/Mage/Catalog/controllers/Product/CompareController.php
@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/
?>
@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 / 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 / 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 / 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 / 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 / magento-BulkSKUpdate.php
Last active February 1, 2019 16:58
Programmatically Updating SKUs in Bulk on Magento #magento
<?php
/*
1) Create a CSV File with Before and After SKUs.
- In the first column, list your current SKUs and in the second column list the new SKUs.
- Do not include headings in your CSV file.
- Be sure this file is saved as a CSV file in the UTF-8 or ANSI encoding. You might run into problems with this if you create the file using Excel.
2) Upload the CSV file to the var/export directory on your Magento server so that it’s path is /var/export/sku2sku.csv.
3) Run the Script
+ If you run into the following error, don’t worry too much. Just re-run the script and see if more SKUs get updated.
- Cannot retrieve products from Magento: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction