Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jerinisready's full-sized avatar
💭
A catalyst of Change

JK jerinisready

💭
A catalyst of Change
View GitHub Profile
@jerinisready
jerinisready / twitter_avg_post_length.py
Created September 6, 2017 15:58
HBase-Spark-Twitter-API-Streaming-Python A sample Code to find Average length of tweets in Twitter. Prerequests: HBASE database : with table name "twitter" and a column family "json" feeded with twitter api stream. Each row name starts with tweet Used Happybase to connect HBASE Database structure is mentioned in https://github.com/jerinisready/K…
# HBASE Database Design Here : https://github.com/jerinisready/Kafka-Twittter-Streaming
from __future__ import print_function
import json
import happybase
# from happybase import connection as Connection
## START bin/hbase rest start -p <port>
## VARS
LISTENING_TOPIC = 'myWorld'
@jerinisready
jerinisready / someone_likes_this.py
Created November 22, 2017 09:36
Someone Like This Puzzle in One Line
"""
QUESTION
Let 'a' be the list of users who likes a post! I want to get displayed as below
eg 1 :- a = []
Output : Nobody likes This
eg 2 :- a = ['Alice']
Output : Alice likes This
@jerinisready
jerinisready / indexes.sql
Last active April 4, 2018 05:28 — forked from garethrees/indexes.sql
List all indexes in postgres database
# VIEW INDEXES applied on database.
select schemaname, tablename, indexname, indexdef from pg_indexes WHERE schemaname='public';
# Create superuser for postgres on linux shell with postgres user.
user@ubuntu$ sudo su postgres
user@ubuntu$ createuser --interactive --pwprompt root
> Enter password for new role: ********
> Enter it again: ********
> Shall the new role be a superuser? (y/n) y
@jerinisready
jerinisready / iris.py
Last active April 4, 2018 08:11
How to train and test iris dataset in python using DecisionTreeClassifier from sklearn.
from sklearn.datasets import load_iris
from sklearn import tree
import numpy as np
import csv
#
# TODO : This Commented code will run with dataset predefined in sklearn.datasets
#
# iris = load_iris()
# # print (iris.feature_names )
# # print (iris.target_names)
@jerinisready
jerinisready / distance_between_points.py
Last active April 5, 2018 10:38
Python Function to describe the distance between two points given by its latitude and longitude
from math import sin, cos, radians, acos
def calculate_distance(lat_a, long_a, lat_b, long_b, in_miles=True):
"""all angles in degrees, default result in miles"""
lat_a = radians(lat_a)
lat_b = radians(lat_b)
delta_long = radians(long_a - long_b)
cos_x = (
sin(lat_a) * sin(lat_b) +
cos(lat_a) * cos(lat_b) * cos(delta_long)
)
@jerinisready
jerinisready / html_error_messages.js
Created April 20, 2018 06:11
A Way to Customize HTML Error Messages!
function set_custom_error_message(data) {
var elements= $(data[0]);
var message = data[1];
for (var i = 0; i < elements.length; i++) {
var my_element = elements[i];
my_element.oninvalid = function(e) {
e.target.setCustomValidity("");
if (!e.target.validity.valid) {
e.target.setCustomValidity(message);
}
@jerinisready
jerinisready / fetch_live_tweets.py
Last active April 20, 2018 13:07
Fun @ GDGCochin #DevFest17
class A:
KEY = 'u5NeFqa------------tZ2UM'
SECRET = 'WgWtW3tL_--------------------------IlKD5GTHCfTjrLBsrC'
TOKEN = '1495931731-r----------------------------kjpfcMAjXxk'
TOKEN_SECRET = 'Im24KQ------------------------------fMJyK'
api_keys = A()
@jerinisready
jerinisready / s3boto3_overrided_storage.py
Created May 6, 2018 15:20
I got " NotImplementedError: This backend doesn't support absolute paths. " when integrated a project's Media storage with `S3 Bucket` with `django-storage` and `boto3`. This was because of the conflict, that was in the s3boto storage class the path method was not implemented. Here is how I solved It. I created a new Class Inderrited From Boto3S…
from django.utils.encoding import filepath_to_uri
from storages.backends.s3boto3 import S3Boto3Storage
class CustomStorage(S3Boto3Storage):
def path(self, name):
return filepath_to_uri(name)
@jerinisready
jerinisready / trim_input_onchange.html
Created May 7, 2018 06:04
trim any spaces at the start of the text box and trim any spaces at the end of the textbox.
<script>
function trim(el){
el.value = el.value.
replace (/(^\s*)|(\s*$)/gi, ""). // removes leading and trailing spaces
replace (/[ ]{2,}/gi," "). // replaces multiple spaces with one space
replace (/\n +/,"\n"); // Removes spaces after newlines
return true;
}
</script>
@jerinisready
jerinisready / django_image_store_as_blob_in_models.py
Created May 7, 2018 10:27
django image store as blob in models.py
class imageStorageAsThumpnail(models.Model)
image = models.ImageField(_("Image"), upload_to='chapter_images')
_thumbnail = models.TextField(
db_column='thumbnail',
blank=True)
def set_thumbnail(self, data):
self._data = base64.b64encode(data)
def get_thumbnail(self):