Skip to content

Instantly share code, notes, and snippets.

View djinn's full-sized avatar

Supreet Sethi djinn

View GitHub Profile
@djinn
djinn / math_error.cpp
Created August 30, 2021 05:52
The tiny code to show some of the floating point errors.
#include <iostream>
#include <string>
#include <cinttypes> // for uint32_t
#include <cfenv>
#include <cmath>
std::string float_to_binary(float f) {
union {float f; uint32_t i;} u;
#!/usr/bin/env python3
# Copyright(C) 2020 Supreet Sethi <[email protected]>
# I do Hindi, Punjabi and Urdu in Python dude!
बोल = print
बोल("ਬੋਲ ਕੇ ਲਾਬ ਆਜ਼ਾਦ ਹੈਂ ਤੇਰੇ - فیض احمد فیض")
@djinn
djinn / document_processing.py
Created October 16, 2020 04:58
Parallel processing of CPU intensive blocking tasks leveraging available CPUs
#!/usr/bin/env python3
# Author: Supreet Sethi <[email protected]>
# Dated: 16/10/2020
# Please use it has working prototype
# Lot can be done from process management and general housekeeping perspective
from multiprocessing import Pool, cpu_count, Manager
from collections import namedtuple
@djinn
djinn / 01-movielens_aws_personalize_transform.py
Last active August 14, 2020 06:41
Movielens AWS Personalize Transform
import pandas, boto3
from sklearn.utils import shuffle
ratings = pandas.read_csv('ratings.csv')
ratings = shuffle(ratings)
ratings = ratings[ratings['rating']>3.6]
ratings = ratings.drop(columns='rating')
ratings.columns = ['USER_ID','ITEM_ID','TIMESTAMP']
ratings = ratings[:100000]
ratings.to_csv('ratings.processed.csv',index=False)
s3 = boto3.client('s3')
#!/usr/bin/env python3
from requests import get
from shutil import copyfileobj
from tempfile import NamedTemporaryFile as TemporaryFile
import time
from os import sendfile
import hashlib
import os.path
WIKIDUMPURL = 'https://dumps.wikimedia.org/enwikinews/20200701/enwikinews-20200701-pages-articles-multistream.xml.bz2'
@djinn
djinn / prime.c++
Created May 19, 2020 08:05
Implementation of Miller–Rabin primality test in C++ using parallelism constructs from C++ '17
// C++ program to print all primes smaller than or equal to
// n using Miller-Rabin Primality Test
// Reference: https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test
// It is not particularly to optimized
// since focus is readability
// Compile: g++ -std=c++17 -o prime prime.c++ -ltbb
#include <execution>
#include <iostream>
#include <math.h>
@djinn
djinn / map_relation.py
Created December 19, 2019 01:30
Graph edge lookup specifically implemented for relation lookup on phone numbers
from json import loads
from random import choice, randint, sample
import timeit
# With this model it is imperative to use integer form of phone number instead of string
# We will use median contact frequency distribution from customer data
# Maximum contacts: 14551
# Minmum: 233
@djinn
djinn / image-proxy.conf
Created November 21, 2019 02:27 — forked from tmaiaroto/image-proxy.conf
Nginx Image Filter Resize Proxy Service
# Feel free to change this path of course (and keys_zone value as well, but also change the usage of it below).
proxy_cache_path /var/www/cache/resized levels=1:2 keys_zone=resizedimages:10m max_size=1G;
# Gzip was on in another conf file of mine...You may need to uncomment the next line.
#gzip on;
gzip_disable msie6;
gzip_static on;
gzip_comp_level 4;
gzip_proxied any;
# Again, be careful that you aren't overwriting some other setting from another config's http {} section.
#!/usr/bin/env python3
# Supreet Sethi <[email protected]>
# Date: 21-05-2019
from subprocess import check_output
from collections import defaultdict, Counter
from requests import get
from bs4 import BeautifulSoup as Soup
from urllib.parse import urljoin, urlparse
#do whois
@djinn
djinn / django_deploy.md
Last active May 2, 2019 13:39 — forked from bradtraversy/django_deploy.md
Django Deployment - Digital Ocean

Django Deployment to Ubuntu 18.04

In this guide I will go through all the steps to create a VPS, secure it and deploy a Django application. This is a summarized document from this digital ocean doc

Any commands with "$" at the beginning run on your local machine and any "#" run when logged into the server

Create A Digital Ocean Droplet

Use this link and get $10 free. Just select the $5 plan unless this a production app.