Skip to content

Instantly share code, notes, and snippets.

View a-lakhanpal's full-sized avatar
🤓

Ankur Lakhanpal a-lakhanpal

🤓
View GitHub Profile
@zjuul
zjuul / sql_data_viz.sql
Last active April 10, 2025 02:48
Data visualisation in SQL
-- this query outputs a data visualisation to explore how many unique products people
-- see on your website, and the conversion rate
-- it uses Big Query SQL on a GA4Dataform events table - check https://github.com/superformlabs/ga4dataform-community
with products_per_user as (
SELECT
user_pseudo_id,
count( distinct if(event_name = 'view_item', i.item_name, NULL) ) as n_items_viewed,
max( if(event_name = 'purchase', 1, 0)) as purchaser
@dwsmart
dwsmart / same_day_previous_year.js
Created October 10, 2024 08:16
Get the same day of the week in a previous year
// get same day of the week in the last x years ago for specific date.
// Default is 1 year ago, and default date is today, takes account of leap year
function getPreviousYearSameDay(dateToStart = false, years = 1) {
const date = dateToStart ? new Date(dateToStart) : new Date();
const lastYear = new Date(date.getFullYear() - years, date.getMonth(), date.getDate());
const dayDiff = date.getDay() - lastYear.getDay();
return new Date(lastYear.setDate(date.getDate() + dayDiff));
}
console.log(getPreviousYearSameDay('2024-10-10', 1).toISOString()); // 2023-10-11T23:00:00.000Z
{
"version": 1,
"snippets": [
{
"version": 1,
"javascript": "const settings \u003d {\\r\\n chatGpt: {\\r\\n \\/\\/ replace with your ChatGPT API key created at https:\\/\\/platform.openai.com\\/api-keys\\r\\n apiKey: \\\u0027ENTER CHATGPT API KEY\\\u0027,\\r\\n\\r\\n \\/\\/ the OpenAI model to use\\r\\n model: \\\u0027gpt-4-turbo\\\u0027,\\r\\n },\\r\\n alsoAsked: {\\r\\n \\/\\/ replace with your AlsoAsked API key created at https:\\/\\/alsoasked.com\\/developer\\/keys\\r\\n apiKey:\\r\\n \\\u0027ENTER ALSOASKED API KEY\\\u0027,\\r\\n\\r\\n \\/\\/ the language to search in\\r\\n language: \\\u0027en\\\u0027,\\r\\n\\r\\n \\/\\/ the region to search in\\r\\n region: \\\u0027gb\\\u0027,\\r\\n\\r\\n \\/\\/ the depth of the search\\r\\n \\/\\/ 2 is the default and returns the smallest number of questions, and costs 1 credit\\r\\n \\/\\/ 3 is the maximum and returns the largest number of questions, but costs 4 credits\\r\\n depth: 2,\\r\\n\\r\\n
@elisalimli
elisalimli / amazon-data-extractor.yaml
Last active October 29, 2024 18:24
SAML - Amazon Data Extractor
# Try out now at https://beta.superagent.sh/workflows
workflows:
- superagent:
llm: gpt-4-turbo-preview
name: JSON Schema generator
prompt: |-
Convert natural language query to JSON schema
Examples:
Question: List all the products launching at https://www.producthunt.com/ today
@natzir
natzir / getPercentDiff.js
Last active March 20, 2025 15:15
getPercentDiff.js
javascript:(function()%7Bjavascript%3A!function()%7Bfunction%20e(e)%7Blet%20l%3De.querySelectorAll(%22tr%22)%2Cn%3Dl%5B1%5D%3Bif(!(n%26%26(n.querySelector(%22%3Anth-child(4)%20%3E%20span%20%3E%20span%20%3E%20span%22)%7C%7Cn.querySelector(%22%3Anth-child(7)%20%3E%20span%20%3E%20span%20%3E%20span%22))))for(let%20a%3D1%3Ba%3Cl.length%3Ba%2B%2B)%7Blet%20r%3Dl%5Ba%5D%3Br.cells%5B1%5D.getAttribute(%22data-numeric-value%22)%3Blet%20i%3Dr.cells%5B2%5D.getAttribute(%22data-numeric-value%22)%2Cc%3Dr.cells%5B3%5D.getAttribute(%22data-numeric-value%22)%3Br.cells%5B4%5D.getAttribute(%22data-numeric-value%22)%3Blet%20s%3Dr.cells%5B5%5D.getAttribute(%22data-numeric-value%22)%2Co%3Dr.cells%5B6%5D.getAttribute(%22data-numeric-value%22)%2Cd%3Di%2Cu%3Ds%2Cp%3Dt(c%2Cd)%2Ch%3Dt(o%2Cu)%2Cf%3Dr.querySelector(%22%3Anth-child(4)%20%3E%20span%20%3E%20span%22)%2Cm%3Dr.querySelector(%22%3Anth-child(7)%20%3E%20span%20%3E%20span%22)%2Cg%3Ddocument.createElement(%22span%22)%2C%24%3Ddocument.createElement(%22span%22)%3Bg.innerText%3D%60%20(
@neubig
neubig / dispatch_openai_requests.py
Last active February 19, 2024 17:55
A simple script to get results from the OpenAI Asynchronous API
# NOTE:
# You can find an updated, more robust and feature-rich implementation
# in Zeno Build
# - Zeno Build: https://github.com/zeno-ml/zeno-build/
# - Implementation: https://github.com/zeno-ml/zeno-build/blob/main/zeno_build/models/providers/openai_utils.py
import openai
import asyncio
from typing import Any
import advertools as adv
import pandas as pd
key = 'YOUR_GOOGLE_KEY'
brands = [
'nike',
'adidas',
'puma',
'asics',
@eliasdabbas
eliasdabbas / serp_heatmap.py
Last active February 2, 2024 22:58
Create a heatmap of SERPs, using a table with columns: "keyword", "rank", and "domain"
import plotly.graph_objects as go
import pandas as pd
def serp_heatmap(df, num_domains=10, select_domain=None):
df = df.rename(columns={'domain': 'displayLink',
'searchTerms': 'keyword'})
top_domains = df['displayLink'].value_counts()[:num_domains].index.tolist()
top_domains = df['displayLink'].value_counts()[:num_domains].index.tolist()
top_df = df[df['displayLink'].isin(top_domains) & df['displayLink'].ne('')]
# !pip install --upgrade transformers plotly pandas
import plotly.graph_objects as go
import pandas as pd
pd.options.display.max_columns = None
from transformers import pipeline
unmasker = pipeline('fill-mask', model='bert-base-uncased')
results = []
cars = ['mercedes', 'audi', 'bmw', 'volkswagen', 'ford', 'toyota',
@jonathanmooredigital
jonathanmooredigital / screaming-frog-lazy-loading-custom-extraction-config.txt
Last active December 8, 2024 10:57
Screaming Frog Lazy-Loading Custom Extraction Config
# TIPS
1) Remove the count function and paste into dev tools to test further
2) To spot additonal oportunities swap the img selector to video, iframe or wildcards
3) Render JS in SF to discover all images and spot differences
4) Spot check source to find different lazy loading libraries e.g. Lazysizes, JQuery Lazy, yall.js etc
# CAVEATS
1) Don't forget to check background CSS images
2) Other implimentaiton techniques may exist, adapt this approach to suit your needs e.g yall.js - lazy-bg-loaded