Skip to content

Instantly share code, notes, and snippets.

View CalebMuhia's full-sized avatar

Muhia Njoroge CalebMuhia

  • Ovtygen Web Solutions
  • Nairobi
View GitHub Profile
@CalebMuhia
CalebMuhia / bank_test.py
Created June 13, 2022 17:44 — forked from mrcfps/bank_test.py
Exploration of how to test concurrency in Python
from __future__ import print_function
import platform
import sys
import threading
import time
class UnsyncedBankAccount(object):
"""Bank account with no synchronization lock, prone to race condition."""
@CalebMuhia
CalebMuhia / custom_elasticsearch.md
Created December 6, 2021 02:08 — forked from aolieman/custom_elasticsearch.md
Haystack provides an interface similar to Django's QuerySet, which instead enables easy querying in one or more popular search backends. Because the Haystack API is meant to hook up to several search backends, however, not all the functionality of the backends has been implemented in the API. In this post we show how Haystack's Elasticsearch bac…

Extending Haystack's Elasticsearch backend

Haystack provides an interface similar to Django's QuerySet, which instead enables easy querying in one or more popular search backends. Because the Haystack SearchQuerySet API is meant to hook up to several search backends, however, not all the functionality of the backends has been implemented in the API. In this article we show how Haystack's Elasticsearch backend can be extended with advanced querying functionality.

As an exemplary use case, we'll focus on implementing Elasticsearch's Nested Query in the SearchQuerySetAPI, to enable e.g. weighted tags on documents. The usage of this extended API will be shown first, after which we'll go through the necessary implementation steps.

ConfigurableSearchQuerySet API Usage

import search.custom_elasticsearch as ces
from files import FileObject
@CalebMuhia
CalebMuhia / example.md
Created June 3, 2021 17:24 — forked from sdnts/example.md
Postman pm.sendRequest example

To send a request via the sandbox, you can use pm.sendRequest.

pm.test("Status code is 200", function () {
    pm.sendRequest('https://postman-echo.com/get', function (err, res) {
        pm.expect(err).to.not.be.ok;
        pm.expect(res).to.have.property('code', 200);
        pm.expect(res).to.have.property('status', 'OK');
    });
});
^XA\n^FT22,43\n^A0N,,36\n^FDEXPRESS WORLDWIDE^FS\n^FT22,43\n^A0N,,36\n^FDEXPRESS WORLDWIDE^FS\n^FT69,70\n^A0N,,15\n^FD2020-03-02 XMLPI 6.2 / *90-1604*^FS\n^FO386,0\n^GB150,79,79,B^FS\n^FT388,58\n^A0N,,65\n^FR^FDWPX^FS\n^FO0,78\n^GB780,0,2,B^FS\n^FT19,102\n^A0N,,17\n^FDFrom :^FS\n^FT19,102\n^A0N,,17\n^FDFrom :^FS\n^FT87,102\n^A0N,,25\n^FDHarumio^FS\n^FT87,129\n^A0N,,25\n^FDHarumio Shipping^FS\n^FT87,156\n^A0N,,24\n^FD402, Yeonnam-dong 249-15, Mapo-gu^FS\n^FT87,182\n^A0N,,25\n^FD03979 Seoul^FS\n^FT87,209\n^A0N,,25\n^FDSouth Korea^FS\n^FT693,102\n^A0N,,22\n^FDOrigin:^FS\n^FT694,140\n^A0N,,41\n^FDSEL^FS\n^FT693,140\n^A0N,,41\n^FDSEL^FS\n^FO0,220\n^GB780,0,2,B^FS\n^FT35,252\n^A0N,,17\n^FDTo :^FS\n^FT35,252\n^A0N,,17\n^FDTo :^FS\n^FO25,226\n^GB0,31,5,B^FS\n^FO28,224\n^GB31,0,5,B^FS\n^FO750,226\n^GB0,31,5,B^FS\n^FO720,224\n^GB31,0,5,B^FS\n^FO25,409\n^GB0,31,5,B^FS\n^FO28,439\n^GB31,0,5,B^FS\n^FO750,409\n^GB0,31,5,B^FS\n^FO720,439\n^GB31,0,5,B^FS\n^FT87,249\n^A0N,,31\n^FDJiaxing Guo^FS\n^FT87,282\n^A0N,,31\n^FDJiaxin
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCpOevIq8wZhjEtggtf7kjDcL/v/rqkvNN1wMGv+HTgUCNoeVyUsc4KUk97UmNrlhe6xGP/vfpFfo2cOLtyuk5LIiFx+MMonf7HSBJRQM0dNtWu0hIidNoKPvZOcQnR0DMBjRxNkSXbbIQQiSpnWUS0QsRjux9/hBXRJASGHLTU5xVTJrdNnDFXzmUOMv81wLmXBJb+fI0Ryiyk5nEQ+Swgfu2qvjVA1TbUZj5SbQLwTHnVMHFF6eqkpQkaNcVPHnDHivfnQjcv+SGYL/VfgHMXorESXuBUXgeo+evbWZYLeZS3k1znC56wx/nXnF5pClGmUeA3aIsAsd4CfHLRlHVJTqKWGp6wpVFa6hk2TFfDZwYZBBSBPG1MlKfR6cJlyiIi/ya2cRRB6c8egVJC3llAlCHk/tvAT9//9iagPia+TBxBDGQfvNxKjCgDfbnl0HYjaxhMvYpDQDVNOyklQUOWEzlgdH6mHYsYE1jh1MtcIiGTxNC53l/myYvt9qadPF6BZ5lE2WFANMJ/acbq/TvixEtrkCzAjo7UaqXQBJQzQKVze/7LlpOW9h3f6RYcWwgJeJPTeFh531xkUs42hw9RFiBeyOvG1A+rWy/M0s2z7ywW/tw40E0wm+QoA3QnLQoa8fUQTbIg7YeJb9j0m8UNXzHXkIc5fQcIY5hdiOx+hQ== clbnjoroge@gmail.com
@CalebMuhia
CalebMuhia / post-server.py
Last active March 25, 2020 23:43 — forked from kylemcdonald/post-server.py
Python POST simple server
from http.server import HTTPServer, BaseHTTPRequestHandler
from io import BytesIO
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.end_headers()
@CalebMuhia
CalebMuhia / wget.md
Created March 11, 2019 10:57 — forked from simonw/wget.md
Recursive wget ignoring robots
$ wget -e robots=off -r -np 'http://example.com/folder/'
  • -e robots=off causes it to ignore robots.txt for that domain
  • -r makes it recursive
  • -np = no parents, so it doesn't follow links up to the parent folder
@CalebMuhia
CalebMuhia / .gitignore
Created February 10, 2018 03:45 — forked from kenjyco/01-Learning-Python3.md
Learn Python 3 with Jupyter Notebook
*.swp
.ipynb_checkpoints/
@CalebMuhia
CalebMuhia / pg_change_schema_owner.sh
Created December 5, 2017 10:02 — forked from bspkrs/pg_change_schema_owner.sh
Changes the owner on all tables, sequences, views, and functions in a PostgreSQL database with support for identifiers with whitespace and non-public schemas.
#!/bin/bash
usage()
{
cat << EOF
usage: $0 options
This script sets ownership for all tables, sequences, views, and functions for a given schema.
Run this script as your postgres OS user.
@CalebMuhia
CalebMuhia / simple_mlp_tensorflow.py
Created December 1, 2017 16:25 — forked from vinhkhuc/simple_mlp_tensorflow.py
Simple Feedforward Neural Network using TensorFlow
# Implementation of a simple MLP network with one hidden layer. Tested on the iris data set.
# Requires: numpy, sklearn>=0.18.1, tensorflow>=1.0
# NOTE: In order to make the code simple, we rewrite x * W_1 + b_1 = x' * W_1'
# where x' = [x | 1] and W_1' is the matrix W_1 appended with a new row with elements b_1's.
# Similarly, for h * W_2 + b_2
import tensorflow as tf
import numpy as np
from sklearn import datasets
from sklearn.model_selection import train_test_split