Skip to content

Instantly share code, notes, and snippets.

View karthicraghupathi's full-sized avatar

Karthic Raghupathi karthicraghupathi

View GitHub Profile
@karthicraghupathi
karthicraghupathi / csv_parser.py
Created July 1, 2020 17:34
CSV reader using generator with the ability to slice
def parse_csv_file(filename, start=0, stop=None, step=1):
"""
Parses a csv file.
start - elements from the iterable are skipped until start is reached
stop - if None, continue iteration until iterator is exhausted or until stop is reached
step - skip items before returning value; useful for skipping headers etc
"""
with open(filename, 'r') as csv_file:
for row in csv.DictReader(
itertools.islice(csv_file, start, stop, step), skipinitialspace=True
@karthicraghupathi
karthicraghupathi / ami_tcp_dialer.py
Last active October 3, 2020 18:23
Asterisk AMI over TCP - Dialer & OriginateResponse Listener with pystrix
import pystrix
CHANNEL_DRIVER_SIP = 'SIP'
CHANNEL_DRIVER_PJIP = 'PJSIP'
class Dialer(object):
_host = _username = _password = _manager = _channel_driver = None
@karthicraghupathi
karthicraghupathi / fields.py
Created November 17, 2020 22:42 — forked from jpadilla/fields.py
CharacterSeparatedField - A Django REST framework field that separates a string with a given separator into a native list and reverts a list into a string separated with a given separator.
from rest_framework import serializers
class CharacterSeparatedField(serializers.WritableField):
"""
A field that separates a string with a given separator into
a native list and reverts a list into a string separated with a given
separator.
"""
def __init__(self, *args, **kwargs):
@karthicraghupathi
karthicraghupathi / gist:0be52da27aa990d812aeca553366f687
Created November 18, 2020 17:59 — forked from brianburridge/gist:11298396
How to load MySQL time zone tables from Mac OS time zone files

The easiest way to load the Mysql Time Zone tables from your Mac OS time zone fields is via this command:

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql

However, on many systems like mine that will fail because some of the time zone information is incompatible with the database schema for the time zone tables.

Therefore, you'll want to load the time zone information into a text file and edit it to only include the time zones you need. (Or, attempt to find the data breaking the import.)

mysql_tzinfo_to_sql /usr/share/zoneinfo > zone_import.sql
@karthicraghupathi
karthicraghupathi / delete_logs.py
Created December 1, 2020 21:51 — forked from hkraal/delete_logs.py
Script for removing messages from Graylog
#!/usr/bin/env python
"""
# Remove data from Graylog.
This script makes it possible to selectively remove data from an index set.
### Usage
* Setup an SSH tunnel to Graylog and Elasticsearch.
diff --git a/Python/random.c b/Python/random.c
index 93d300d..396041d 100644
--- a/Python/random.c
+++ b/Python/random.c
@@ -3,6 +3,9 @@
#include <windows.h>
#else
#include <fcntl.h>
+#if defined(HAVE_GETRANDOM) || defined(HAVE_GETENTROPY)
+#include <sys/random.h>
@karthicraghupathi
karthicraghupathi / pcap2wav
Created January 6, 2021 23:36 — forked from avimar/pcap2wav
Convert raw PCAP files into a .wav file
#!/bin/bash
#
# pcap2wav
# Original Author: Michael Collins <msc@freeswitch.org>
#Standard disclaimer: batteries not included, your mileage may vary...
# Updated by Avi Marcus <avi@bestfone.com>
#
# Accepts arg of pcap file w/only 2 RTP streams
# Creates a .<codec> file and a .wav file
# For codecs other than PCMA and PCMU the script calls fs_cli and does a little recording to create the wav file(s)
#!/bin/bash
if [ $# -ne 3 ]; then
echo "usage: $0 <unix socket file> <host> <listen port>"
exit
fi
SOCK=$1
HOST=$2
PORT=$3
@karthicraghupathi
karthicraghupathi / install.sh
Created October 19, 2021 03:47
Install Python 3.6.15 on macOS 11.6 (Big Sur)
brew install openssl@1.1 readline sqlite3 xz zlib
ASDF_PYTHON_PATCH_URL="https://github.com/python/cpython/commit/8ea6353.patch?full_index=1" \
CPPFLAGS="-I$(brew --prefix openssl@1.1)/include -I$(brew --prefix zlib)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/System/Library/Frameworks/Tk.framework/Versions/Current/Headers" \
LDFLAGS="-L$(brew --prefix openssl@1.1)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix readline)/lib" \
asdf install python 3.6.15
@karthicraghupathi
karthicraghupathi / bg_disown.sh
Created November 12, 2021 05:54
SSH - Keep Tasks Running Through Disconnects
# For a command that is currently running.
# First suspend current command
CTRL + Z
# Get a list of current jobs
jobs -l
# Then resume execution of the command in the background
bg