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 / 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 / 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 / .traffic_light
Last active March 1, 2019 07:50
Plain HTML JQuery Example for a demo traffic Light!
This Demonize a Traffic Signal Control sample HTML PAGE using Pure JS
Preview is available on : https://bl.ocks.org/jerinisready/raw/8e15bcab2fe048b317119ea174576ef1/
Description is avbailable on : https://bl.ocks.org/jerinisready/8e15bcab2fe048b317119ea174576ef1#file-traffic_light-html
PREVIEW PARTNERSHIP WITH : https://bl.ocks.org
@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 / another_django_pagination_template.html
Last active September 12, 2018 18:00
Django Template Pagination snippet!
Showing {{ page_obj.start_index }} to {{ page_obj.end_index }} of {{ page_obj.paginator.count }} entries
{% if is_paginated %}
<ul class="pagination">
<!-- VERY FIRST -->
<li class="first {% if page_obj.number == 1 %} disabled {% endif %} "
id="m_table_1_first">
<a href="?page=1">
@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)