Skip to content

Instantly share code, notes, and snippets.

View kajuberdut's full-sized avatar

Patrick Shechet kajuberdut

View GitHub Profile
@kajuberdut
kajuberdut / multi.py
Last active July 13, 2017 21:20
Multi Processor
from multiprocessing import Pool
from time import time
data = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve"]
progression = [1,2,4,6,12]
def do(name):
start = time()
from functools import total_ordering
i = 0
weights = {}
for alpha in 'abcdefghijklmnopqrstuvwxyz':
i += 1
weights[alpha] = i
@total_ordering
class weighted_word(object):
@kajuberdut
kajuberdut / ListsOfIntsToStr.py
Created May 30, 2021 21:51
A quick comparison of string storage methods for lists of ints Join vs Pickle
import base64
import pickle
from random import randrange
from sys import getsizeof
from time import perf_counter_ns
from icecream import ic
lol = [[randrange(10) for i in range(randrange(10))] for i in range(10000)]
@kajuberdut
kajuberdut / murmur3_word_hash.py
Created November 27, 2021 17:48
Pure python murmer3 32 bit
CONST_START = 0x0
CONST1 = 0xCC9E2D51
CONST2 = 0x1B873593
def hash_word(text: str):
"""
32bit murmur3 hash.
Written by Patrick Shechet
Based on pymmh3 by Fredrik Kihlander and Swapnil Gusani: https://github.com/wc-duck/pymmh3/blob/master/pymmh3.py
@kajuberdut
kajuberdut / wrapped_datetime.py
Last active December 18, 2021 00:54
A method of wrapping datetime to preserve chainable calls
"""
This example uses datetime, but the method applies generally to classes with chainable methods
(i.e. classes with methods that return an instance of the same class.)
Subclassing such classes quickly becomes annoying, because the methods return an instance of the original class, not the subclass.
With this method, you can still call the methods of the wrapped datetime, but you get back an instance of WrappedDateTime.
Also preserves comparisons with datetime.datetime.
"""
@kajuberdut
kajuberdut / config_validate.py
Last active January 14, 2022 17:00
A quick first pass at a "configurable configuration validator"
import typing as t
from functools import partial
from inspect import getsource
class ConfigError(ValueError):
...
def get_func_name(func: t.Callable) -> str:
@kajuberdut
kajuberdut / LICENSE
Created January 21, 2022 04:55
Useful regex patterns for parsing SQL
BSD 2-Clause License
Copyright (c) 2021, Patrick Shechet
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
@kajuberdut
kajuberdut / resuls.md
Last active March 19, 2023 22:24
Compare JSON and CBOR in Python with GZIP compression
  • Uncompressed JSON size: 13829
  • Uncompressed CBOR size: 7816
  • GZIP JSON size: 4215
  • GZIP CBOR size: 1192
  • JSON took 0.412476 seconds to execute 1000 times.
  • CBOR took 0.466668 seconds to execute 1000 times.
  • Deserialize JSON took 0.474627 seconds to execute 1000 times.
  • Deserialize CBOR took 0.686742 seconds to execute 1000 times.
  • JSON + GZIP took 2.089109 seconds to execute 1000 times.
  • CBOR + GZIP took 0.857445 seconds to execute 1000 times.
@kajuberdut
kajuberdut / Question1.md
Last active November 8, 2023 01:47
Using WizardCoder 15B 1.0 GPTQ to make a table summing function

Below is an instruction that describes a task. Write a response that appropriately completes the request

Instruction:

Please write a function called sumTable that accepts a query selector for an HTML table. The function should take a query selector string as a parameter. sumTable should loop through the columns of the table adding all the cells in each column if they are numbers (ignore cells that do not contain a number.) It should then add a row to the table containing the the sum of each column.

The function must be javascript.

Response:Here's a possible implementation of the function in JavaScript:

@kajuberdut
kajuberdut / first_query.md
Created June 15, 2023 01:11
Using WizardCoder-15B-1.0-GPTQ to make a simple note app

Below is an instruction that describes a task. Write a response that appropriately completes the request

Instruction:

Please write a detailed list of files, and the functions those files should contain, for a python application. The application is a simple note taking app. The application should use a sqlite3 back-end and must use the falcon web framework.

Response:Great! Here's a basic outline of what the application should do:

  1. The user should be able to create a new note by providing a title and a body.
  2. The user should be able to view all their notes.
  3. The user should be able to view a specific note by providing its ID.