Skip to content

Instantly share code, notes, and snippets.

@ehmo
ehmo / pipe.py
Last active August 20, 2021 23:25
from PIL import Image
import imagehash
import copy
import time
def change_pixel(img, pix, position, color):
if img.mode == '1':
value = int(color >= 127) # Black-and-white (1-bit)
elif img.mode == 'L':
with countries as (select * from (values(1, 'AF', 'AFGHANISTAN', 'Afghanistan', 'AFG', 4, 93),
(2, 'AL', 'ALBANIA', 'Albania', 'ALB', 8, 355),
(3, 'DZ', 'ALGERIA', 'Algeria', 'DZA', 12, 213),
(4, 'AS', 'AMERICAN SAMOA', 'American Samoa', 'ASM', 16, 1684),
(5, 'AD', 'ANDORRA', 'Andorra', 'AND', 20, 376),
(6, 'AO', 'ANGOLA', 'Angola', 'AGO', 24, 244),
(7, 'AI', 'ANGUILLA', 'Anguilla', 'AIA', 660, 1264),
(8, 'AQ', 'ANTARCTICA', 'Antarctica', NULL, NULL, 0),
(9, 'AG', 'ANTIGUA AND BARBUDA', 'Antigua and Barbuda', 'ATG', 28, 1268),
(10, 'AR', 'ARGENTINA', 'Argentina', 'ARG', 32, 54),
CREATE TEMP TABLE IF NOT EXISTS countries (
id bigint primary key,
iso text NOT NULL,
name text NOT NULL,
nicename text NOT NULL,
iso3 text DEFAULT NULL,
numcode int DEFAULT NULL,
phonecode int NOT NULL
);

Keybase proof

I hereby claim:

  • I am ehmo on github.
  • I am rasty (https://keybase.io/rasty) on keybase.
  • I have a public key whose fingerprint is 8CA4 FD95 DD41 76CA 777D 7C2E 0B0D 7059 1277 75B0

To claim this, I am signing this object:

CREATE OR REPLACE FUNCTION citus_run_on_3_colocated_placements(table_name1 regclass,
table_name2 regclass,
table_name3 regclass,
command text,
parallel bool default true,
OUT nodename text,
OUT nodeport int,
OUT shardid1 bigint,
OUT shardid2 bigint,
OUT shardid3 bigint,
// define constants for bytesize
type ByteSize float64
const (
_ = iota
KB ByteSize = 1 << (10 * iota)
MB
GB
TB
-- Super fast quasi fibonacci function for postgresql
-- Returns rounded big integer
CREATE OR REPLACE FUNCTION fib (
n integer
) RETURNS bigint AS $$
BEGIN
IF n > 91 THEN
RAISE EXCEPTION 'Bigint overflow past fib(91) [%]', n;
END IF;
@ehmo
ehmo / fibonacci.sql
Created August 11, 2016 01:19
Fast fibonacci function in pure SQL
# Fast fibonacci function in pure SQL
# Tested on Postgresql 9.5
CREATE OR REPLACE FUNCTION _fib (
n integer, a bigint, b bigint
) RETURNS bigint AS $$
BEGIN
IF n < 1 THEN
RETURN b;
END IF;
@ehmo
ehmo / test.py
Created March 30, 2016 15:00
Regex in lxml
script = webpage.xpath(
"//script[re:match(text(), 'params')]",
namespaces={
"re": "http://exslt.org/regular-expressions"
}
)[0].text
@ehmo
ehmo / base62.go
Last active August 29, 2015 14:22
Implementation of an URL shortener using base62 encoding in Go
package main
import (
"fmt"
"strings"
)
const alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
// Integer power: compute a**b using binary powering algorithm