Skip to content

Instantly share code, notes, and snippets.

View therajumandapati's full-sized avatar
👨‍💻
Hacking away...

Raju Mandapati therajumandapati

👨‍💻
Hacking away...
View GitHub Profile
@therajumandapati
therajumandapati / MigrateWPZoomRecipeCardtoACF.php
Created January 12, 2023 03:46
Migrates the recipe data from WPZoom recipe block to ACF blocks
$post_ids = [3011, 2883, 2930, 2912, 2904, 2801, 2640, 2515, 2480, 1505, 1118, 1011, 1098];
function convertRecipeData($post_id) {
if($post_id === null) return;
echo "============ START POST ID: " . $post_id . " =============\n";
echo "Getting post...\n";
$post = get_post($post_id);
@therajumandapati
therajumandapati / ExtractRecipeDataFromWPZoomRecipeBlock.php
Created January 8, 2023 00:24
Extract recipe data from WPZoom Recipe plugin
$post = get_post(2930);
$blocks = parse_blocks( $post->post_content );
foreach ( $blocks as $block ) {
if( 'wpzoom-recipe-card/block-recipe-card' === $block['blockName']) {
$recipe = [
'title' => $block['attrs']['recipeTitle'],
'summary' => array_key_exists('jsonSummary', $block['attrs']) ? $block['attrs']['jsonSummary']: null,
@therajumandapati
therajumandapati / ga-redirect-tracking.html
Last active May 2, 2018 17:25
GA Tracking before redirection
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXX');
</script>
<script>
function redirect(url) {
@therajumandapati
therajumandapati / coercion.js
Created June 10, 2015 13:58
JavaScript for Amateurs
+[] evaluates to the number zero, because unary-plus tries to convert any value to a number, so that leaves
++[[]][0]+[0]
[[]][0] is an expression accessing the first element in the array, which is a reference to the inner array. This is shorthand for x = [[]]; x[0];, if it helps you see it better.
++[[]][0] then evaluates to a pre-increment of the first element in the array, which returns the value after the element is incremented. Because an array is not numeric, it first needs to coerce it to a number. We saw before that an empty array coerces to 0, so incrementing 0 is 1. If we had a reference to [[]], we’d see that it becomes [1] after the increment operation. (i.e. x = [[]]; ++x[0] // returns 1, and x is now [1])
So, this whole expression boils down to 1 + [0]. Since a number and an array can’t normally be added together, javascript converts both values to strings and concatenates them.