Skip to content

Instantly share code, notes, and snippets.

View ivorpad's full-sized avatar
🇪🇸
Working from Spain

Ivor ivorpad

🇪🇸
Working from Spain
View GitHub Profile
@ivorpad
ivorpad / index.js
Created September 19, 2024 22:04
Download m3u8 files
const ffmpeg = require('fluent-ffmpeg');
const path = require('path');
const m3u8Url = 'https://stream.mux.com/playback_id.m3u8';
const outputPath = path.join(__dirname, 'output.mp4');
ffmpeg(m3u8Url)
.outputOptions([
'-c copy',
@ivorpad
ivorpad / xero_oauth.sh
Created July 25, 2024 16:48
This script is a Bash utility for managing OAuth 2.0 authentication with the Xero API.
#!/bin/bash
source ./send_email.sh
# OAuth 2.0 configuration
CLIENT_ID=""
CLIENT_SECRET=""
REDIRECT_URI="http://localhost:3000/api/xoauth/callback"
AUTH_URL="https://login.xero.com/identity/connect/authorize"
TOKEN_URL="https://identity.xero.com/connect/token"
# config/initializers/method_source_locator.rb
# Utility to find the source location of a method based on its receiver and name
def source_location(receiver, method_name)
method_object = if receiver.singleton_class.method_defined?(method_name) || receiver.singleton_class.private_method_defined?(method_name)
# Class method
receiver.method(method_name)
elsif receiver.method_defined?(method_name) || receiver.private_method_defined?(method_name)
# Instance method
receiver.instance_method(method_name)
@ivorpad
ivorpad / .js
Created July 18, 2023 07:05
Convert AWS IAM credentials to AWS SMTP credentials
const crypto = require("crypto");
const secretAccessKey = ""; // AWS_ACCESS_KEY_SECRET
const regionName = "us-east-1";
// Assuming you've already set up your SES Policy on your IAM User:
// {
// "Version": "2012-10-17",
// "Statement": [
// {
@ivorpad
ivorpad / .sql
Created June 20, 2023 07:53
Database Introspection
-- Generates multiple CREATE TABLE statements (without INDEXES)
SELECT string_agg(create_table_stmt, E'\n\n' ORDER BY tablename)
FROM (
SELECT
tablename,
'CREATE TABLE ' || tablename || ' (' || column_defs || ');' as create_table_stmt
FROM (
SELECT
@ivorpad
ivorpad / mitmproxy.md
Created May 8, 2023 15:35
Testing an API Replacement with mitmproxy and Chrome

Redirect API calls from a live URL to localhost when path signatures are different

Introduction

When developing a new version of an API that's meant to replace an existing one, you may need to test the new API using the live URL to ensure proper functionality. However, if the path signatures of the new API are different from the existing one, using /etc/hosts to redirect the calls won't be sufficient. In this article, we will demonstrate how to use mitmproxy to redirect API calls from the live URL to your localhost, allowing you to test the new API with different path signatures.

Prerequisites

Before we begin, make sure you have the following software installed:

#!/usr/bin/env bash
# wait for a program to start listening on a PORT ($1)
wait_for_port() {
local PORT=$1
echo "waiting for $PORT"
for i in `seq 1 60`;
do
nc -z localhost $PORT && echo "port $PORT is ready" && return
echo -n .
@ivorpad
ivorpad / scheduler.rb
Created August 31, 2022 11:05
Start Job in sidekiq-scheduler dynamically
Sidekiq.schedule = {"hello_world"=>{"dynamic"=>true, "cron"=>"* * * * * *", "class"=>"HelloJob", "enabled"=>false}}
Sidekiq::Scheduler.enabled = true
Sidekiq::Scheduler.reload_schedule!
# or
SidekiqScheduler::RedisManager.get_job_state("hello_world") # "{\"enabled\":false}"
state = {"enabled" => true}
SidekiqScheduler::RedisManager.set_job_state("hello_world", state)
@ivorpad
ivorpad / .sh
Created April 8, 2021 21:34
Install Node with n in Apple Silicon
n --arch x64 10.16.0
@ivorpad
ivorpad / machine.js
Created April 1, 2021 14:41
Generated by XState Viz: https://xstate.js.org/viz
let count = 0;
const functionThatCanFail = async () => {
const urls = [
`https://api.github.com/users/mojombo`,
`https://api.github.com/users/ivorpad`,
`https://api.github.com/users/failtofetch`,
`https://api.github.com/users/davidkpiano`
];
const user = await fetch(urls[count]);