Skip to content

Instantly share code, notes, and snippets.


ʞↃ∀ɾ thagxt

View GitHub Profile
thagxt / dark-mode.js
Last active Jan 10, 2020
Detect if OS is in dark mode with Vanilla JS and add class to BODY
View dark-mode.js
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() {
thagxt / dark-mode.css
Last active Oct 27, 2019
Detect if the OS is in dark mode in browsers
View dark-mode.css
/* Light mode */
@media (prefers-color-scheme: light) {
body {
background-color: #FFFFFF;
color: #000000;
/* Dark mode */
@media (prefers-color-scheme: dark) {
thagxt / url-check.php
Last active Oct 27, 2019
Check if URL exists in PHP - With this function you can check if a URL is really 404 or else
View url-check.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 / dl-ex.php
Last active Oct 24, 2020
Download & Extract .zip with cURL directly on your server
View dl-ex.php
$url = ""; // URL of what you wan to download
$zipFile = ""; // 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 / .htaccess
Created Aug 31, 2016
Make a redirect match with or without closing /
View .htaccess
# Make a redirect match with or without closing /
# is the same as
# something that doesn't happen with Redirect 301
RedirectMatch 301 ^/highlights/?$ /highlights.html
thagxt / upgrade.cli
Created Aug 31, 2016
Magento 2 > Upgrade to next version via composer
View upgrade.cli
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 / get-product-info.php
Created Aug 25, 2016
Magento 2 > product page > get Product URL, get Product Name and get Product ID
View get-product-info.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 /
Last active May 18, 2021
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 / strip-https
Last active Jun 28, 2017
Remove both http:// & https:// from URL
View strip-https
$url = "";
$url = preg_replace('/^https?:\/\//', '', $url);
// output:

Regular expressions syntax

Regular Expression Matches
foo The string “foo”
^foo “foo” at the start of a string
foo$ “foo” at the end of a string
^foo$ “foo” when it is alone on a string
[abc] a, b, or c
[a-z] Any lowercase letter