Skip to content

Instantly share code, notes, and snippets.

Derek Haynes itsderek23

Block or report user

Report or block itsderek23

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View intercom_signups.py
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
grouped = df_users.groupby(pd.Grouper(key='signed_up_at',freq='W')).agg({"email": 'count'})
plt.figure(figsize=(12,8))
plt.plot(grouped.index.values, grouped.email.values)
plt.xlabel('Week', fontsize=12)
plt.ylabel('Users', fontsize=12)
View intercom_datetime_parse.py
import datetime
datetime_cols = [col for col in df_users.columns if col.endswith("_at")]
print("Timestamps cols to convert to datetime:",datetime_cols)
for col in datetime_cols:
df_users[col] = df_users.apply(lambda row: datetime.datetime.utcfromtimestamp(row[col]), axis=1)
View intercom_user_id_index.py
df_users.index = pd.to_numeric(df_users.index, errors='coerce')
df_users = df_users[df_users.index.notnull()]
View intercom_to_df.py
import pandas as pd
df_users = pd.DataFrame.from_records(users_list)
df_users.shape
View intercom_users.py
users_list = []
count = 1
for user in intercom.users.all():
users_list.append(user.to_dict())
if (count % 200 == 0 ):
print("Added user", count, "of", total)
if (count % 1000 == 0):
print(intercom.rate_limit_details)
View intercom_python_hello_world.py
!pip install python-intercom
API_TOKEN = 'YOUR KEY'
import intercom
from intercom.client import Client
intercom = Client(personal_access_token=API_TOKEN)
total = intercom.counts.for_app().user['count']
View fit_partial.py
model = RandomForestClassifier()
model.fit(X_train[:1000],y_train[:1000])
View train_test.py
# Download the data
from sklearn.datasets import fetch_mldata
mnist = fetch_mldata("MNIST original")
# Grab the datset and labels
X,y = mnist["data"], mnist["target"]
# Split into training and test sets
X_train, X_test, y_train, y_test = X[:60000], X[60000:], y[:60000], y[60000:]
# We'll shuffle the data to be safe ... some algorithms need this.
shuffle_index = np.random.permutation(60000)
@itsderek23
itsderek23 / net_http_with_domain.rb
Last active Sep 20, 2018
Breakout HTTP calls to specified domains in Scout
View net_http_with_domain.rb
# This modification provides more fine-grained visiblity of HTTP calls within Scout, breaking out time spent in HTTP calls for specified domains.
#
# Instructions:
# 1. `bundle update scout_apm`. Older versions of `scout_apm` have a bug w/disabling instrumentation.
#
# 2. Disable Scout's default HTTP instrumentation:
# config/scout_apm.yml
# production:
# <<: *defaults
# disabled_instruments: ['NetHttp']
View views.py.diff
# views.py
except EmptyPage:
search_results = paginator.page(paginator.num_pages)
+ scout_apm.api.Context.add("search_query",search_query)
+ scout_apm.api.Context.add("search_results_size",len(search_results))
return render(request, 'search/search_results.html', {
'search_query': search_query,
You can’t perform that action at this time.