Skip to content

Instantly share code, notes, and snippets.

View BigWhale's full-sized avatar

David Klasinc BigWhale

  • Slovenska Bistrica, Slovenia
View GitHub Profile
@BigWhale
BigWhale / mixins.py
Last active February 1, 2021 15:25
Django Rest Framework, conditionally required parameters
from rest_framework import serializers
#
# Use in your Serializer for fields that you want to be required only when certain crieteria is met
#
class ConditionalRequiredMixin(serializers.BaseSerializer):
# List of fields that may be required
conditionally_required: List[str] = []
# Override in your serializer to set required attribute
@BigWhale
BigWhale / functions.php
Created January 17, 2020 17:25
Woocommerce - modify order number
add_filter( 'woocommerce_order_number', 'arglebargle_set_order_prefix' );
function arglebargle_set_order_prefix( $order_id ) {
switch ( get_locale() ) {
case 'hr':
$prefix = 'HR-';
break;
default:
$prefix = 'SI-';
break;
}
@BigWhale
BigWhale / single.php
Last active June 29, 2019 09:08
WordPress - get related posts by post tags
// Add this to your single.php or somewhere else where you see fit. :)
//
$post_id = get_the_ID();
// Extract post tags
$tags = get_the_terms( $post_id, 'post_tag' );
$tag_list = wp_list_pluck( $tags, 'term_id' );
$tag_list = implode( ',', $tag_list );
// Select post ID's from term_relationships table and order by those that match the most number of tags
@BigWhale
BigWhale / tailwind-config.js
Last active June 27, 2019 13:50
Tailwind more pseudo classes and variants
variants: {
margin: ['responsive', 'last-child', 'first-child', 'odd-child', 'even-child'],
},
plugins: [
function({ addVariant, e }) {
addVariant('first-child', ({ modifySelectors, separator }) => {
modifySelectors(({ className }) => {
return `.${e(`first-child${separator}${className}`)}:first-child`
})
})
@BigWhale
BigWhale / share_it.php
Last active April 17, 2019 12:02
All WordPress plugins for sharing links on social media sucks
/**
* Creates a social media links for various sites
*
* @param string $title Title that is passed to sharing site
* @param string $link permalink that will be shared
* @return string html snippet with icons
*/
function insert_social_links( $link, $title, $image, $desc ) {
$link = esc_url( $link );
@BigWhale
BigWhale / glitch_check.js
Created September 2, 2018 23:00
Glitch check for Roll20 Shadowrun 5E advanced template
on("ready", function() {
log("Woo, I am here!");
on('chat:message', function(msg) {
var ones = 0,
total = 0,
hits = 0,
res,
who,
re = new RegExp("^{{name=(.*?)}}");
if (msg.type !== "api") {
@BigWhale
BigWhale / wp-mem-usage.php
Created September 27, 2017 14:40
WordPress theme memory usage
add_action( 'shutdown', 'do_shutdown', 999);
function do_shutdown() {
$f = fopen('/tmp/memory_usage.txt', 'a+');
$usage = memory_get_peak_usage( true );
fwrite( $f, $usage / 1024 / 1024 . " MB\n" );
fclose( $f );
}