Skip to content

Instantly share code, notes, and snippets.

View kedarjos's full-sized avatar

Kedar Joshi kedarjos

  • Intel
  • Santa Clara, California
View GitHub Profile
@kedarjos
kedarjos / progress.py
Last active September 14, 2022 15:33 — forked from vladignatyev/progress.py
Python command line progress bar in less than 10 lines of code.
# The MIT License (MIT)
# Copyright (c) 2016 Vladimir Ignatev
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the Software
# is furnished to do so, subject to the following conditions:
#
@kedarjos
kedarjos / merge_dict_py3.5.py
Created February 19, 2021 19:16
Merge 2 dictionaries in Python
# Works only for python 3.5 and above
dict1 = {'a': 1, 'b': 2}
dict2 = {'c': 3, 'd': 4}
dict3 = {**dict1, **dict2}
@kedarjos
kedarjos / bytesto.py
Created June 9, 2020 23:07 — forked from shawnbutts/bytesto.py
bytes to to mb, gb, etc in python
def bytesto(bytes, to, bsize=1024):
"""convert bytes to megabytes, etc.
sample code:
print('mb= ' + str(bytesto(314575262000000, 'm')))
sample output:
mb= 300002347.946
"""
a = {'k' : 1, 'm': 2, 'g' : 3, 't' : 4, 'p' : 5, 'e' : 6 }
@kedarjos
kedarjos / remove_function_calls.py
Created January 2, 2020 23:26
Python Remove Function calls from loop
#! /usr/bin/env python
import os, sys
import random
from timeit import timeit
from collections import deque
max = 100000
# Just a normal function
@kedarjos
kedarjos / list_vs_deque.py
Last active January 2, 2020 18:16
Python List vs Deque performance
#! /usr/bin/env python
import os, sys
import random
from timeit import timeit
from collections import deque
# Generate random numbers
max = 10
numbers = list()
@kedarjos
kedarjos / .gitignore
Created November 14, 2019 21:47
Python Gitignore example
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
@kedarjos
kedarjos / Python Deque Demo
Created November 8, 2019 04:49
Python Deque Demo
#! /usr/bin/env python
from collections import deque
if __name__ == "__main__":
d = deque('abcd')
print(d)
# deque(['a', 'b', 'c', 'd'])
@kedarjos
kedarjos / Python Command Executor
Last active August 20, 2019 22:07
Gist for a wrapper module to run system commands
#! /usr/bin/env python
'''
Created on Aug 20, 2019
@author: kedarjos
'''
import os
import subprocess
import datetime
@kedarjos
kedarjos / Perl DBIConnector Wrapper
Created August 20, 2019 22:00
Gist for a wrapper module around standard Perl DBI
#! /usr/bin/env perl
# Author: Kedar Joshi
package DBConnector;
use DBI;
# Constructor to build an object for db connection
# Import this module and create object with:
# my $obj = new DBConnector($host, $user, $password, $database, "mysql");