Showing posts with label Hackathon Project. Show all posts
Showing posts with label Hackathon Project. Show all posts

Wednesday, July 15, 2026

Build a Memory Match Game on ServiceNow: A Fun Hackathon Project for Developers

Memory Match: a ServiceNow hackathon project banner

Most ServiceNow hackathon demos look the same: a catalog item with an approval flow, a Flow Designer automation that closes tickets a little faster, a dashboard nobody asked for. A few of us wanted to try something different for our next internal hackathon — could we build something that's actually fun to demo, while still exercising real Service Portal development skills? That question turned into a small browser game called Memory Match, built entirely as a native ServiceNow widget.

The idea itself is simple: a flip-card memory game with a live moves/time tracker and a saved leaderboard. What makes it a genuinely useful hackathon project isn't the game concept — it's that building one small, self-contained feature forces you through nearly every layer of Now Platform widget development: client-side state management, GlideRecord operations, ACL decisions, and the HTML/CSS/client/server split that every production widget shares.

From there, we sketched out a project plan the same way we would for any other hackathon build.

Project Plan for the Memory Match Widget

1. Requirements Gathering

  • Understand what a Service Portal widget can and can't do out of the box.
  • Define what the game needs to actually work:
    • A card grid that flips and checks for matches, entirely client-side for responsiveness.
    • A moves counter and a running timer.
    • A win state that lets the player save their score.
    • A persisted leaderboard, stored server-side so it survives page reloads and is visible to everyone.
    • A custom table to hold scores, since nothing in the base schema fits.
    • Sensible ACLs — this is worth flagging early: the moment you add write access for anonymous or lightly-authenticated users, you need to think through who can insert records and whether the client can be trusted to self-report a score without any server-side sanity checking.

2. Technology Stack

  • Frontend: Service Portal's built-in AngularJS 1.x widget framework — HTML template plus a client controller, no external UI library needed.
  • Backend: the widget's native Server Script, running standard server-side JavaScript.
  • Data: a custom table (u_memory_game_score) accessed through GlideRecord.
  • Hosting: none needed — it runs entirely inside the existing ServiceNow instance, on Service Portal.

3. Design and Architecture

  • HTML Template: the card grid, stats bar, win screen, and leaderboard table — all driven by Angular bindings against the client controller's scope.
  • Client Controller: owns all real-time gameplay — card flips, match checking, the timer — so nothing needs a server round-trip while the player is actually playing.
  • Server Script: only gets involved twice — once to save a finished score, once to fetch the current leaderboard.
  • CSS: a simple 3D flip transform for the cards, kept in the widget's own CSS field so it doesn't leak into the rest of the portal theme.

4. Implementation Steps

  1. Create the table: u_memory_game_score with player name, moves, and seconds fields.
  2. Build the widget shell: new Service Portal widget, wire up the four fields — HTML Template, CSS, Client Controller, Server Script.
  3. Implement gameplay: shuffle a deck, handle flip/match logic, run the timer with $interval.
  4. Wire up persistence: on win, call c.server.get() to save the score and pull back a fresh leaderboard.
  5. Add the page: drop the widget onto a portal page through Service Portal Designer.
  6. Test: confirm the full loop — play, win, save name, see the leaderboard update — works end to end, on both desktop and mobile.

5. Deployment and Maintenance

  • Build and test it in a personal developer instance first (free at developer.servicenow.com) before touching anything production-facing.
  • Move it between instances with a standard Update Set, like any other customization.
  • Review the table's ACLs periodically — especially if it ever moves from an internal demo to something with wider portal exposure.

With the plan settled, here's what the actual widget code looks like — the same pattern you'd use for any Service Portal widget, just applied to a game instead of a form.

The Widget, Piece by Piece

The HTML Template lays out the card grid, stats, and leaderboard using standard Angular directives:

<div class="mg-board" ng-if="!c.won">
  <div class="mg-card"
       ng-repeat="card in c.cards track by $index"
       ng-class="{flipped: card.flipped || card.matched}"
       ng-click="c.flipCard($index)">
    <div class="mg-card-inner">
      <div class="mg-card-front">?</div>
      <div class="mg-card-back">{{card.icon}}</div>
    </div>
  </div>
</div>

The Client Controller handles every flip, entirely in the browser — no server call while the player is mid-game:

c.flipCard = function(index) {
  if (lockBoard) return;
  var card = c.cards[index];
  if (card.flipped || card.matched) return;

  card.flipped = true;
  flippedIndexes.push(index);

  if (flippedIndexes.length === 2) {
    c.moves++;
    lockBoard = true;
    var first = c.cards[flippedIndexes[0]];
    var second = c.cards[flippedIndexes[1]];

    if (first.icon === second.icon) {
      first.matched = true;
      second.matched = true;
      flippedIndexes = [];
      lockBoard = false;
      checkWin();
    } else {
      setTimeout(function() {
        $scope.$apply(function() {
          first.flipped = false;
          second.flipped = false;
          flippedIndexes = [];
          lockBoard = false;
        });
      }, 800);
    }
  }
};

And the Server Script is where GlideRecord does the only two things it needs to: save a score, and return the current top ten.

function getLeaderboard() {
  var results = [];
  var gr = new GlideRecord('u_memory_game_score');
  gr.orderBy('u_moves');
  gr.orderBy('u_seconds');
  gr.setLimit(10);
  gr.query();
  while (gr.next()) {
    results.push({
      name: gr.getValue('u_player_name'),
      moves: gr.getValue('u_moves'),
      seconds: gr.getValue('u_seconds')
    });
  }
  return results;
}

if (input.action === 'save_score') {
  var gr = new GlideRecord('u_memory_game_score');
  gr.initialize();
  gr.setValue('u_player_name', input.name);
  gr.setValue('u_moves', input.moves);
  gr.setValue('u_seconds', input.seconds);
  gr.insert();

  data.leaderboard = getLeaderboard();
} else if (input.action === 'get_leaderboard') {
  data.leaderboard = getLeaderboard();
}

That's the whole architecture: client owns the interaction, server owns the record of truth. It's a pattern you'll reuse constantly in real widget development — usually dressed up as "request status" or "approval state" instead of a game score.

Why This Works Well as a Hackathon Project

  • It demos itself. Judges don't need a walkthrough — they can just play it.
  • A working v1 is fast. A minimal playable version, no leaderboard, can be done in an hour or two.
  • It's memorable. Weeks later, "the team that built a game" outlasts "the team that streamlined another form" in people's memory.
  • It scales with skill level. Beginners ship a working game. More experienced developers can add difficulty scaling, real-time multiplayer, or tie the leaderboard into actual Performance Analytics data.

Additional Tips If You Try This

  • Lock down the leaderboard table: restrict write access appropriately once this leaves a sandbox — don't leave it open to any authenticated user by default.
  • Reuse the pattern for real training tools: the same widget skeleton works for an onboarding quiz, an incident-response speed drill, or a leaderboard tied to real ticket-resolution metrics.
  • Keep gameplay client-side: anything that needs to feel instant — flips, timers, animations — should never wait on a server round-trip.

If your next hackathon team is stuck between "another approval flow" and "something people will actually remember," build the game. It touches the same core skills as any production widget — just with a much better demo.

Sunday, July 21, 2024

AdSense Eligibility Checker script

There are plenty of online tools that claim to check a website's Google AdSense eligibility. A few colleagues and I gave this some thought as a hackathon project: could we build a tool that helps publishers spot the basic checklist items they might overlook before applying for Google AdSense? Getting AdSense approval is tricky enough on its own — missing a basic requirement can lead to rejection even after a lot of hard work on the underlying site.

The goal for the tool itself was simple: it needed to be genuinely easy to use. A user enters their domain in a free-form input box, clicks Start Now, and the tool runs through the mandatory checks for Google AdSense approval before returning detailed results.

The core checks we landed on: does the site have unique, useful content; is that content original or properly licensed; does the site have clear menus and easy navigation; does it get a reasonable amount of organic search traffic; does it avoid anything that would violate AdSense policies; and is the content in a supported language and region.

From there, we sketched out a high-level project plan for the hackathon build.

Project Plan for AdSense Eligibility Checker

1. Requirements Gathering

  • Understand all Google AdSense eligibility requirements.
  • Define the criteria the tool should check:
    • Unique and useful content.
    • Original or appropriately licensed material.
    • Clear menus and easy navigation.
    • A reasonable amount of organic traffic.
    • No content violating AdSense policies.
    • Content in a supported language and region.
    • Required pages present — an About page, a Privacy Policy, and a Contact page. These are now consistently treated as close to non-negotiable for approval.
    • Site ownership and HTML access — the applicant needs to actually own the site and be able to access its HTML source. This is worth flagging as a real limitation of any domain-only checker tool (including this one): it's something a URL-based check genuinely can't verify.

2. Technology Stack

  • Frontend: HTML, CSS, JavaScript, React/Angular for the user interface.
  • Backend: Node.js/Python for server-side processing.
  • Database: MongoDB/MySQL for storing user queries and results.
  • Web Scraping and Analysis: Python with BeautifulSoup, Scrapy, or Puppeteer for checking content, navigation, and policies.
  • Traffic Analysis: Integrate with the Google Analytics API or another SEO/traffic data provider.
  • Hosting: AWS/GCP/Azure for hosting the application.

3. Design and Architecture

  • UI Design: A simple, intuitive interface where users enter their domain and start the check.
  • Backend Services: RESTful APIs to handle user input, perform checks, and return results.
  • Web Scraping Module: Scrapes and analyzes website content.
  • Traffic Analysis Module: Integrates with external services to fetch traffic data.
  • Policy Check Module: Checks content against AdSense policies.

4. Implementation Steps

  1. Frontend Development: design the domain-entry form, wire up the "Start Now" button to trigger backend checks, and display results clearly.
  2. Backend Development: set up the server and database, create endpoints for receiving domain names and triggering checks, and implement the content, traffic, and policy modules.
  3. Web Scraping and Analysis: use BeautifulSoup/Scrapy to scrape site content, analyze it for uniqueness and licensing, and check for clear navigation.
  4. Traffic Analysis: integrate with the Google Analytics API to fetch traffic data.
  5. Policy Compliance Check: implement checks against AdSense policies.
  6. Testing: unit and integration testing, plus user acceptance testing to confirm the tool is actually easy to use.

5. Deployment and Maintenance

  • Deploy the application on a cloud platform.
  • Set up monitoring and logging.
  • Plan for regular updates and maintenance — AdSense policy details shift periodically.

We didn't want to spend anything building this, so for a quick UI trial we used Blogger. For anyone referencing this: the Blogger solution below is a simplified demonstration, not a functional checker. It shows how you could structure the tool with HTML and JavaScript within Blogger's constraints. Building something genuinely functional on Blogger would require external APIs to perform the real checks.

Enhanced Blogger Solution with External APIs

  1. Check for Unique Content — use a plagiarism-detection API. Several paid and free-tier options exist; evaluate current providers rather than assuming any specific one is still free, since pricing and availability change.
  2. Check for Clear Navigation — a simple heuristic: fetch the page HTML and look for common navigation elements like <nav> or <ul>.
  3. Check for Organic Traffic — a traffic-estimation service can provide a rough signal, though free tiers of these tools are usually limited and directional rather than precise.
  4. Check for Policy Violations and Supported Language — these are the hardest to automate meaningfully without a real backend. Basic checks, like detecting the page's language client-side, are feasible; genuine policy-violation detection generally isn't, without something closer to Google's own review process.
Worth being upfront about: a URL-based checker — this one included — can approximate a few surface signals, but it fundamentally can't verify site ownership, HTML source access, or the kind of content-quality judgment Google's own reviewers (increasingly AI-assisted) now apply. Treat any such tool as a rough pre-check, not a substitute for actually reading Google's current Publisher Policies and reviewing the site yourself.

Example Implementation (Blogger / Static HTML)

This example shows the structure — it won't perform real checks without wiring in actual API calls, but it's a working starting point you can build on:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AdSense Eligibility Checker</title>
    <style>
        .checker-container {
            max-width: 600px;
            margin: auto;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 8px;
            background-color: #f9f9f9;
        }
        input[type="text"] {
            width: calc(100% - 22px);
            padding: 10px;
            margin-bottom: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        button {
            padding: 10px 20px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        button:hover {
            background-color: #0056b3;
        }
        #results {
            margin-top: 20px;
        }
    </style>
</head>
<body>
    <div class="checker-container">
        <h1>AdSense Eligibility Checker</h1>
        <input type="text" id="domainName" placeholder="Enter your domain name">
        <button onclick="checkEligibility()">Start Now</button>
        <div id="results"></div>
    </div>

    <script>
        async function checkEligibility() {
            const domainName = document.getElementById('domainName').value;
            document.getElementById('results').innerHTML = 'Checking...';

            const results = {
                uniqueContent: await checkUniqueContent(domainName),
                clearNavigation: await checkNavigation(domainName),
                organicTraffic: await checkTraffic(domainName),
                noPolicyViolations: checkPolicyViolations(domainName),
                supportedLanguage: await checkLanguage(domainName)
            };
            displayResults(domainName, results);
        }

        async function checkUniqueContent(domain) {
            // Implement API call to a plagiarism checker service
            // Example (pseudo code):
            // const response = await fetch(`https://api.example-plagiarism-checker.com/check?domain=${domain}`);
            // return response.isUnique;
            return Math.random() > 0.5; // Placeholder
        }

        async function checkNavigation(domain) {
            // Fetch the HTML of the domain and check for navigation elements
            // Example (pseudo code):
            // const response = await fetch(`https://your-cors-proxy.example.com/${domain}`);
            // const html = await response.text();
            // return html.includes('<nav>') || html.includes('<ul>');
            return Math.random() > 0.5; // Placeholder
        }

        async function checkTraffic(domain) {
            // Use a traffic analytics service to get traffic data
            // Example (pseudo code):
            // const response = await fetch(`https://api.example-traffic-tool.com/website/${domain}/traffic`);
            // return response.visits > 1000; // Arbitrary traffic threshold
            return Math.random() > 0.5; // Placeholder
        }

        function checkPolicyViolations(domain) {
            // Implement basic checks for AdSense policy violations
            // This typically requires a backend for comprehensive checks
            return Math.random() > 0.5; // Placeholder
        }

        async function checkLanguage(domain) {
            // Use a language detection library to verify the site's language
            // Example (pseudo code):
            // const response = await fetch(`https://your-cors-proxy.example.com/${domain}`);
            // const html = await response.text();
            // const detectedLanguage = detectLanguage(html);
            // return detectedLanguage === 'en'; // Check if language is supported
            return Math.random() > 0.5; // Placeholder
        }

        function displayResults(domain, results) {
            let resultHtml = `<h2>Results for ${domain}</h2>`;
            resultHtml += `<p>Unique Content: ${results.uniqueContent ? 'Yes' : 'No'}</p>`;
            resultHtml += `<p>Clear Navigation: ${results.clearNavigation ? 'Yes' : 'No'}</p>`;
            resultHtml += `<p>Organic Traffic: ${results.organicTraffic ? 'Yes' : 'No'}</p>`;
            resultHtml += `<p>No Policy Violations: ${results.noPolicyViolations ? 'Yes' : 'No'}</p>`;
            resultHtml += `<p>Supported Language: ${results.supportedLanguage ? 'Yes' : 'No'}</p>`;

            document.getElementById('results').innerHTML = resultHtml;
        }
    </script>
</body>
</html>

We realized a fully functional checker on Blogger is genuinely difficult given the platform's constraints. With enough external API and JavaScript work you can get further, but if the project scope allows even a small investment, WordPress is a considerably more flexible platform for something like this.

Comparison: WordPress vs. Blogger

Feature WordPress Blogger
Ease of UseBeginner-friendly, with a learning curveVery beginner-friendly
CustomizationHighly customizableLimited customization options
Plugins and ExtensionsExtensive plugin libraryLimited plugin support
Development FlexibilityFull control with custom codeLimited development capabilities
Backend IntegrationEasy to set up backend with PHPNo backend capabilities
Community and SupportLarge community, extensive resourcesSmaller community, fewer resources

Step-by-Step Guide for WordPress

1. Set Up a WordPress Site

  • Install WordPress: set up a site on your chosen hosting provider.
  • Create a New Page: go to Pages > Add New and create a page for the checker.

2. Create a Custom Plugin for Backend Functionality

Create a plugin folder at wp-content/plugins/adsense-eligibility-checker, and inside it, a main plugin file named adsense-eligibility-checker.php:

<?php
/*
Plugin Name: AdSense Eligibility Checker
Description: A tool to check AdSense eligibility criteria for a website.
Version: 1.0
Author: Your Name
*/

// Enqueue scripts and styles
function adsense_checker_enqueue_scripts() {
    wp_enqueue_script('adsense-checker-script', plugin_dir_url(__FILE__) . 'adsense-checker.js', array('jquery'), null, true);
    wp_enqueue_style('adsense-checker-style', plugin_dir_url(__FILE__) . 'adsense-checker.css');
}
add_action('wp_enqueue_scripts', 'adsense_checker_enqueue_scripts');

// AJAX handler
function adsense_checker_ajax_handler() {
    $domain = sanitize_text_field($_POST['domain']);

    // Perform checks (placeholder functions)
    $results = array(
        'uniqueContent' => check_unique_content($domain),
        'clearNavigation' => check_navigation($domain),
        'organicTraffic' => check_traffic($domain),
        'noPolicyViolations' => check_policy_violations($domain),
        'supportedLanguage' => check_language($domain),
    );

    wp_send_json($results);
}
add_action('wp_ajax_adsense_checker', 'adsense_checker_ajax_handler');
add_action('wp_ajax_nopriv_adsense_checker', 'adsense_checker_ajax_handler');

// Placeholder functions for checks
function check_unique_content($domain) { return true; }
function check_navigation($domain) { return true; }
function check_traffic($domain) { return true; }
function check_policy_violations($domain) { return true; }
function check_language($domain) { return true; }

// Shortcode to display the checker form
function adsense_checker_shortcode() {
    ob_start();
    ?>
    <div class="checker-container">
        <h1>AdSense Eligibility Checker</h1>
        <input type="text" id="domainName" placeholder="Enter your domain name">
        <button id="startNow">Start Now</button>
        <div id="results"></div>
    </div>
    <?php
    return ob_get_clean();
}
add_shortcode('adsense_checker', 'adsense_checker_shortcode');
?>

Add the companion JavaScript file, adsense-checker.js, in the same plugin folder:

jQuery(document).ready(function($) {
    $('#startNow').click(function() {
        var domainName = $('#domainName').val();
        $('#results').html('Checking...');

        $.ajax({
            url: ajaxurl,
            type: 'POST',
            data: {
                action: 'adsense_checker',
                domain: domainName
            },
            success: function(response) {
                var resultHtml = '<h2>Results for ' + domainName + '</h2>';
                resultHtml += '<p>Unique Content: ' + (response.uniqueContent ? 'Yes' : 'No') + '</p>';
                resultHtml += '<p>Clear Navigation: ' + (response.clearNavigation ? 'Yes' : 'No') + '</p>';
                resultHtml += '<p>Organic Traffic: ' + (response.organicTraffic ? 'Yes' : 'No') + '</p>';
                resultHtml += '<p>No Policy Violations: ' + (response.noPolicyViolations ? 'Yes' : 'No') + '</p>';
                resultHtml += '<p>Supported Language: ' + (response.supportedLanguage ? 'Yes' : 'No') + '</p>';

                $('#results').html(resultHtml);
            },
            error: function(error) {
                $('#results').html('Error checking eligibility. Please try again.');
                console.error('Error:', error);
            }
        });
    });
});

And the stylesheet, adsense-checker.css:

body {
    font-family: Arial, sans-serif;
    margin: 20px;
}
.checker-container {
    max-width: 600px;
    margin: auto;
    padding: 20px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background-color: #f9f9f9;
}
input[type="text"] {
    width: calc(100% - 22px);
    padding: 10px;
    margin-bottom: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
}
button {
    padding: 10px 20px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}
button:hover {
    background-color: #0056b3;
}
#results {
    margin-top: 20px;
}

3. Activate the Plugin

  • Go to your WordPress Dashboard.
  • Navigate to Plugins > Installed Plugins.
  • Find the AdSense Eligibility Checker plugin and click Activate.

4. Add the Checker to a Page

  • Go to the page you created in step 1.
  • Add the shortcode [adsense_checker] where you want the checker to appear.
  • Save and publish the page.

Testing and Enhancing

  • Testing: visit the page, enter a domain name, and click "Start Now" to confirm the flow works end to end.
  • Enhancing: replace the placeholder functions with real implementations for each check.

Additional Tips

  • SEO Analysis Tools: integrate a third-party SEO/traffic analysis API for more detailed traffic data than a free tier typically provides.
  • Regular Updates: AdSense policies change periodically — revisit and update the checks accordingly rather than treating them as fixed.
  • User Feedback: collect feedback to improve the tool's usability and the accuracy of its checks over time.