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 / 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|
{
@marckohlbrugge
marckohlbrugge / good_job_throttle_extension.rb
Created February 29, 2024 09:07
Attempt at adding throttling to Good Job (work in progress)
module GoodJobThrottleExtension
extend ActiveSupport::Concern
GoodJobThrottleExceededError = Class.new(GoodJob::ActiveJobExtensions::Concurrency::ConcurrencyExceededError)
included do
include GoodJob::ActiveJobExtensions::Concurrency
class_attribute :throttle_enabled, default: false
class_attribute :throttle_count, default: 2
@marckohlbrugge
marckohlbrugge / rss.php
Last active November 5, 2022 08:27
Use WIP's GraphQL API to create an RSS feed of your completed todos
<?php
$username = isset($_GET['username']) ? $_GET['username'] : 'marcano';
function graphql_query($endpoint, $query, $variables = [], $token = null) {
$headers = ['Content-Type: application/json', 'User-Agent: Minimal GraphQL client'];
if (null !== $token) {
$headers[] = "Authorization: bearer $token";
}