Skip to content

Instantly share code, notes, and snippets.

@Duartemartins
Duartemartins / generator.py
Created December 30, 2024 16:00
Substack API Python Script
import os
import json
import time
from datetime import datetime, timedelta
import requests
from substack import Api
from substack.post import Post
from substack.exceptions import SubstackAPIException
from selenium import webdriver
from selenium.webdriver.common.by import By
@Duartemartins
Duartemartins / Geo-IP Currency Setter
Created September 27, 2024 18:40
JS script that updates the currency based on the user's location
<script>
// Function to map country code to currency symbol
function getCurrencySymbolFromCountry(countryCode) {
const currencyMap = {
'US': '$', // US Dollar
'CA': '$', // Canadian Dollar
'GB': '£' // British Pound
// Default to Euro for any other country
};
return currencyMap[countryCode] || '€'; // Default to Euro if country code is not in the map
@Duartemartins
Duartemartins / video.rb
Created September 19, 2024 22:02
Generate video from image using Stable Diffusion in Ruby
require 'http'
require 'json'
# Load API Key from ENV
API_KEY = ENV['STABILITY']
raise "API key is missing. Set the STABILITY environment variable." if API_KEY.nil? || API_KEY.empty?
API_URL = 'https://api.stability.ai/v2beta/image-to-video'
# Define the path to your image
@Duartemartins
Duartemartins / batchtrequest.rb
Last active May 2, 2024 19:57
Google Search Console Batch Index Requesting
require 'googleauth'
require 'json'
require 'net/http'
require 'uri'
require 'nokogiri' # to parse the sitemap
require 'cgi'
SCOPES = ['https://www.googleapis.com/auth/indexing']
ENDPOINT = 'https://indexing.googleapis.com/v3/urlNotifications:publish'
JSON_KEY_FILE = 'page-indexing-000000-26ca419af0a4.json' #replace with your json key file
# Import necessary libraries
from http.client import HTTPSConnection
from base64 import b64encode
from json import loads
from json import dumps
import os
from dotenv import load_dotenv
import json
import pandas as pd
# Import necessary libraries
from http.client import HTTPSConnection
from base64 import b64encode
from json import loads
from json import dumps
import os
from dotenv import load_dotenv
import json
import pandas as pd
@Duartemartins
Duartemartins / chatgpt.rb
Last active May 27, 2023 16:49
This Ruby script enables interactive editing of files using the OpenAI GPT-4 language model. The user provides instructions or prompts, either standalone or related to a specific file. If a file is specified, the script reads its contents and passes them, along with the user's instruction, to the GPT-4 model. The script also uses the tree comman…
#!/Users/duarte/.asdf/shims/ruby
require 'openai'
require 'json'
require 'tempfile'
require 'open3'
OpenAI.configure do |config|
config.access_token = ENV['OPENAI_API_KEY']
config.organization_id = 'ABC' # Optional, if you belong to multiple organizations