Skip to content

Instantly share code, notes, and snippets.

View zeshanshani's full-sized avatar
🎯
Focusing

Zeshan Ahmed zeshanshani

🎯
Focusing
View GitHub Profile
# Retrieve a single article and its image with requests
import requests
BASE = "https://web-news-service.greenstreet.com"
def get_article(token, article_id):
r = requests.get(f"{BASE}/api/articles/{article_id}", headers={"Authorization": f"Bearer {token}"})
r.raise_for_status()
return r.json()
// Fetch article list with filters using fetch()
async function fetchArticles({ token, region = 'USA', keyword, sectors = [], subregions = [], page = 1 }) {
const url = new URL('https://web-news-service.greenstreet.com/api/articles');
url.searchParams.set('region', region);
if (keyword) url.searchParams.set('keyword', keyword);
sectors.forEach((s) => url.searchParams.append('sectors', String(s)));
subregions.forEach((r) => url.searchParams.append('subregions', String(r)));
if (page) url.searchParams.set('page', String(page));
const res = await fetch(url.toString(), {
{
"message": "The region field must be at least 3 characters.",
"errors": {
"region": ["region is invalid for some reason."]
}
}
# 1) Health check
curl -s https://web-news-service.greenstreet.com/api/ping
# 2) Get regions (requires entitlements)
curl -s -H "Authorization: Bearer $TOKEN" \
https://web-news-service.greenstreet.com/api/regions
# 3) Get sectors (requires entitlements)
curl -s -H "Authorization: Bearer $TOKEN" \
https://web-news-service.greenstreet.com/api/sectors
{
"arguments": {
"filters": [
"filter_01", "filter_04"
]
},
"filters": {
"continents": [
{
"id": "filter_01",
@zeshanshani
zeshanshani / gravityforms-create-coupon-example.php
Created November 18, 2022 21:25
This function allows you to programatically create GravityForms coupon.
<?php
function zawp_create_coupon_codes() {
if ( isset( $_GET['create_coupons'] ) ) {
$coupons = array(
array(
'coupon_name' => 'Agnieszka K - OCC - SML client code 100€ OFF',
'coupon_code' => 'AgnieszkaK100',
'amount' => '100',
'type' => 'flat',
jQuery(document).ready(function($) {
$(document).on('keyup', function(e) {
if ( $('.lightbox').is(':visible') ) {
if ( e.which === 37 ) {
$('.gallery_prev').trigger('click');
} else if ( e.which === 39 ) {
$('.gallery_next').trigger('click');
}
}
})
@zeshanshani
zeshanshani / url-functions.js
Last active August 18, 2021 14:36
These functions include inserting a URL parameter, getting value from a URL parameter, and parsing query string
/**
* Insert Parameter in URL
*
* Dynamically insert or update a parameter in the URL.
*
* @param {string} key parameter name
* @param {string} value parameter value
* @param {string} base set a custom URL base.
* @param {boolean} historyUpdate defines if it update the URL without reloading the page
*/
<?php
/**
* Convert String to ID
*
* @param string $string
* @return string
*/
function zawp_convert_to_id( $string ) {
// Lower case everything
@zeshanshani
zeshanshani / side-popup.html
Created March 9, 2020 17:29
Side Popup that hides on scroll as you past down the #section-1 or whatever offset element you set.
<div class="side-popup">
<div class="side-popup__inner aos-init aos-animate" data-aos="fade-left" data-aos-easing="ease-out" data-aos-duration="1000" data-aos-delay="500">
<h4>Some Heading Goes Here</h4>
<a href="#" class="side-popup__cta button button--primary" target="">CTA Button Text</a>
</div>
</div>