Skip to content

Instantly share code, notes, and snippets.

View EdCharbeneau's full-sized avatar
🏠
Working from home

Ed Charbeneau EdCharbeneau

🏠
Working from home
View GitHub Profile
@SteveSandersonMS
SteveSandersonMS / sequence-number.md
Last active November 28, 2023 20:28
Why sequence numbers should relate to code line numbers, not execution order

Why sequence numbers should relate to code line numbers, not execution order

Or in other words, why you should hard-code sequence numbers, and not generate them programmatically.

Unlike .jsx files, .razor/.cshtml files are always compiled. This is potentially a great advantage for .razor, because we can use the compile step to inject information that makes things better or faster at runtime.

A key example of this are sequence numbers. These indicate to the runtime which outputs came from which distinct and ordered lines of code. The runtime uses this information to generate efficient tree diffs in linear time, which is far faster than is normally possible for a general tree diff algorithm.

Example

// In the form you can multiple of these:
<MTextField Text=@Text
IsAutofocus=@IsAutofocus
IsMultiline=@IsMultiline
Lines=@Lines
Value=@Value
Placeholder=@Placeholder
Suffix=@Suffix
OnChange=@OnChange
InputType=@InputType
public HandRank GetHandRank() =>
IsRoyalFlush() ? HandRank.RoyalFlush :
IsStraightFlush() ? HandRank.StraightFlush :
IsFourOfAKind() ? HandRank.FourOfAKind :
IsFullHouse() ? HandRank.FullHouse :
IsFlush() ? HandRank.Flush :
IsStraight() ? HandRank.Straight :
IsThreeOfAKind() ? HandRank.ThreeOfAKind :
IsTwoPair() ? HandRank.TwoPair :
IsPair() ? HandRank.Pair :
@milosdjakonovic
milosdjakonovic / pattern.js
Created July 28, 2016 18:50
Regex to match media queries and get values
/@\s*?media\s*?\(\s*?(min|max)-(width|height)\s*?:\s*?(\d+)(px|em)\s*?\)\s*?{(.*)}/gms
/**
* Only basically tested.
* Should match min-max-width-height number px|em and following rules.
* Provides capturing groups to determinate condition alongside with css.
*
* Created with help of regex101
* https://regex101.com/r/zA6fX2/1
@basham
basham / css-units-best-practices.md
Last active April 18, 2024 16:44
CSS Units Best Practices

CSS units

Recommendations of unit types per media type:

Media Recommended Occasional use Infrequent use Not recommended
Screen em, rem, % px ch, ex, vw, vh, vmin, vmax cm, mm, in, pt, pc
Print em, rem, % cm, mm, in, pt, pc ch, ex px, vw, vh, vmin, vmax

Relative units

Relative units

@ericlathrop
ericlathrop / LouisvilleTechMeetups.md
Last active April 14, 2020 22:12
Louisville Tech Meetups
@EricBusch
EricBusch / replace-buy-button-with-more-details.php
Created January 22, 2014 15:35
Replaces "Buy" button with "More Details" button on list of products (WooCommerce). For example on category pages.
<?php
/**
* Removes the "Buy" button from list of products (ex. category pages).
*/
add_action( 'woocommerce_after_shop_loop_item', 'mycode_remove_add_to_cart_buttons', 1 );
function mycode_remove_add_to_cart_buttons() {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
}