Skip to content

Instantly share code, notes, and snippets.

View haridas's full-sized avatar
🎯
Focusing

Haridas N haridas

🎯
Focusing
View GitHub Profile
@haridas
haridas / virtualenv_alias.sh
Created February 16, 2013 10:22
A Simple bash alias for python virtualenv. :)
# Python virtual env alias
alias activate='test -d ENV && source ./ENV/bin/activate || echo "No Virtualenv in the current folder"'
alias mkenv='test -d ENV && echo "Already exists" || virtualenv --system-site-packages ENV; activate'
import os
import sys
import subprocess
from optparse import OptionParser
from datetime import datetime
def run_shell_script(shell_script):
"""
Assuming that the script is comming from trusted source.
# Add the new password
sudo adduser $1
# Add the user to labs group.
sudo usermod -aG labs $1
# Force user to change password.
sudo chage -d 0 $1
@haridas
haridas / find_error_lines_in_json.py
Created November 23, 2018 05:17
Ensure a big jsons particular field does't includes null, Helpful as part of datacleanup process.
import json
def read_json_lines(fname, filed_name):
num = 0
doc_size = []
error_docs = []
with open(fname) as f:
while True:
line = f.readline()
if not line:
break
@haridas
haridas / fix_unicode.py
Created November 2, 2018 03:24
NLP pre-processing - Remove unicode chars from text
import glob
import pandas as pd
files = glob.glob('out-*.json')
def remove_unicode_char(file_name):
f = open(file_name, 'rb').read()
with open(file_name, 'w') as nf:
nf.write(f.decode(encoding="ascii", errors="ignore"))
print ("=> ", file_name)
@haridas
haridas / testing.py
Created October 8, 2018 16:44
Python debugger on Ipython shell
import os
import ipdb; ipdb.set_trace()
# other codes..
END=""
trap 'increment && END=1' 2
increment() {
ls /
echo "Cleaned up"
}
@haridas
haridas / new_memcached.py
Created March 24, 2015 03:10
Ketama based Consistent hashing implementation of python-memcache library.
"""
To Test this Script the start 8 memcache servers using this command.
$ memcached -d -p {PortNumber}
PortNumber:
11211
11212
11213
11214
@haridas
haridas / celeryd.sh
Created June 14, 2012 06:08
Celery Init.d script with Django settings.
#!/bin/bash -e
#=======================================
#
# :Usage: /etc/init.d/celeryd {start|stop|force-reload|restart|try-restart|status}
#
# :Configuration file: /etc/default/celeryd
#
# To configure celeryd you probably need to tell it where to chdir.
#
# EXAMPLE CONFIGURATION
@haridas
haridas / Compile-python-from-source.md
Last active May 8, 2017 07:21
Compile python source from source, compile flags, and other settings for data science works.
  1. Ensure all the development files required to build custom bindings, mainly bzip2, and sqlite3 bingings are important.
  2. Build python with enabling the unicode flag usc4
$ sudo apt-get install libbz2-dev libsqlite3-dev
$ ./configure --enable-unicode=ucs4
$ make
$ make install