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 / 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 =
jobs = do |job|
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 =
included do
include GoodJob::ActiveJobExtensions::Concurrency
class_attribute :throttle_enabled, default: false
class_attribute :throttle_count, default: 2
marckohlbrugge / rss.php
Last active November 5, 2022 08:27
Use WIP's GraphQL API to create an RSS feed of your completed todos
$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";
marckohlbrugge / migrate_redis.rb
Created October 9, 2022 10:36
Simple script to migrate all Redis keys from one server (REDIS_ORIGIN_URL) to another (REDIS_DESTINATION_URL)
# NOTE: Don't get your two Redis URLs mixed up or you'll lose data!
require "redis"
redis1 = ENV.fetch("REDIS_ORIGIN_URL"))
redis2 = ENV.fetch("REDIS_DESTINATION_URL"))
# NOTE: Uncomment this if you want to clear out all Sidekiq stats from the ORIGIN(!) server
# redis1.pipelined do |pipeline|
# redis1.keys("stat:processed:*").each do |key|
# Make sure you have a .env file with DISCORD_CLIENT_ID set
require "dotenv/load"
require "http"
puts "Go to the following URL in your browser to authorize this application:"
puts "{ENV.fetch("DISCORD_CLIENT_ID")}&"
puts ""
puts "Paste the URL you were redirected to after authorization:"
marckohlbrugge / bookmarklet.js
Last active December 31, 2019 12:43
Shows all tweets with 25+ retweets of Twitter profile you're currently looking at.
javascript:(function() // window.location = `${document.location.href.match(/\/([a-z0-9_]+)/i)[1]}%20min_retweets%3A25&src=typed_query`
marckohlbrugge /
Created October 30, 2019 21:07
Use to fix Hacker News styling
body { background-color: rgb(246, 246, 239); margin-top: 0 }
.title { font-size: 16px; padding-top: .6em; padding-bottom: .3em; }
.athing > .votelinks { padding-top: .8em }
.subtext { font-size: 12px; }
.comment { font-size: 16px; line-height: 1.5; }
marckohlbrugge / countdown.rb
Last active October 10, 2018 10:47
Calculates estimated time it takes for a block to return zero. Useful when running operations in parallel (e.g. migrations).
# Calculates estimated time it takes for a block to return zero. Useful when
# running operations in parallel (e.g. migrations).
# Usage:
# Run in IRB/Rake/whatever: add_slugs_to_each_post # example of long-running operations
# Run in parallel IRB session: countdown { Post.where(slug: nil).count }
# sleep_time parameter is optional. The higher the value the more accurate the
# results, but the longer the method takes to run.
marckohlbrugge / unread_only.js
Created May 3, 2018 11:42
Hides all read chats so you only see unread chats. Save this as a bookmarklet with and run on
$(".im_dialog_wrap").each(function(index, el){$(el).parents("li.im_dialog_wrap").addClass("ng-hide");});
marckohlbrugge / wip_graphql_demo.rb
Last active October 10, 2022 11:46
Ruby example of creating a todo and then completing it using graphql.
# NOTE: Be sure to set the API key further down in the code!
require "net/http"
require "uri"
require "json"
class WIP
def initialize(api_key:)
@api_key = api_key