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
#!/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]);
@ivorpad
ivorpad / machine.js
Created April 1, 2021 11:44
Generated by XState Viz: https://xstate.js.org/viz
const functionThatCanFail = async () => {
const urls = [
`https://api.github.com/users/failtofetch`,
`https://api.github.com/users/mojombo`
];
return await fetch(urls[Math.floor(Math.random() * 2)]);
};
const healthCheck = () => {
return new Promise((resolve, reject) => {
@ivorpad
ivorpad / machine.js
Created January 28, 2021 05:54
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
[2021-01-05 22:55:29] waiting for changes...
src/http/any-catchall/index.ts:1:35 - error TS2307: Cannot find module '@architect/shared/architect-types' or its corresponding type declarations.
1 import { Request, Response } from "@architect/shared/architect-types";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/http/any-catchall/index.ts:2:21 - error TS2307: Cannot find module '@architect/shared/utils' or its corresponding type declarations.
2 import { log } from "@architect/shared/utils";
~~~~~~~~~~~~~~~~~~~~~~~~~
@ivorpad
ivorpad / setup-gh-cli-auth-2fa.md
Created December 3, 2020 22:08 — forked from ateucher/setup-gh-cli-auth-2fa.md
Setup git on the CLI to use 2FA with GitHub

These are instructions for setting up git to authenticate with GitHub when you have 2-factor authentication set up. This authentication should be inherited by any GUI client you are using. These are intentionally brief instructions, with links to more detail in the appropriate places.

  1. Download and install the git command-line client (if required).

  2. Open the git bash window and introduce yourself to git (if required):

    git config --global user.name 'Firstname Lastname'
    git config --global user.email '[email protected]'
    
const { Telegraf } = require("telegraf");
const bot = new Telegraf(process.env.TELEGRAM_BOT_KEY);
bot.start((ctx) => ctx.reply('Welcome!'))
bot.launch()
export default (req, res) => {
if (req.method === "POST") {
const message = `Hey ${req.body.text} — a message from slack at ${
req.body.channel_name === "directmessage"
@ivorpad
ivorpad / .sql
Last active October 16, 2020 11:43
jsonb_path_query @ PostgreSQL 12
SELECT
jsonb_path_query(tracker_events::jsonb, '$.result[*] ? (@.status == "delivered").tracking_details') as events
FROM orders WHERE store_host='store-name.myshopify.com';