Skip to content

Instantly share code, notes, and snippets.

// https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Routes/#tag/Routes/operation/post-v3-routes
// This sample works with .net framework
private static async Task<Route> CreateRoute(string recipientAddress, string forwardAddress)
{
RestClientOptions options = new RestClientOptions(new Uri("https://api.mailgun.net/v3"));
options.Authenticator = new HttpBasicAuthenticator("api", ApiKey);
using (RestClient client = new RestClient(options))
{
//Url encoded format, example: https://example.com/api?priority=0&description=it%27s+a+new+route&expression=match_recipient%28%22user%40example.com%22%29&action=%5B%27forward%28%22forward%40example.com%22%29%27%5D
@warrenkc
warrenkc / example.py
Created November 14, 2024 08:58
Mailgun API Create Route
# Example from Mailgun: https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Routes/#tag/Routes/operation/post-v3-routes
import requests
url = "https://api.mailgun.net/v3/routes"
data = {
"priority": "0",
"description": "it's a new route",
"expression": "match_recipient('.*@gmail.com')",
"action[0]": "forward("http://myhost.com/messages/")"
@warrenkc
warrenkc / openai-api-json-format.cs
Created October 24, 2024 08:00
To turn on JSON mode with the Chat Completions or Assistants API you can set the response_format to { "type": "json_object" }.
Dictionary < string, string > responseFormat = new Dictionary < string, string > {
{
"type",
"json_object"
}
};
var payload = new {
model = "gpt-4o-mini",
messages = messages,
max_tokens = 300,
@warrenkc
warrenkc / sample.py
Created July 26, 2024 10:52
AWS Amazon Transcribe Python - Don't output partial results
async def handle_transcript_event(self, transcript_event: TranscriptEvent):
# This handler can be implemented to handle transcriptions as needed.
# Here's an example to get started.
results = transcript_event.transcript.results
for result in results:
if not result.is_partial:
for alt in result.alternatives:
print(alt.transcript)
@warrenkc
warrenkc / convert-celcius-to-fahrenheit.ps1
Last active April 2, 2023 01:01
Convert Celcius to Fahrenheit: Powershell Script
# Load WPF assemblies
Add-Type -AssemblyName PresentationFramework
# Define XAML code for the GUI
[xml]$xaml = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Celsius to Fahrenheit Converter" Height="250" Width="400">
<Grid>
<Label Content="Celsius:" HorizontalAlignment="Center" Margin="0,40,0,0" VerticalAlignment="Top" FontSize="16" FontWeight="SemiBold"/>
@warrenkc
warrenkc / SquareTokenTest.js
Created November 15, 2022 03:04
SquareTokenTest.js
const appId = 'sq0idp-yCB3jRpR0PbPfffcFBEVbA';
const locationId = 'LGB4QKD1ME9BE';
const username = 'xxxx';
const amount = '500';
const partyId = 'xx';
const winningBidderId = 'xxxx';
const auctionGroupId = 'xxxx';
async function initializeCard(payments) {
const card = await payments.card();
@warrenkc
warrenkc / square-create-payment-link.py
Created October 28, 2022 06:31
Create payment link for Square in Python
@warrenkc
warrenkc / fix-wol-bible reading.js
Last active November 29, 2022 01:47
Fix bible reading from https://wol.jw.org/id for text to speech in Indonesian
// For https://wol.jw.org/ms Bible reading in Edge browser using text to speech. This will allow the browser to read the text without the verse numbers being read.
// Add chapter to chapter number
var elements = document.querySelectorAll('.cl');
element = elements[0]
var chapterNumber = element.innerText.trim()
element.innerText = `Pasal ${chapterNumber}: `
// Turn off reference symbols.
elements = document.querySelectorAll('.toggle');
var uppy = new Uppy.Core({
autoProceed: true,
restrictions: {
allowedFileTypes: ['image/*']
},
onBeforeFileAdded: (currentFile, files) => {
// Change the file name to the last modified date. This file name doesn't arrive at the server upload handler.
const modifiedFile = {
...currentFile,
name: currentFile.data.lastModified + ".jpg"
@warrenkc
warrenkc / uptime.cs
Created June 24, 2022 09:33
Sample C# code for Uptime Robot Heartbeat Monitor
var client = new HttpClient();
// Heartbeat URL
const string url = "https://heartbeat.uptimerobot.com/YOUR CODE HERE";
// Get the response.
HttpResponseMessage response = await client.GetAsync(url);
Console.WriteLine(response.StatusCode);