Skip to content

Instantly share code, notes, and snippets.

@victorwyee
victorwyee / functions.php
Created April 12, 2020 04:30
Display page/post categories, excluding specified categories. #wordpress
function exclude_post_categories($exclude="", $spacer=" ", $id=false){
// allow for specifiying id in case we want to use the function to bring in
// another pages categories
if(!$id){
$id = get_the_ID();
}
$categories = get_the_category($id); // get the categories
$exclude = explode(",",$exclude); // split the exclude string into an array
$result = array(); // define array for storing results
foreach($categories as $cat) { // loop the cats
@victorwyee
victorwyee / functions.php
Last active April 12, 2020 03:04
Hide categories from Wordpress category widget #wordpress
function exclude_widget_categories($args) {
$exclude = "4, 6, 7, 8, 9, 23, 43, 69";
$args["exclude"] = $exclude;
return $args;
};
add_filter("widget_categories_args", "exclude_widget_categories");
@victorwyee
victorwyee / functions.php
Last active April 12, 2020 03:04
Styling embedded gists with a shortcode #wordpress
<?php # to enable highlighting
function register_gist_highlighting() {
wp_register_style( 'gist-highlighting-obsidian', '//victorwyee.github.io/gist-syntax-themes/stylesheets/obsidian.css', false, null, 'all');
}
function gist_highlighting_obsidian_shortcode() {
wp_enqueue_style( 'gist-highlighting-obsidian' );
}
@victorwyee
victorwyee / remotes.sh
Last active April 12, 2020 03:05
Rebase or reset to upstream fork. #git
# Add upstream remote
git remote add upstream https://url/to/repo
# Verify remotes
git remote -v
# Fetch upstream remote's branches
git fetch upstream
# Checkout branch to update (e.g. master)
@victorwyee
victorwyee / distance.py
Created March 19, 2020 22:00
Similarity/Distance Functions
def cosine_similarity(v1, v2):
magnitude1 = np.linalg.norm(v1)
magnitude2 = np.linalg.norm(v2)
if (not magnitude1) or (not magnitude2):
return 0
return np.dot(v1, v2) / (magnitude1 * magnitude2)
@victorwyee
victorwyee / middleman.js
Created February 21, 2016 01:09
Creates a webserver that takes a requested URL path, retrieves a response from that URL path, and forwards that response to the requester.
var http = require('http');
function onRequest(client_req, client_res) {
console.log('req: ' + client_req.url);
var options = {
hostname: 'victorwyee.com',
port: 80,
path: client_req.url,
method: 'GET',
@victorwyee
victorwyee / 0_reuse_code.js
Created February 1, 2016 20:05
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console