Skip to content

Instantly share code, notes, and snippets.

@aychen5
aychen5 / sample_points.py
Created February 12, 2023 22:18
Sample road segments in NYC from centerline file. Calculate the heading of each subsegment.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import geopandas as gpd
import pyproj
import numpy as np
import geojson
from shapely.geometry import Point, LineString, MultiPoint
from tqdm import tqdm
import math

06.3 jQuery Selectors Whack-a-mole! (SOLUTION CODE)

Oh no, my yard is infested with moles! Help me whack them! Let's use jQuery to remove each mole. Remember that means we're writing in the JavaScript editor now.

Mild:

  1. Let's start with the first mole at the top. It has the class mole1. Fix the code provided on lines 1-3 so that the mole disappears when you click on its "Whack Me!" button. Hint: You'll need to change the selector from "INCORRECT" to the name of the button you want to click.

Did you get rid of the first mole?! YES? GREAT!

@aychen5
aychen5 / get_tweets_full_archive.py
Created June 11, 2021 19:48
This script gets the entire Twitter history of local government officials.
# This script gets the entire Twitter history of local government officials
# INPUT: list of screen_names of Twitter users
# OUTPUT: saves {screen_name}.csv to ../data/local/
import requests
import os
import json
import pandas as pd
import time
# This token is from Academic Research Twitter API account (limit is 10 million)
using Distributed
numCore = 4;
addprocs(numCore - 1);
#rmprocs(workers());
#%%
# PARAMETERS
# alpha: Pr(false positive)
# starting sample size: initial HITs distributed
# effect size:
import os
import json
import pandas
import pickle
import google.oauth2.credentials
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
library(rsq)
library(gglot2)
library(dplyr)
data <- read.csv(here::here("child_soldiering.csv"))
# our linear model
mod <- rsq.partial(lm(educ ~ abd + age + fthr.ed + C.ach, data = data))
# What is half the magnitude of the treatment coefficient?
@aychen5
aychen5 / conjoint_Ghana.js
Last active June 3, 2023 15:04
code for conjoint profiles
// import seeded random number generator code
// https://github.com/davidbau/seedrandom/blob/released/seedrandom.min.js
!function(a,b){function c(c,j,k){var n=[];j=1==j?{entropy:!0}:j||{};var s=g(f(j.entropy?[c,i(a)]:null==c?h():c,3),n),t=new d(n),u=function(){for(var a=t.g(m),b=p,c=0;q>a;)a=(a+c)*l,b*=l,c=t.g(1);for(;a>=r;)a/=2,b/=2,c>>>=1;return(a+c)/b};return u.int32=function(){return 0|t.g(4)},u.quick=function(){return t.g(4)/4294967296},u["double"]=u,g(i(t.S),a),(j.pass||k||function(a,c,d,f){return f&&(f.S&&e(f,t),a.state=function(){return e(t,{})}),d?(b[o]=a,c):a})(u,s,"global"in j?j.global:this==b,j.state)}function d(a){var b,c=a.length,d=this,e=0,f=d.i=d.j=0,g=d.S=[];for(c||(a=[c++]);l>e;)g[e]=e++;for(e=0;l>e;e++)g[e]=g[f=s&f+a[e%c]+(b=g[e])],g[f]=b;(d.g=function(a){for(var b,c=0,e=d.i,f=d.j,g=d.S;a--;)b=g[e=s&e+1],c=c*l+g[s&(g[e]=g[f=s&f+b])+(g[f]=b)];return d.i=e,d.j=f,c})(l)}function e(a,b){return b.i=a.i,b.j=a.j,b.S=a.S.slice(),b}function f(a,b){var c,d=[],e=typeof a;if(b&&"object"==e)for(c in a)t