Skip to content

Instantly share code, notes, and snippets.

View alecbw's full-sized avatar

Alec Barrett-Wilsdon alecbw

View GitHub Profile
@alecbw
alecbw / Export_Wealthfront_Transactions_to_CSV.js
Created March 27, 2024 19:27
A snippet you can paste in the console after manually paginating through as many months of transaction data as you like to cleanly export it to CSV. The only alternative Wealthfront provides natively is per-month PDFs. Based heavily on Mike Bianco's work - mikebian.co/download-a-csv-of-wealthfront-financial-activity
rows = document.querySelectorAll('.tk-list-item-wrapper');
csvData = [];
rows.forEach(row => {
texts = Array.from(row.querySelectorAll('[data-toolkit-component="Text"]'))
.map(element => {
let text = element.textContent.trim();
// Check if text matches "completed DD/MM/YYYY" and extract the date
let match = text.match(/completed (\d{2}\/\d{2}\/\d{4})/);
return match ? `"${match[1]}"` : `"${text}"`; // Add quotes for CSV format
@alecbw
alecbw / SourceStack_Node_AF_Call.js
Created September 5, 2023 20:53
A POST API call to the SourceStack jobs endpoint to find up to 100 jobs in the United States or Canada that are related to Graphic Design or Logo Design and have a company_url associated with them
const axios = require('axios');
const data = {
"count_only": false,
"limit": 100,
"export": "caller", // returns JSON
"fields": ["job_name", "department", "hours", "seniority", "remote", "company_name", "company_url", "post_url_https", "board_url", "tags_matched", "tag_categories", "categories", "company_categories", "job_location", "city", "region", "country", "addresses", "comp_est", "comp_range", "language", "twitter_url", "linkedin_url", "github_url", "logo_url", "contact_url", "about_url", "author", "emails", "last_indexed", "job_published_at", "post_html", "company_description", "alexa_rank", "domcop_rank"],
"filters": [
{"field": "categories", "operator": "CONTAINS_ANY", "value": ["Graphic Design", "Logo Design"]},
{"field": "country", "operator": "IS_IN", "value": ['United States', 'Canada']},
import requests
import json
import os
## Option 1 - query the companies dataset, pull pre-aggregated data
response = requests.get(
"https://sourcestack-api.com/companies?url=Copy.ai&fields=open_job_names,open_job_tech_use",
headers={"X-API-KEY": os.environ["SOURCESTACK_KEY"]}
)
@alecbw
alecbw / move_rows.js
Created January 30, 2023 20:57
AppScript.js - Move one or more rows to a given starting row in Google Sheets
// Adds a menu on user opening the spreadsheet
function onOpen() {
options = [
{name:"Move Rows", functionName:"moveRows"},
];
SpreadsheetApp.getActiveSpreadsheet().addMenu("~ Tools ~ ", options);
}
function moveRows() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
@alecbw
alecbw / SourceStack API Call - PHP - Jobs Advanced Filtering.php
Created January 13, 2023 22:21
PHP implementation of calling the SourceStack API to pull active job posts, with several filter requirements applied
<?php
function fetch_jobs() {
$api_key = getenv("SOURCESTACK_KEY");
$data = array(
"export" => "caller",
"limit" => 100,
"fields" => ["post_url", "company_url", "job_name", "company_name", "job_location", "hours", "department", "seniority", "remote", "tags_matched", "tag_categories", "last_indexed", "post_html"],
"filters" => array(array("field" => "job_name", "operator" => "CONTAINS_ANY", "value" => ["SEO", "Content Market", "Digital Market"]))
);
$options = array(
@alecbw
alecbw / url_split.sql
Created January 11, 2023 17:46
Clean a column of urls with mixed HTTP/HTTPS and www. prefixes
WITH sample_data AS (
SELECT 'https://www.example.com' AS url
)
SELECT
CASE
WHEN split_part(split_part(url, '://', 1), 'www.', 1) = url THEN url
WHEN split_part(url, '://', 1) = url and split_part(url, 'www.', 1) != url THEN split_part(url, 'www.', 2)
WHEN split_part(url, '://', 1) != url and split_part(url, 'www.', 1) = url THEN split_part(url, '://', 2)
ELSE split_part(split_part(url, '://', 2), 'www.', 2)
END as result
@alecbw
alecbw / GSheetMoveRows.js
Created January 5, 2023 05:55
Largely created by GPT-3; tested in browser.
// Adds a menu on user opening the spreadsheet
function onOpen() {
options = [
{name:"Move Rows", functionName:"moveRows"},
];
SpreadsheetApp.getActiveSpreadsheet().addMenu("~ Tools ~ ", options);
}
function moveRows() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
@alecbw
alecbw / get_stripe_checkout_session.py
Created November 9, 2022 16:46
Simple function to lookup a Stripe checkout session by its ID
def get_stripe_checkout_session(checkout_session_id):
api_url = "https://api.stripe.com/v1/checkout/sessions/"
api_url += checkout_session_id
api_url += "?expand[]=line_items"
api_url += "&expand[]=customer"
api_url += "&expand[]=total_details.breakdown.discounts.discount"
api_url += "&expand[]=payment_intent.charges"
resp = requests.get(
api_url,
@alecbw
alecbw / appscript_amazon_autocomplete_api_minimal.js
Created October 21, 2022 05:46
Generate keywords with Amazon's Autocomplete API
// This allows us to add a custom menu to Google Sheets so users can trigger without diving into the code
function onOpen() {
options = [
{name:"Amazon Autocomplete Lookup", functionName:"query_amazon_autocomplete"},
];
SpreadsheetApp.getActiveSpreadsheet().addMenu("* Tools * ", options);
}
function query_amazon_autocomplete() {
var sheet = SpreadsheetApp.getActiveSheet()
@alecbw
alecbw / checkUser.sh
Last active September 11, 2022 18:31
Add to your bash_profile to quickly lookup a dynamo item by key and print two of the resulting fields
function checkUser() {
aws dynamodb get-item --table-name userTable --key '{"email": {"S": "'"$1"'"}}' | jq '.Item.field_1.S + " " + .Item.field_2_int.N'
}
# to use:
checkUser foo@bar.com