Skip to content

Instantly share code, notes, and snippets.

View thagxt's full-sized avatar
🎯
Focusing

ʞↃ∀ɾ thagxt

🎯
Focusing
View GitHub Profile
@thagxt
thagxt / run-a-local-server-inside-dir.md
Last active December 2, 2022 16:48
Run a local web server inside any folder on Mac, Window, Linux, PHP, Node.js

Node.js

# Install http-server module globally 
npm install http-server -g

# Navigate to any directory you want the server to run in
cd /path/to/dir/with/files

# Launch HTTP server
@thagxt
thagxt / dark-mode.js
Last active January 10, 2020 20:59
Detect if OS is in dark mode with Vanilla JS and add class to BODY
document.addEventListener("DOMContentLoaded", function(){
// Detect dark mode with Vanilla JS and add class to BODY
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.body.classList.add("dark-mode"); // your class here
}
// Turn Dark Mode on/off, manually
document.querySelector('.lightsoff').onclick = function() {
document.querySelector('body').classList.toggle('dark-mode');
}
@thagxt
thagxt / dark-mode.css
Last active October 27, 2019 12:17
Detect if the OS is in dark mode in browsers
/* Light mode */
@media (prefers-color-scheme: light) {
body {
background-color: #FFFFFF;
color: #000000;
}
}
/* Dark mode */
@media (prefers-color-scheme: dark) {
@thagxt
thagxt / url-check.php
Last active September 7, 2022 17:39
Check if URL exists in PHP - With this function you can check if a URL is really 404 or else
<?php
// With this function you can check response code if it really is 404 or nah
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) ){
@thagxt
thagxt / dl-ex.php
Last active February 23, 2022 18:45
Download & Extract .zip with cURL directly on your server
<?php
$url = "https://wordpress.org/latest.zip"; // URL of what you wan to download
$zipFile = "wordpress.zip"; // Rename .zip file
$extractDir = "extracted"; // Name of the directory where files are extracted
$zipResource = fopen($zipFile, "w");
// Get The Zip File From Server
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
@thagxt
thagxt / .htaccess
Created August 31, 2016 11:48
Make a redirect match with or without closing /
# Make a redirect match with or without closing /
# example.com/highlights is the same as example.com/highlights/
# something that doesn't happen with Redirect 301
RedirectMatch 301 ^/highlights/?$ /highlights.html
@thagxt
thagxt / upgrade.cli
Created August 31, 2016 11:36
Magento 2 > Upgrade to next version via composer
composer require magento/product-community-edition 2.1.1 --no-update
composer update
rm -rf var/di var/generation
php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento indexer:reindex
@thagxt
thagxt / get-product-info.php
Created August 25, 2016 14:10
Magento 2 > product page > get Product URL, get Product Name and get Product ID
<?php
// get current page URL
$URL = $this->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]);
// get current product name & ID
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('current_product'); //get current product
$id = $product->getId();
$title = $product->getName();
@thagxt
thagxt / mage2-multiweb-subdir.md
Last active May 2, 2024 14:03
Set up Magento 2 multiple websites in sub directories

Set up Magento 2 multiple websites in sub directories

  1. Go to Admin > Stores > All Stores
  2. Click > Create Web Site
  3. In the Name field, enter store name.
    • e.g. Japan
  4. In the Code field, enter a unique string without spaces and > Save Web Site
    • e.g. super_jp
  5. Create Store
  6. Create Store View
@thagxt
thagxt / strip-https
Last active June 28, 2017 21:04
Remove both http:// & https:// from URL
<?php
$url = "https://example.com/";
$url = preg_replace('/^https?:\/\//', '', $url);
// output: example.com/
?>