Skip to content

Instantly share code, notes, and snippets.

@juanpabloaj
juanpabloaj / main.py
Last active July 30, 2023 15:00
looking for job using Linkedin API
import os
import sqlite3
from linkedin_api import Linkedin
import logging
def extract_id(urn):
return urn.split(":")[-1]
@juanpabloaj
juanpabloaj / main.go
Created July 2, 2023 22:13
heartbeats example
// package main example of the book Concurrency in Go by Katherine Cox-Buday
// it includes the patterns: orChannel, orDone, take, and bridge.
// newSteward monitors a goroutine and restarts it if it stops sending heartbeats
package main
import (
"log"
"time"
)
@juanpabloaj
juanpabloaj / send_telegram_message.py
Last active March 26, 2023 13:26
python3 send telegram message
import os
import urllib.request
import urllib.parse
TELEGRAM_TOKEN = os.environ["TELEGRAM_TOKEN"]
TELEGRAM_CHANNEL_ID = os.environ["TELEGRAM_CHANNEL_ID"]
telegram_url = f"https://api.telegram.org/bot{TELEGRAM_TOKEN}/sendMessage"
telegram_url += f"?chat_id={TELEGRAM_CHANNEL_ID}"
@juanpabloaj
juanpabloaj / main.go
Created November 8, 2022 16:31
Channel example, channel as queue with discard of messages
// go playground
// https://go.dev/play/p/3HjtqJlbMnE
package main
import (
"log"
"time"
)
func main() {
@juanpabloaj
juanpabloaj / .gitignore
Last active August 14, 2022 14:53
download images with puppeteer
imgs
.DS_Store
node_modules
@juanpabloaj
juanpabloaj / gas_alert.sh
Last active January 7, 2024 14:59
ethereum gas telegram alert
#!/bin/bash
# get channel id
# https://api.telegram.org/bot<YourBOTToken>/getUpdates
# crontab
# */5 * * * bash /path/gas_alert.sh 2>&1 | logger -t gas_alert
cheapPrice="80"
url="https://api.etherscan.io/api?module=gastracker&action=gasoracle"
@juanpabloaj
juanpabloaj / ohlcbtc.sh
Last active December 9, 2021 12:19
OHLC BTC
# pip install ohlc; apt install jq
# with other token, ohlcbtc ETHUSDT
ohlcbtc () {
token=${1:-BTCUSDT}
while true;
do
ohlc --pab --ha -n <( curl "https://api.binance.com/api/v3/klines?symbol=${token}&interval=1h" 2>/dev/null | jq -r '.[][1:5]|join(" ")' )
sleep 3600
done
@juanpabloaj
juanpabloaj / pool_length.py
Created July 9, 2021 22:35
get pool length
from web3 import Web3
# https://web3py.readthedocs.io/en/stable/quickstart.html
# https://docs.matic.network/docs/develop/network-details/network/
w3 = Web3(Web3.HTTPProvider("https://rpc-mainnet.matic.network"))
print(w3.isConnected())
print(w3.eth.block_number)
@juanpabloaj
juanpabloaj / logs_with_color.exs
Created June 25, 2021 23:41
elixir, colorful log lines
require Logger
Logger.configure_backend(:console, format: "$time $metadata[$level] $levelpad$message\n")
# more colores in
# https://hexdocs.pm/elixir/1.12/IO.ANSI.html
Logger.info("colorful log line", ansi_color: :black)
Logger.info("colorful log line", ansi_color: :blue)
Logger.info("colorful log line", ansi_color: :cyan)
@juanpabloaj
juanpabloaj / docker_clean_old.service
Created June 1, 2021 23:20
delete old containers
# /etc/systemd/system/docker_clean_old.service
[Unit]
Description=delete old containers
[Service]
CPUQuota=20%
TimeoutSec=3600
ExecStart=/bin/bash /root/opt/bin/docker_clean_old