Skip to content

Instantly share code, notes, and snippets.

View akanik's full-sized avatar

Alexandra Kanik akanik

View GitHub Profile
@akanik
akanik / sheets-script-mailchimp
Created October 4, 2018 18:33
Google sheets + Google Script + Mailchimp API
function getMailChimpData(){
// Here are the things you will change
var API_KEY = 'YOUR-KEY-HERE';
var MEMBER_LIST_ID = 'LIST-ID-WITH-SEGMENTS';
var KYCIR_LIST_ID = 'LIST-ID-WITH-NO-SEGMENTS';
function calculateAvgRates(runType, segmentID, rateType){
var ratesList = [];
@akanik
akanik / rank-excel
Last active October 1, 2018 16:48
excel ranking equation
# Equation looks to see if there are ties, if ties exist,
# then it skips the next ranking number so your last ranking
# number corresponds with the actual number of actual things
# you're ranking.
# This equation allows for up to a 4-way tie.
# Column E holds the values you're comparing to create the
# rank and Column F is where you're putting this equation
//These two functions create a new menu item titled "Update data" that
//when clicked will run the rest of the code we're writing here
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Update data')
.addItem('Update data', 'updateDataMenu')
.addToUi();
}
function updateDataMenu() {
function gaDateFetch(){
// Here are all the variables you'll need to set
var sheetName = 'by-date';
var viewId = 'ga:xxxxxxx';
var metric = 'ga:users';
// select the sheet named by-date
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(sheetName);
@akanik
akanik / pandas-multi-var-new-field
Created July 18, 2018 17:41
Calculate a new field from multiple dataframe variables
#https://stackoverflow.com/questions/19914937/applying-function-with-multiple-arguments-to-create-a-new-pandas-column
def float_to_datetime(ddate, ttime):
return pd.to_datetime('1899-12-30') + pd.to_timedelta(ddate + ttime),'s')
response_data['pickup_datetime'] = np.vectorize(float_to_datetime)(response_data['date'], response_data['911_pickup_time'])
response_data['dispatch_datetime'] = np.vectorize(float_to_datetime)(response_data['date'], response_data['dipatch_time'])
response_data['arrive_datetime'] = np.vectorize(float_to_datetime)(response_data['date'], response_data['arrive_time'])
#https://gist.github.com/oag335/9959241
response_data['real_date'] = pd.to_datetime('1899-12-30') + pd.to_timedelta(response_data['date'],'D')
@akanik
akanik / pdf-extract
Created May 30, 2018 20:12
Extract pages from a pdf into another pdf
# https://www.commandlinefu.com/commands/view/9002/extracting-a-range-of-pages-from-a-pdf-using-ghostscript
# commandline
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=14 -dLastPage=17 -sOutputFile=OUTPUT.pdf ORIGINAL.pdf
@akanik
akanik / python-combine-csv
Last active March 7, 2019 03:31
combine csv files into one
import os
data_dir = '/Users/akanik/data/csv/'
file1 = 'whatever-data-1.csv'
file1_path = data_dir + file1
#Make sure your combined file does not live within your data_dir.
#This will cause an endless loop of writing
combined_file = '/Users/akanik/data/whatever-data-ALL.csv'
fout = open(combined_file,'a')
@akanik
akanik / pivot-blanks
Created August 7, 2017 19:49
Pivot table blanks, fill them in
=if(isblank(B2),A1,B2)
@akanik
akanik / new-django-install
Last active July 24, 2017 20:44
Steps to setting up a new django install
#virtual environment
>> cd [project-path]
>> mkvirtualenv -a ./ [-r requirements_file] ENVNAME
#install django in virtualenv
>> pip install Django
#create django project
>> django-admin startproject mysite