Skip to content

Instantly share code, notes, and snippets.

@umairsd
umairsd / list-ops.py
Created February 24, 2023 20:45
Experiment with Python Type Annotations.
# Learned about Python type annotations.
from typing import Callable
from typing import Any
from typing import TypeVar
T = TypeVar('T')
S = TypeVar('S')
U = TypeVar('U')
@umairsd
umairsd / Big List of Real Estate APIs.md
Created April 21, 2019 23:05 — forked from patpohler/Big List of Real Estate APIs.md
Evolving list of Real Estate APIs by Category

Big List of Real Estate APIs

Listings / Property Data

####Rets Rabbit http://www.retsrabbit.com

Rets Rabbit removes the nightmare of importing thousands of real estate listings and photos from RETS or ListHub and gives you an easy to use import and Web API server so you can focus on building your listing search powered website or app.

@umairsd
umairsd / PythonSetup.md
Last active February 3, 2019 16:15
Commands and tricks about Python.

Virtual Environments

Creating a virtual environment (by default, this will not include any of existing site packages):

# Python 3.6 and above
$ python3 -m venv ~/.virtualenv/<env-name>

In order to use this environment’s packages/resources in isolation, you need to “activate” it. To do this, just run the following:

@umairsd
umairsd / RegEx-Dates
Created May 7, 2017 19:23
RegEx-Dates
\w{3}\s\d+,\s\d{4}
Matches both "May 15, 1980", and "May 5, 1980"
@umairsd
umairsd / parse-read-books.py
Created November 26, 2016 19:44
Mini-script to parse my read-books file
with open('books.txt') as f_old, open('newbook.txt', 'w+') as f_new:
for line in f_old:
if "[" in line and "]" in line:
# Process the line only if it has the "[" and "]" characters
book_name, sep1, old_date_str = line.partition("[")
_, _, book_name = book_name.partition("-")
month, _, tmp = old_date_str.partition("/")
day, _, tmp = tmp.partition("/")
year, _, _ = tmp.partition("]")
@umairsd
umairsd / program.js
Last active January 6, 2016 17:14
Solution to Juggling Async problem (Learn You the Node.js)
// Note: Does not use any external node.js packages.
// *** Exercise 9: JUGGLING ASYNC
var http = require('http');
var count = 3;
var urls = process.argv.slice(2);
var results = [];
function httpGet(index)
@umairsd
umairsd / huffman.hs
Created October 7, 2015 23:03
Huffman Codes - Creates a Huffman Tree from passed in array of (key, probability) pairs, and then generates all the codes by iterating over the tree (P50 in 99 Haskell Problems)
-- Problem 50, 99 Haskell Problems (https://wiki.haskell.org/99_questions/46_to_50)
{-# OPTIONS_GHC -Wall #-}
import Data.Ord(comparing)
import Data.List(sortBy)
huffman :: [(Char, Int)] -> [(Char, String)]
huffman = sortBy (comparing fst) . (serializeHTree . buildHTree . createHTreeList)
@umairsd
umairsd / miscellaneous.hs
Created October 3, 2015 13:01
General purpose Haskell functions
-- a function that's equivalent to the standard library's sequence function
myseq ms = foldr k ([[]]) ms
where k m m' = [x:xs | x <- m, xs <- m']
-- another variant of the sequence function, uses return [] instead of [[]]
myseq1 ms = foldr k (return []) ms
where k m m' = [x:xs | x <- m, xs <- m']
-- Miscellaneous arithmetic functions
-- Square roots using Newton's method
sqrtNewton :: (Floating a, Ord a) => a -> a
sqrtNewton n = head $ dropWhile (\g -> abs(n - g^2) > tolerance) $ iterate (newGuess n) 1
where
tolerance = 0.000001
newGuess :: Floating a => a -> a -> a
newGuess n oldGuess = (oldGuess + n / oldGuess) / 2
@umairsd
umairsd / pascal-triangle.hs
Last active August 29, 2015 14:24
Pascal's Triangle
-- Takes an array of integers, and adds pairs of numbers to create a new
-- array. For example, [1,2,3,4] changes to [(1+2), (2+3), (3+4)], resulting
-- in [3,5,7]
sumOfPairs :: [Integer] -> [Integer]
sumOfPairs [] = []
sumOfPairs (x:[]) = []
sumOfPairs (x:y:ys) = (x+y) : sumOfPairs (y:ys)
-- Given a row of Pascal's triangle, returns the next row