Skip to content

Instantly share code, notes, and snippets.

@p-hash
p-hash / create_list.sh
Last active January 30, 2017 17:18
Create Mega Adblock Hostsfile for use with Dnsmasq (Modified from Pi-hole)
#!/bin/bash
# Modified Pi-hole script to generate a generic hosts file
# for use with dnsmasq's addn-hosts configuration
# original : https://github.com/jacobsalmela/pi-hole/blob/master/gravity-adv.sh
# Address to send ads to.
destinationIP="0.0.0.0"
outlist='./final_blocklist'
tempoutlist="$outlist.tmp"
@p-hash
p-hash / pager_buttons.py
Last active December 1, 2019 22:42
Inline Buttons for paging in Telegram.
from telebot.types import InlineKeyboardButton
def pager_buttons(prefix, page_no, pages_count, buttons_count=5, marks=None):
"""
Buttons for pagers.
Helper function for telebot library (https://github.com/eternnoir/pyTelegramBotAPI).
Creates a list of InlineKeyboardButtons like one in @music bot (https://t.me/music).
@p-hash
p-hash / short_oid.py
Last active April 3, 2017 21:16
ObjectId encoders: one-way shortener and two-way url-encoder
import bson
import base64
"""
Generate short id's from ObjectID's for use in url's or other applications.
Id's are generated from the timestamp and counter of the ObjectId, with some slight variation. They should be reasonably unique.
This is, unfortunately, a one-way function. It will reliably produce the same short id for the same ObjectId, but the operation can't be reversed (it is missing information about the machine id, process id, and most of the counter).
@p-hash
p-hash / bktree3.py
Created June 24, 2016 00:21
Fast Levenshtein distance and BK-tree implementations in Python 3.
"""
bktree3.py, by phash
Based on bktree.py by bearophile ( http://code.activestate.com/recipes/572156-bk-tree/ )
Fixed for python 3
Fast Levenshtein distance and BK-tree implementations in Python.
"""
def editDistance(s1, s2):
"""Computes the Levenshtein distance between two arrays (strings too).