Skip to content

Instantly share code, notes, and snippets.

View chankeypathak's full-sized avatar
Commit all day, everyday!

Chankey Pathak chankeypathak

Commit all day, everyday!
View GitHub Profile
@chankeypathak
chankeypathak / haversine.py
Created August 5, 2020 11:32
Distance between points
import csv
import pathlib
from math import radians, sin, cos, sqrt, asin
from functools import partial
MI= 3959
NM= 3440
KM= 6373
def haversine( lat_1: float, lon_1: float,
@chankeypathak
chankeypathak / meta-reset.md
Created April 6, 2020 14:42
Metabolism Reset Diet
  • Keywords: #books #food #diet

  • Liver is the boss

  • Coined from the term "life"

  • Unhealthy liver

    • Stores fuel as fat, cannot burn it
    • Restrains nutrients that are required to burn fat
    • No matter what diet you choose, how hard you try, weight loss is impossible
  • Metabolism Reset Diet

@chankeypathak
chankeypathak / ikigai.md
Last active April 5, 2020 15:41
Ikigai, Japanese secret of long and happy life
  • Keywords: #books #mentalhealth #life

  • Age limit: 120 (cell regeneration stops)

  • 5 Blue Zones in the World (the geographic regions where people live longest)

  • There's no word that means "retire" in Japanese

  • Diet, exercise, finding a purpose in life, forming strong social ties

  • 1800-1900 calories per day (eat only 80%)

  • The secrets to slowing down aging process

@chankeypathak
chankeypathak / chat_client.pl
Last active August 24, 2018 14:36
Simple chat client in Perl
#!/usr/bin/perl -w
# chat_client.pl
use strict;
use IO::Socket::INET;
my $port = shift or die "No port\n";
my $server = shift or die "No server\n";
my $client_socket = IO::Socket::INET->new(
PeerPort => $port,
PeerAddr => $server,
@chankeypathak
chankeypathak / chat_server.pl
Created September 23, 2015 05:03
Simple chat server in perl
#!/usr/bin/perl -w
# chat_server.pl
use strict;
use IO::Socket::INET;
my $port = shift or die "Port required!\n";
my $socket = IO::Socket::INET->new(
LocalPort => $port,
Proto => 'tcp',
Listen => SOMAXCONN
@chankeypathak
chankeypathak / list_files_using_threads.py
Created November 15, 2017 10:28
Threading example in Python
import os, time
import threading, Queue
class WorkerThread(threading.Thread):
""" A worker thread that takes directory names from a queue, finds all
files in them recursively and reports the result.
Input is done by placing directory names (as strings) into the
Queue passed in dir_q.
def get_file_md5(f, chunk_size=8192):
h = hashlib.md5()
while True:
chunk = f.read(chunk_size)
if not chunk:
break
h.update(chunk)
return h.hexdigest()
@chankeypathak
chankeypathak / top10_scores.py
Created October 9, 2017 09:59
Get top 10 student names
import pandas as pd
df = pd.read_csv(r'data.csv', encoding='utf8')
df['score'] = df['score'].str.replace('%', '')
score_df = (df['score'].sort_values(ascending=False)[:5])
indexes = score_df.index
print (df.iloc[indexes])
@chankeypathak
chankeypathak / python_chunk_download.py
Created July 26, 2017 06:42
Download big files from internet in chunks to avoid out of memory error
import requests # just a choice of comfort for me
def download(url_address, filename):
response = requests.get(url_address, stream=True)
response.raise_for_status()
with open(filename, "wb") as f:
total_length = response.headers.get('content-length')
if total_length is None:
f.write(response.content)
else:
total_length = int(total_length)
@chankeypathak
chankeypathak / efficient_sort.py
Created July 27, 2017 10:13
Sorting a million 32-bit integers in 2MB of RAM using Python
#!/usr/bin/env python3.0
import sys, array, tempfile, heapq
assert array.array('i').itemsize == 4
def intsfromfile(f):
while True:
a = array.array('i')
a.fromstring(f.read(4000))
if not a: