Skip to content

Instantly share code, notes, and snippets.

View harshithjv's full-sized avatar

Harshith J. V. harshithjv

  • Mangalore
  • 07:08 (UTC +05:30)
View GitHub Profile
@harshithjv
harshithjv / validate_crontab_time_format.py
Last active August 6, 2020 13:41
Python Regex object to validate crontab entry time format string.
"""
Referred from stackoverflow question: http://stackoverflow.com/questions/235504/validating-crontab-entries-w-php
"""
validate_crontab_time_format_regex = re.compile(\
"{0}\s+{1}\s+{2}\s+{3}\s+{4}".format(\
"(?P<minute>\*|[0-5]?\d)",\
"(?P<hour>\*|[01]?\d|2[0-3])",\
"(?P<day>\*|0?[1-9]|[12]\d|3[01])",\
"(?P<month>\*|0?[1-9]|1[012])",\
@harshithjv
harshithjv / validate_crontab_time_format_simple.py
Last active August 6, 2020 13:46
Simpler Python Regex object to validate crontab entry time format string.
validate_crontab_time_format_regex = re.compile(\
r"^{0}\s+{1}\s+{2}\s+{3}\s+{4}$".format(\
r"(?P<minute>[\d\*]{1,2}([\,\-\/][\d\*]{1,2})*)",\
r"(?P<hour>[\d\*]{1,2}([\,\-\/][\d\*]{1,2})*)",\
r"(?P<day>[\d\*]{1,2}([\,\-\/][\d\*]{1,2})*)",\
r"(?P<month>[\d\*]{1,2}([\,\-\/][\d\*]{1,2})*)",\
r"(?P<day_of_week>[0-6\*]([\,\-\/][0-6\*])*)"
) # end of str.format()
) # end of re.compile()
@harshithjv
harshithjv / base_5_generator.py
Created February 16, 2016 15:22
Mimics the Base 5 number system as a generator function.
def get_5x_increments(num):
num_str = str(num)
num_len = len(str(num))
if num_str[-1:] == '4':
new_num = num + 6
if '5' in str(new_num):
return 6 + get_5x_increments(new_num)
else:
return 6
"""
For implementation of digits_0to5 refer this gist: https://gist.github.com/harshithjv/969f4fb820dd96e4739c
"""
from base_5_generator import digits_0to5
from collections import Counter
for i in digits_0to5(50000):
i_str = str(i)
digit_repr = tuple([int(j) for j in i_str])
num_counts = {'0':0, '1':0,'2':0,'3':0,'4':0}
@harshithjv
harshithjv / rename_shell_title.py
Created February 22, 2016 12:07
Renames shell title with current folder name.
import sys
import os
if sys.platform == 'linux2':
os.system('echo -en "\033]0;$(basename $(pwd))\007"')
elif sys.platform == 'win32': #does not work as it will sets title inside a new prompt for the current execution and disappears after executing
(directory, base_name) = os.path.split(os.getcwd())
if not base_name:
base_name = directory
@harshithjv
harshithjv / kill_celery_processes.sh
Last active February 18, 2024 10:20
Killing all celery processes in one line.
# Killing all celery processes involves 'grep'ing on 'ps' command and run kill command on all PID. Greping
# on ps command results in showing up self process info of grep command. In order to skip that PID, 'grep
# -v grep' command is piplined which executes 'not' condition on 'grep' search key. The 'awk' command is
# used to filter only 2nd and 'tr' command translates result of 'awk' command output from rows to columns.
# Piplining 'kill' command did not work and so the entire process has been set as command substitution, i.e.,
# '$()'. The redirection at the end is not mandatory. Its only to supress the enitre output into background.
kill -9 $(ps aux | grep celery | grep -v grep | awk '{print $2}' | tr '\n' ' ') > /dev/null 2>&1
@harshithjv
harshithjv / GitHubEmojiLinks.md
Last active March 2, 2020 15:51
Online resources to find github emojis 🎨 📝 🐛
@harshithjv
harshithjv / alternatePositiveNegativeInt.py
Last active February 11, 2020 19:25
Generator function that yields alternating negative and positive integers from given list.
def alternatePositiveNegativeInt(arr, startPositive=False):
"""
Generator function that yields alternating negative and positive integers from given list.
arr - list or tuple type object. The 'arr' is short for 'array.'
startPositive - Seed value to start yield negative or positive integer. False by default stating
to start yielding a negative integer.
"""
if not isinstance(arr, (list, tuple)):
@harshithjv
harshithjv / .Lucky Palindrome & Social Circles.md
Last active March 2, 2020 15:53 — forked from 2rohityadav/Questions.md
Questions - Javascript Coding

Challenge Questions

Lucky Palindrome / Social Circle

QUESTION 1

Lucky Palindrome

QUESTION DESCRIPTION

@harshithjv
harshithjv / FlattenDictionaryGenerator.py
Created March 14, 2020 14:16
Flatten Dictionary Generator
def flattenDict(a_dict):
for (key, value) in a_dict.items():
yield key
if not isinstance(value, dict):
if isinstance(value, list):
for v in value:
yield v
else:
yield value
else: