Skip to content

Instantly share code, notes, and snippets.

@fogmoon
fogmoon / readExcel.py
Created August 6, 2024 04:23 — forked from armaandhir/readExcel.py
Reading data from excel using openpyxl
#
# I hate the documentation of openpyxl and it took me a while to undertand their stuff. So I decided to write down this code.
# Has some wrapper functions that reads all rows from the excel sheet and also a function to read a particular row.
# Add some code to the functions if you wish to do something on fly like adding values to list and sorting them later.
#
# Date: 28/09/2015
from openpyxl import load_workbook
# Reads all rows
@fogmoon
fogmoon / generate_blocks.sh
Created July 3, 2023 16:38 — forked from System-Glitch/generate_blocks.sh
Tutorial for bitcoin regtest
# Script to generate a new block every minute
# Put this script at the root of your unpacked folder
#!/bin/bash
echo "Generating a block every minute. Press [CTRL+C] to stop.."
address=`./bin/bitcoin-cli getnewaddress`
while :
do
@fogmoon
fogmoon / easy-bitcoin-address-from-public-key.py
Created June 27, 2023 21:29 — forked from circulosmeos/easy-bitcoin-address-from-public-key.py
Easily generate the bitcoin address from the public key using Python (compatible with Python 2 and 3)
#!/usr/bin/env python
# https://en.bitcoin.it/wiki/Protocol_documentation#Addresses
import hashlib
import base58
# ECDSA bitcoin Public Key
pubkey = '0450863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b23522cd470243453a299fa9e77237716103abc11a1df38855ed6f2ee187e9c582ba6'
# See 'compressed form' at https://en.bitcoin.it/wiki/Protocol_documentation#Signatures
compress_pubkey = False
@fogmoon
fogmoon / gen.py
Created June 27, 2023 20:36 — forked from matthewdowney/gen.py
P2WPKH-P2SH (SegWit) Wallet Address Generation
"""
Implementation of "Pay to Witness Public Key Hash nested in BIP16 Pay to Script Hash" (P2WPKH-P2SH) address generation.
Described in BIP 141 (SegWit) https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#P2WPKH_nested_in_BIP16_P2SH
I.e.: Public key -> SegWit address
"""
import hashlib
from hashlib import sha256
@fogmoon
fogmoon / easy-litecoin-address-from-public-key.py
Created June 18, 2023 16:11 — forked from circulosmeos/easy-litecoin-address-from-public-key.py
Easily generate the litecoin address from the public key using Python (compatible with Python 2 and 3)
#!/usr/bin/env python
# patched from https://bitcoin.stackexchange.com/questions/56923/is-this-how-to-generate-a-bitcoin-address-with-python
# https://en.bitcoin.it/wiki/Protocol_documentation#Addresses
# Adapted to litecoin, following https://bitcoin.stackexchange.com/questions/65282/how-is-a-litecoin-address-generated
import hashlib
import base58
# ECDSA bitcoin Public Key
pubkey = '0450863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b23522cd470243453a299fa9e77237716103abc11a1df38855ed6f2ee187e9c582ba6'
@fogmoon
fogmoon / HttpProxy.go
Created April 19, 2023 14:51 — forked from yowu/HttpProxy.go
A simple HTTP proxy by Golang
package main
import (
"flag"
"io"
"log"
"net"
"net/http"
"strings"
)
@fogmoon
fogmoon / cloudflare-workers-apilityio.js
Created April 19, 2023 12:20 — forked from diegoparrilla/cloudflare-workers-apilityio.js
Using Cloudflare Workers and https://Apility.io API add to the request headers information of the blacklists of abusers that contains the IP address of the client.
addEventListener('fetch', event => {
event.respondWith(fetchAndCheckOrigin(event.request))
})
async function fetchAndCheckOrigin(req) {
try {
startTime = new Date();
const body = await req.body;
const ip = req.headers.get('cf-connecting-ip');
const es = req.headers.get('cf-ipcountry');
@fogmoon
fogmoon / jwt-expiration.md
Created March 27, 2023 15:43 — forked from soulmachine/jwt-expiration.md
How to deal with JWT expiration?

First of all, please note that token expiration and revoking are two different things.

  1. Expiration only happens for web apps, not for native mobile apps, because native apps never expire.
  2. Revoking only happens when (1) uses click the logout button on the website or native Apps;(2) users reset their passwords; (3) users revoke their tokens explicitly in the administration panel.

1. How to hadle JWT expiration

A JWT token that never expires is dangerous if the token is stolen then someone can always access the user's data.

Quoted from JWT RFC:

@fogmoon
fogmoon / memcache.md
Created November 20, 2022 16:53 — forked from ashikawa/memcache.md
コンソールで memcache と戦う方法
@fogmoon
fogmoon / memcached.txt
Created November 20, 2022 16:24 — forked from xeoncross/memcached.txt
description of memcached stats
watch "echo stats | nc 127.0.0.1 11211"
accepting_conns The Memcached server is currently accepting new connections.
auth_cmds Number of authentication commands processed by the server - if you use authentication within your installation. The default is IP (routing) level security which speeds up the actual Memcached usage by removing the authentication requirement.
auth_errors Number of failed authentication tries of clients.
bytes Number of bytes currently used for caching items, this server currently uses ~6 MB of it's maximum allowed (limit_maxbytes) 1 GB cache size.
bytes_read Total number of bytes received from the network by this server.
bytes_written Total number of bytes send to the network by this server.