Skip to content

Instantly share code, notes, and snippets.

View kurasaiteja's full-sized avatar

Saiteja Kura kurasaiteja

  • Hyderabad
View GitHub Profile
@kurasaiteja
kurasaiteja / gist:9dca348e8f397c74f14b530a4f9ea402
Last active November 28, 2018 11:23
This is working fine
*/Head.js*/
import React from 'react';
const head = (props) => {
return(
<p>I'm {props.name}.Welcome! </p>
)
}
/*Register.js*/
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { withStyles } from '@material-ui/core/styles';
import MenuItem from '@material-ui/core/MenuItem';
import Head from './Head'
import TextField from '@material-ui/core/TextField';
def perform_bernoulli_trials(n, p):
#Perform n Bernoulli trials with success probability p and return number of successes.
# Initialize number of successes: n_success
n_success = 0
# Perform trials
for i in range(n):
# Choose random number between zero and one: random_number
random_number = np.random.random()
# If less than p, it's a success so add one to n_success
if random_number<p:
from tweepy import OAuthHandler
from tweepy import API
# Consumer key authentication(consumer_key,consumer_secret can be collected from our twitter developer profile)
auth = OAuthHandler(consumer_key, consumer_secret)
# Access key authentication(access_token,access_token_secret can be collected from our twitter developer profile)
auth.set_access_token(access_token, access_token_secret)
# Set up the API with the authentication handler
from tweepy import Stream
# Set up words to track
keywords_to_track = ['#javascript','#python']
# Instantiate the SListener object
listen = SListener(api)
# Instantiate the Stream object
stream = Stream(auth, listen)
tweets = []
files = list(glob.iglob('/content/tweets.json'))
for f in files:
fh = open(f, 'r', encoding = 'utf-8')
tweets_json = fh.read().split("\n")
## remove empty lines
tweets_json = list(filter(len, tweets_json))
## parse each tweet
def check_word_in_tweet(word, data):
"""Checks if a word is in a Twitter dataset's text.
Checks text and extended tweet (140+ character tweets) for tweets,
retweets and quoted tweets.
Returns a logical pandas Series.
"""
contains_column = data['text'].str.contains(word, case = False)
contains_column |= data['extended_tweet-full_text'].str.contains(word, case = False)
contains_column |= data['quoted_status-text'].str.contains(word, case = False)
contains_column |= data['retweeted_status-text'].str.contains(word, case = False)
# Print created_at to see the original format of datetime in Twitter data
print(df_tweet['created_at'].head())
# Convert the created_at column to np.datetime object
df_tweet['created_at'] = pd.to_datetime(df_tweet['created_at'])
# Print created_at to see new format
print(df_tweet['created_at'].head())
# Set the index of df_tweet to created_at
import matplotlib.pyplot as plt
# Average of python column by day
mean_python = df_tweet['python'].resample('1 min').mean()
# Average of js column by day
mean_js = df_tweet['js'].resample('1 min').mean()
# Plot mean python/js by day
plt.plot(mean_python.index.minute, mean_python, color = 'green')
plt.plot(mean_js.index.minute, mean_js, color = 'blue')
def calculateCentroid(place):
""" Calculates the centroid from a bounding box."""
# Obtain the coordinates from the bounding box.
coordinates = place['bounding_box']['coordinates'][0]
longs = np.unique( [x[0] for x in coordinates] )
lats = np.unique( [x[1] for x in coordinates] )
if len(longs) == 1 and len(lats) == 1:
# return a single coordinate