Skip to content

Instantly share code, notes, and snippets.

View marckohlbrugge's full-sized avatar
🏠
Working from home

Marc Köhlbrugge marckohlbrugge

🏠
Working from home
View GitHub Profile
@marckohlbrugge
marckohlbrugge / assistant.rb
Created January 12, 2025 22:56
Overview of my LLM-powered prototype. Very rough code.
# Add these gems to your Gemfile
gem "rails" # not strictly needed, but I use ActiveConcern, etc
gem "raix" # helpful gem to reduce code needed for function calling etc
gem "thor" # to make a CLI app (not needed if you make a web app)
gem "http" # my preferred gem to make API calls
# This is the main app (`app/models/ai_chat/cli.rb`)
module AIChat
class Cli
# Thor
@marckohlbrugge
marckohlbrugge / cli.rb
Created January 7, 2025 18:08
Example of implementing user confirmation with function calling in Raix
require "thor"
require "raix"
module AIChat
class Cli < Thor
desc "chat", "Start a chat session with AI"
def chat
client = Client.new(
user_interaction: -> (message, type: :prompt) {
case type
@marckohlbrugge
marckohlbrugge / bluesky.rb
Last active November 16, 2024 01:25
work in progress implementation of `omniauth-bluesky`
require 'omniauth-oauth2'
require 'openssl'
require 'jwt'
require 'securerandom'
module OmniAuth
module Strategies
class Bluesky < OmniAuth::Strategies::OAuth2
option :name, 'bluesky'
@marckohlbrugge
marckohlbrugge / x_analysis.rb
Created September 3, 2024 10:44
Calculate "followers per tweet", etc for a list of usernames – https://x.com/marckohlbrugge/status/1830919319573700786
require 'http'
require 'json'
require 'terminal-table'
users = [
{ username: "marckohlbrugge" }
]
# Fetch data for each user
export default {
async fetch(request, env, ctx) {
const url = new URL(request.url);
// Modify the request to point to the Google Tag Manager endpoint
url.hostname = env.GTM_HOST;
// Create a new headers object based on the original request headers
const modifiedHeaders = new Headers(request.headers);

WIP Streaks Scriptable Widget

Introduction

Welcome! This guide will help you add the WIP Streaks widget to your home screen using the Scriptable app. This widget shows your streak and how many hours you have left to complete a todo if you haven't completed any today yet.

Prerequisites

Before you begin, make sure you have:

// Replace with your API key from https://wip.co/my/api_keys
const API_KEY = "wip_sk_FOOBAR";
const API_URL = `https://api.wip.co/v1/users/me.json?api_key=${API_KEY}`;
// Function to fetch data from the API
async function fetchStreakData() {
if (API_KEY === "wip_sk_FOOBAR") {
let alert = new Alert();
alert.title = "API Key Missing";
alert.message = "Please replace the placeholder API key with your actual API key.";
@marckohlbrugge
marckohlbrugge / WIP_Streak.scriptable
Created June 1, 2024 13:38
Scriptable widget showing your streak. Make sure to set your own API key ( https://wip.co/my/api_keys )
{
"always_run_in_app" : false,
"icon" : {
"color" : "yellow",
"glyph" : "fire"
},
"name" : "WIP Streak",
"script" : "\/\/ Replace with your API key\nconst API_KEY = \"wip_sk_REPLACE_ME\";\nconst API_URL = `https:\/\/api.wip.co\/v1\/users\/me.json?api_key=${API_KEY}`;\n\n\/\/ Function to fetch data from the API\nasync function fetchStreakData() {\n let request = new Request(API_URL);\n let response = await request.loadJSON();\n return response;\n}\n\n\/\/ Function to calculate hours left until midnight in a given time zone\nfunction hoursLeftUntilMidnight(timeZone) {\n let now = new Date();\n let nowInUserTimeZone = new Date(now.toLocaleString(\"en-US\", { timeZone: timeZone }));\n let midnight = new Date(nowInUserTimeZone);\n midnight.setHours(24, 0, 0, 0); \/\/ Set to midnight\n\n let hoursLeft = (midnight - nowInUserTimeZone) \/ (1000 * 60 * 60); \/\/ Convert milliseconds to hours\n return hoursLeft.toFixed(0);\n}\n\n\/\/ Function to create a widget displaying the streak info\nasy
@marckohlbrugge
marckohlbrugge / changelog.php
Created June 1, 2024 09:43
Simple example of creating a changelog with the WIP API
<?php
// Get your API key here: https://wip.co/my/api_keys
$apiKey = 'wip_sk_FOOBAR';
$baseUrl = 'https://api.wip.co/v1';
$projectSlug = 'nomadlist';
// Get todos for the project with pagination
$limit = 10;
$startingAfter = isset($_GET['starting_after']) ? $_GET['starting_after'] : null;
@marckohlbrugge
marckohlbrugge / migrate_sidekiq_to_activejob.rb
Created March 7, 2024 11:34
Simple script to move scheduled Sidekiq jobs to Active Job. Not properly tested yet. Use at your own risk!
require "sidekiq/api"
# Fetch scheduled Sidekiq jobs for migration to GoodJob
def fetch_sidekiq_jobs_for_goodjob_migration
raise "Remove this line if you understand this code is not properly tested and you assume the risk of losing data"
puts "Starting to fetch scheduled Sidekiq jobs for migration..."
scheduled_set = Sidekiq::ScheduledSet.new
jobs = scheduled_set.map do |job|
{