Skip to content

Instantly share code, notes, and snippets.

View akanik's full-sized avatar

Alexandra Kanik akanik

View GitHub Profile
@akanik
akanik / gist:a3ac3fea2893ef0ddeed
Last active December 30, 2015 20:58
coral_asset_discussion_score
def asset_discussion_score(threads, k=1, theta=2):
X = np.array([max_thread_width(t) * max_thread_depth(t) for t in threads])
n = len(X)
k = np.sum(X) + k
t = theta/(theta*n + 1)
return {'discussion_score': gamma_poission_model(X, n, k, theta, 0.05)}
@akanik
akanik / gist:d0175d8ab418f3729d26
Created December 30, 2015 20:59
coral_gamma_poission_model
def gamma_poission_model(X, n, k, theta, quantile):
k = np.sum(X) + k
t = theta/(theta*n + 1)
return stats.gamma.ppf(quantile, k, scale=t)
@akanik
akanik / gist:1f86e2f45223c1ae403a
Created December 30, 2015 21:04
coral_beta_binomial_model
def beta_binomial_model(y, n, alpha, beta, quantile):
alpha_ = y + alpha
beta_ = n - y + beta
return stats.beta.ppf(quantile, alpha_, beta_)
@akanik
akanik / gist:be3ca9beffe1acab274d
Created December 30, 2015 21:04
coral_asset_diversity_score
def asset_diversity_score(threads, alpha=2, beta=2):
X = set()
n = 0
for t in threads:
users, n_comments = unique_participants(t)
X = X | users
n += n_comments
y = len(X)
return {'diversity_score': beta_binomial_model(y, n, alpha, beta, 0.05)}
@akanik
akanik / htaccess-no-www.txt
Last active February 2, 2016 20:34
.htaccess redirect www
# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# Make sure to replace example.com with your own site name
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
@akanik
akanik / htaccess-no-naked.txt
Created February 2, 2016 20:34
htaccess redirect naked domain
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# Make sure to replace example.com with your own site name
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
@akanik
akanik / htaccess-modrewrite.txt
Created February 2, 2016 21:42
turn modrewrite on
RewriteEngine on
@akanik
akanik / excel-csv.py
Last active May 15, 2018 15:26
excel sheets to individual csv files
# Thanks to http://stackoverflow.com/questions/9884353/xls-to-csv-convertor
import os, csv, xlrd
excel_file = '/path/to/file.xls'
#we're specifying a directory here because we'll have several files
#be sure to include end slash
csv_filepath = 'path/to/csv/directory/'
def csv_from_excel(excel_file):
workbook = xlrd.open_workbook(excel_file)
@akanik
akanik / logging.py
Created March 18, 2016 03:28
logging text and Exception
from sys import argv
import datetime, os, logging
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
def handle(self, *args, **options):
self.print_date()
def print_date(self):
@akanik
akanik / arc-gov-appal-counties.csv
Created July 18, 2016 21:12
A csv list of counties considered "Appalachian" by arc.gov.
state county
Alabama Bibb
Alabama Blount
Alabama Calhoun
Alabama Chambers
Alabama Cherokee
Alabama Chilton
Alabama Clay
Alabama Cleburne
Alabama Colbert