Snippets Collections
from dotenv import load_dotenv
from os import getenv
import vt

load_dotenv()

"""
requirements :
pip install python-dotenv==1.1.0
pip install vt_py==0.20.0

1 - Create account in https://www.virustotal.com/
2 - Copy your API Key and but it into .env file or put it into your script

"""
apikey = getenv('api_key')

url = input('URL:')

stats_meaning = {
    'malicious': 'No engine explicitly marked this URL as malicious (i.e., known for phishing, malware, scams, etc.). ✅',
    'suspicious': 'No engine thought the URL looked suspicious or sketchy based on patterns or heuristics. ✅',
    'harmless': 'engines scanned the URL and found it to be safe. ✅',
    'undetected': 'engines scanned it but didn’t detect anything, which often means they didn’t have an opinion one way or the other — like saying “no result.” 🟡',
    'timeout': 'No engines timed out while analyzing the URL. ✅',
}

with vt.Client(apikey=apikey) as client:
    analysis = client.scan_url(url=url, wait_for_completion=True)
    stats = analysis.stats
    for k in stats:
        print(f"{k} : {str(stats[k])} {stats_meaning[k].capitalize()}")


add_filter('post_type_link', 'custom_post_type_link', 10, 3);
function custom_post_type_link($permalink, $post, $leavename) {
    if (!($post instanceof WP_Post)) {
        return $permalink;
    }

    if ($post->post_type === 'movies') {
        return get_home_url() . '/' . $post->post_name . '/';
    }

    return $permalink;
}

add_action('pre_get_posts', 'custom_pre_get_posts');
function custom_pre_get_posts($query) {
    global $wpdb;

    if (!$query->is_main_query()) {
        return;
    }

    // Get the requested post name
    $post_name = $query->get('name'); // Use 'name' instead of 'pagename'

    if (empty($post_name)) {
        return;
    }

    // Fetch post type from database
    $result = $wpdb->get_row(
        $wpdb->prepare(
            "SELECT wpp1.post_type, wpp2.post_name AS parent_post_name 
             FROM {$wpdb->posts} AS wpp1 
             LEFT JOIN {$wpdb->posts} AS wpp2 ON wpp1.post_parent = wpp2.ID 
             WHERE wpp1.post_name = %s LIMIT 1",
            $post_name
        )
    );

    if (!$result) {
        return; // Ensure we have a valid result
    }

    $post_type = $result->post_type; // Fix: Define $post_type

    if ($post_type === 'movies') {
        $query->set('post_type', $post_type);
        $query->set('name', $post_name);
        $query->is_single = true;
        $query->is_page = false;
    }
}
function testPropagation(e) {
  e.preventDefault();
  const { target } = e;
  if (target.localName !== 'a' || target.classList.contains('btn--show-modal'))
    return;
  console.log(target);
  const url = new URL(target.href);
  console.log('url', url);
}




//Expanation of new Url()

const baseURL = 'https://www.example.com/';
const url = new URL('/path/to/page', baseURL);

console.log(url.href); // "https://www.example.com/path/to/page"






const url = new URL('https://www.example.com/path/to/page?query=123');

url.protocol = 'http';
url.hostname = 'another-example.com';
url.pathname = '/new/path';
url.searchParams.set('query', '456'); // Update the query parameter
url.hash = '#newSection';

console.log(url.href); // "http://another-example.com/new/path?query=456#newSection"







const url = new URL('https://www.example.com/path?name=David&age=30');

// Get the value of a query parameter
console.log(url.searchParams.get('name')); // "David"

// Add a new query parameter
url.searchParams.append('city', 'Berlin');

// Update an existing query parameter
url.searchParams.set('age', '31');

// Remove a query parameter
url.searchParams.delete('name');

console.log(url.href); // "https://www.example.com/path?age=31&city=Berlin"
https://source.unsplash.com/user/c_v_r
 const searchParams = new URLSearchParams(window.location.search);
  const id = searchParams.get('id');
  console.log(id)
https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.4.120/pdf.min.js
http://localhos/adminer.php
//Get hash of a given url

var some_url = 'https://usefulangle.com/posts?123#slider'

var hash = new URL(some_url).hash;

// "#slider"
console.log(hash);

//
//
//


//Get hash of the current url

// document.URL refers to the current url
var hash = new URL(document.URL).hash;

console.log(hash);



//
//
//


//Change hash of a given url

var some_url = 'https://usefulangle.com/posts?123#slider'

var url_ob = new URL(some_url);
url_ob.hash = '#reviews';

// new url string
var new_url = url_ob.href;

// "https://usefulangle.com/posts?123#reviews"
console.log(new_url);


//
//
//


//Change hash of the current url

// document.URL is the current url
var url_ob = new URL(document.URL);
url_ob.hash = '#345';

// new url
var new_url = url_ob.href;

// change the current url
document.location.href = new_url;


//
//
//

/*
Detecting Change in Hash of the Current URL

The window.hashchange event can be listened to know when the hash fragment in the current url changes.
*/

window.addEventListener('hashchange', function() {
	// new hash value
	console.log(new URL(document.URL).hash);
});
import UIKit
import WebKit

class ViewController: UIViewController, WKNavigationDelegate {
    var webView: WKWebView!

    override func loadView() {
        webView = WKWebView()
        webView.navigationDelegate = self
        view = webView
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        let url = URL(string: "https://www.google.com")!
        webView.load(URLRequest(url: url))
        webView.allowsBackForwardNavigationGestures = true
    }
    
    public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Swift.Void) {
            if(navigationAction.navigationType == .other) {
                if let redirectedUrl = navigationAction.request.url {
                    //do what you need with url
                    //self.delegate?.openURL(url: redirectedUrl)
                }
                decisionHandler(.cancel)
                return
            }
            decisionHandler(.allow)
        }
}
# Zsh
1. zsh: https://github.com/ohmyzsh/ohmyzsh/wiki/Installing-ZSH
2. Oh My Zsh: https://github.com/ohmyzsh/ohmyzsh
3. Powerlevel10k: https://github.com/romkatv/powerlevel10k

	// Don't forget to set the theme and install the fonts
	https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf
	https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf
	https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf
	https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf

	// Execute this to configure the theme
	p10k configure

# Plugins:
// One Dark colour theme
  https://github.com/one-dark/iterm-one-dark-theme

// Look at history of previous commands used:-
  https://github.com/junegunn/fzf

// Command line auto suggestions:-
  https://github.com/zsh-users/zsh-autosuggestions
  
// Quick switch to directories
  https://github.com/agkozak/zsh-z
  
// Found these on this blog post https://udaraw.com/iterm-plugins
UIApplication.shared.open(URL(string: "http://www.google.com")!, options: [:], completionHandler: nil)
/**
 * Provides quick & simple way to verify if some
 * string is valid URL
 *
 * @param   <string>  URL to verify
 * @returns <boolean> Returns true if passed string
 *                    is valid URL, false otherwise
 */
function validateUrl (url) {
    try {
        new URL(url)
    } catch (error) {
        return false
    }
  
    return true
}
// create a schema
const eventSchema = new Schema({
  name: String,
  slug: {
    type: String,
    unique: true
  },
  description: String
});

// create the model
const eventModel = mongoose.model('Event', eventSchema);

// middleware -----
// make sure that the slug is created from the name
eventSchema.pre('save', function(next) {
  this.slug = slugify(this.name);
  next();
});

// function to slugify a name
function slugify(text) {
  return text.toString().toLowerCase()
    .replace(/\s+/g, '-')           // Replace spaces with -
    .replace(/[^\w\-]+/g, '')       // Remove all non-word chars
    .replace(/\-\-+/g, '-')         // Replace multiple - with single -
    .replace(/^-+/, '')             // Trim - from start of text
    .replace(/-+$/, '');            // Trim - from end of text
}
# There are a few ways to change the url in wordpress


# The prefered method is the wp-cli via search-replace.
$ wp search-replace 'http://example.test' 'http://example.com' --skip-columns=guid

# You can also test with a dry run
$ wp search-replace 'foo' 'bar' wp_posts wp_postmeta wp_terms --dry-run


# If the wp-cli is not available or you can't use SSH there are three other ways to try inside the files wp-config and functions.php

# At the beginning of wp-config.php, add
define( 'WP_HOME', 'http://example.com' );
define( 'WP_SITEURL', 'http://example.com' );

# At the end of the file, before the comment to stop editing here, you can set the relocate method. This always takes the current url calling "/wp-login.php" as slug as site url.
define('RELOCATE',true);

# Inside funcions.php, as first call, you can set
update_option( 'siteurl', 'http://example.com');
update_option( 'home', 'http://example.com');

# Use Plugin

The plugin 'Better search replace' is also able to change the links in the database quite easily.


# As last resort, you can change the database values manually.You will have to look for "siteurl" in the table "wp_options" and change the values to the correct url.

# After changing the url, don't forget to remove the above settings again. Move to your settings in the backend and check the url. Also, inside the options section, look for "permalinks". It will bring you to an options page where you can regenerate the dynamic links. Without this regenerating, links for assets, media files and so an would possibly keep pointing to the old url. 
const urlString = window.location.search
const urlParameters = new URLSearchParams(urlString)

if (urlParameters.has('parameter')) {
  urlParameters.get('parameter')
}
const getURLParameters = url =>
  (url.match(/([^?=&]+)(=([^&]*))/g) || []).reduce(
    (a, v) => ((a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a),
    {}
  );

// Examples
getURLParameters('http://url.com/page?n=Adam&s=Smith'); // {n: 'Adam', s: 'Smith'}
getURLParameters('google.com'); // {}
star

Sat Apr 19 2025 09:47:10 GMT+0000 (Coordinated Universal Time)

##python #coding #python #url #securty
star

Thu Jul 04 2024 01:11:04 GMT+0000 (Coordinated Universal Time)

#event #url #newurl
star

Tue Apr 09 2024 01:29:12 GMT+0000 (Coordinated Universal Time)

#random #image #url
star

Tue Mar 21 2023 06:14:02 GMT+0000 (Coordinated Universal Time)

#searchparams #url #search #id
star

Tue Mar 14 2023 05:33:07 GMT+0000 (Coordinated Universal Time) https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.4.120/pdf.min.js

#cdn #javascript #url #code #html
star

Mon Jan 30 2023 05:15:52 GMT+0000 (Coordinated Universal Time)

#url #detabase
star

Thu Jun 23 2022 15:32:32 GMT+0000 (Coordinated Universal Time) https://usefulangle.com/post/298/javascript-url-hash

#jquery #event #change #hash #url
star

Wed Mar 30 2022 07:50:10 GMT+0000 (Coordinated Universal Time)

#ios #swift #url #geturl
star

Fri Feb 11 2022 23:22:04 GMT+0000 (Coordinated Universal Time)

#url #zsh #ohmyzsh #terminal #ubuntu #git #shell #bash
star

Thu Feb 03 2022 12:20:28 GMT+0000 (Coordinated Universal Time)

#ios #swift #webpage #page #web #url #link
star

Sat Jan 08 2022 17:15:53 GMT+0000 (Coordinated Universal Time)

#javascript #url #validation #string
star

Mon Jun 14 2021 12:21:17 GMT+0000 (Coordinated Universal Time) https://scotch.io/courses/create-a-crud-app-with-node-and-mongodb/a-mongoose-model

#express #nodej #mongodb #mongoose #slug #url
star

Fri Jun 11 2021 14:15:50 GMT+0000 (Coordinated Universal Time) https://developer.wordpress.org/cli/commands/search-replace/, https://wordpress.org/support/article/changing-the-site-url/

#wordpress #configuration #url #network
star

Thu Apr 08 2021 13:13:09 GMT+0000 (Coordinated Universal Time)

#javascript #url
star

Wed Nov 04 2020 08:47:54 GMT+0000 (Coordinated Universal Time) https://medium.com/swlh/24-modern-es6-code-snippets-to-solve-practical-js-problems-3609f301859e

#javascript #http #get #url

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension