Skip to content

Instantly share code, notes, and snippets.

@ejfox
ejfox / build_top40_allsector_geojson.mjs
Created September 22, 2022 16:31
A GPT-3 code-davinci-002 written script to scrape the top 40 worst polluters for all available industries
/* Our API takes queries like https://api.dev.climatetrace.org/v0/assets?sectors=steel&limit=40&year=2020 and returns geojson with point features */
/* We need to loop through every available sector and concatenate all of the features together into one large GeoJSON file called top40_allsectors.geojson */
/* Available sectors are: [{"SectorId":1,"SectorName":"solid-waste-disposal"},{"SectorId":2,"SectorName":"manure-management"},{"SectorId":3,"SectorName":"oil-and-gas-production-and-transport"},{"SectorId":4,"SectorName":"coal-mining"},{"SectorId":5,"SectorName":"cement"},{"SectorId":6,"SectorName":"electricity-generation"},{"SectorId":7,"SectorName":"oil-and-gas-refining"},{"SectorId":8,"SectorName":"aviation"},{"SectorId":9,"SectorName":"international-aviation"},{"SectorId":10,"SectorName":"copper-mining"},{"SectorId":11,"SectorName":"shipping"},{"SectorId":12,"SectorName":"iron-mining"},{"SectorId":13,"SectorName":"bauxite-mining"},{"SectorId":14,"SectorName":"domestic-aviation"},{"SectorId":15,"SectorNam
<template>
<section class="hero-map-container ba b--white bw2 bw3-l" ref="root">
<div id="map" class="w-100 vh-100 z-1 top-0" ref="mapRoot"></div>
<div ref="mapText" class="map-text relative z-999 ml5-l measure">
<p data-lat="35.102215" data-lng="-89.999185">TK 1</p>
<p
data-lat="35.12587"
data-lng="-90.0362"
const fs = require('fs');
const axios = require('axios');
const apiKey = 'X';
const apiKeySecret = 'X';
const bearerToken =
'X';
// go through all tweets and add tags using openAI
const { Configuration, OpenAIApi } = require('openai');
@ejfox
ejfox / add_tags_to_tweets.js
Created June 27, 2022 18:36
Use OpenAI to add tags to a JSON file of tweets
const fs = require('fs');
const { Configuration, OpenAIApi } = require('openai');
const { RateLimiter } = require('limiter');
const limiter = new RateLimiter({
tokensPerInterval: 10,
interval: 'minute',
fireImmediately: true,
});
{
"global": {
"red": {
"value": "#E60D4E",
"type": "color"
},
"blue": {
"value": "#0D7EE6",
"type": "color"
},
@ejfox
ejfox / setWidthAndHeight.js
Created May 13, 2022 13:38
Vue method to set width and height based on component element size
setWidthAndHeight() {
const cs = getComputedStyle(this.$el)
const paddingX = parseFloat(cs.paddingLeft) + parseFloat(cs.paddingRight)
const paddingY = parseFloat(cs.paddingTop) + parseFloat(cs.paddingBottom)
const borderX =
parseFloat(cs.borderLeftWidth) + parseFloat(cs.borderRightWidth)
const borderY =
parseFloat(cs.borderTopWidth) + parseFloat(cs.borderBottomWidth)
// CLEAR DATA
MATCH (n:Officer) DETACH delete n;
MATCH (n:Incident) DETACH delete n;
MATCH (n:Precinct) DETACH delete n;
MATCH (n:Penalty) DETACH delete n;
// SET CONSTRAINTS
CREATE CONSTRAINT officerIdConstraint ON (officer:Officer) ASSERT officer.id IS UNIQUE
CREATE CONSTRAINT incidentIdConstraint ON (incident:Incident) ASSERT incident.id IS UNIQUE
CREATE CONSTRAINT precinctIdConstraint ON (precinct:Precinct) ASSERT precinct.id IS UNIQUE
@ejfox
ejfox / import.cypher
Created May 6, 2021 17:10
Import CSV with Neo4J Cypher
// clear data
MATCH (n:Officer) delete n;
MATCH (n:Incident) delete n;
MATCH (n:Precinct) delete n;
MATCH (n:Penalty) delete n;
CREATE CONSTRAINT officerIdConstraint ON (officer:Officer) ASSERT officer.id IS UNIQUE
Parsed Date happiness total social energy wellness
2019-07-10 48.25351918 83.88230576 97.03125003 148.7255695 238.6566667
2019-07-11 149.6123334 98.34205408 185.3835502 94.47351362 249.3607796
2019-07-12 151.5025529 100 181.2305023 131.2680142 335.0919097
2019-07-13 104.975604 76.02830081 130.5435739 24.72176457 93.05885718
2019-07-14 106.9930615 79.22556595 70.54415526 50.38911631 176.7435962
2019-07-15 48.49782752 69.34323403 134.5885842 49.3129526 116.4604166
2019-07-16 65.89493656 88.01984618 181.9219129 94.17121736 127.9488072
2019-07-17 65.7430037 87.16667812 133.5655477 91.4792567 234.0841979
2019-07-18 78.91884416 86.8878136 95.92553568 80.09017738 245.2977639
@ejfox
ejfox / ndplayer.processing
Created February 10, 2021 23:00
Doomscroller Processing Script
PImage img; // Declare a variable of type PImage
float yScroll = 0;
// float scrollAmt = 50;
float threshold = 127;
PImage destination;
int lines = 1;
int scrollStart = 768;
float scrollScreens;
int revealAmt;