Skip to content

Instantly share code, notes, and snippets.

View afeld's full-sized avatar

Aidan Feldman afeld

View GitHub Profile
@afeld
afeld / README.md
Last active March 8, 2022 18:40
automatic virtualenv switching

This script will automatically switch to a Python virtual environment after you cd into a Python project, then deactivate when you leave. Inspired by a similar script from Justin Abrahms.

Installation

  1. Install virtualenvwrapper.

  2. Download the auto_virtualenv.sh script, and put it in your home directory (~/).

  3. Run the following:

chmod a+x ~/auto_virtualenv.sh

@afeld
afeld / gist:4952991
Last active February 8, 2022 03:13
good APIs for mashups

This list has been superseded by Public APIs. Check there for APIs with Auth: No, HTTPS and CORS Yes.


List of data APIs that require no server-side auth or private credentials, and are thus good for small browser-only JS projects.

@afeld
afeld / sample.py
Last active November 5, 2021 15:20
reduce size of CSV with pandas
import pandas as pd
# maintain the original data format by reading everything as strings
original = pd.read_csv("original.csv", dtype="object")
# set the random_state so it's reproducible. alternatively, can pass a `frac` to use a percentage.
sampled = original.sample(n=5000, random_state=1).sort_index()
# exclude the index so the columns match the orignal
@afeld
afeld / slack_reactions.js
Last active September 18, 2021 19:59
get emoji reactions for a message in Slack – unfortunately their API "might not always contain all users that have reacted". limited to 50 as of 2/12/16.
'use strict';
const Promise = require('bluebird');
const WebClient = require('slack-client').WebClient;
const token = process.env.SLACK_API_TOKEN;
if (!token) {
throw "Please set SLACK_API_TOKEN";
}
@afeld
afeld / MY_Exceptions.php
Created February 10, 2019 08:20
StackDriver reporting for PHP CodeIgniter
<?php
use Google\Cloud\ErrorReporting\Bootstrap;
use Google\Cloud\Logging\LoggingClient;
use Google\Cloud\Core\Report\SimpleMetadataProvider;
// application/core/MY_Exceptions.php
class MY_Exceptions extends CI_Exceptions {
public function __construct()
@afeld
afeld / _body.html.erb
Created December 12, 2011 20:47
using HTML in a RSS feed in Rails
<h1><%= record.name %></h1>
<!-- etc -->
@afeld
afeld / gist:10d85bb67c3cc8c7b7bb
Last active December 29, 2020 20:40
fix orientation for all images in an S3 bucket
# Reads from EXIF data and applies the appropriate rotation. Requires AWS CLI and ImageMagick.
# To use, replace `BUCKET` and run in your terminal.
mkdir -p BUCKET/upright
cd BUCKET
aws s3 sync s3://BUCKET .
find . -name "*.jpg" -exec convert {} -auto-orient upright/{} \;
aws s3 sync . s3://BUCKET --acl public-read
@afeld
afeld / jest-nock.test.js
Created September 29, 2020 06:14
Jest+Nock setup
// ensures that there's a clean slate for each test, and that no real HTTP requests are made
const nock = require("nock");
beforeAll(() => {
// ensures no requests hit live APIs
nock.disableNetConnect();
});
beforeEach(() => {
@afeld
afeld / gist:5003570
Last active April 13, 2020 17:03
GoDadddy->local Wordpress development setup

I've seen waaaay too many people modifying their Wordpress sites live, which is fragile because when (not "if") you break something, your visitors will see it. Here are steps for setting up a copy of your site locally, so you can muck around without worry. These instructions are for Wordpress sites hosted on GoDaddy specifically, but they should be fairly easy to interpret for other providers.

To back up your database

  1. Log into GoDaddy, and go to "My Account".
  2. Under "Web Hosting", click Launch next to your site's name.
  3. Under "Databases", click "MySQL".
  4. Next to your database name, click "Actions"->"Back Up".
  5. Log into FTP, and under /_db_backups/ you'll see a new *.sql file.
  6. Rename this to be mydb-YYMMDD.sql format (e.g. superwordpress-130220.sql).
@afeld
afeld / README.md
Last active March 19, 2020 14:44
running SQL against Google Sheets

Google Sheets has a QUERY function that can be used for writing SQL queries. It uses the Google Visualization API Query Language, which is unfortunately a pretty limited SQL dialect. A few options for writing more complex SQL queries:

  • Export to CSV and load into a database somewhere
    • Pros: Use whatever database you want
    • Cons: Have to re-export every time the data is updated
  • Load into BigTable
    • Pros: Automatically updates
    • Cons: Requires some Google Cloud setup
  • Load into Google Colaboratory ("Colab")
  • Pros: Very flexible, as you can use SQL, Pandas, or any other Python code/packages