Skip to content

Instantly share code, notes, and snippets.

View JamesChevalier's full-sized avatar

James Chevalier JamesChevalier

View GitHub Profile
@JamesChevalier
JamesChevalier / mac_utf8_insanity.md
Last active May 2, 2024 23:38
Unicode on Mac is insane. Mac OS X uses NFD while everything else uses NFC. This fixes that.

convmv manpage

Install convmv if you don't have it

sudo apt-get install convmv

Convert all files in a directory from NFD to NFC:

convmv -r -f utf8 -t utf8 --nfc --notest .

@JamesChevalier
JamesChevalier / overpass_query_all_streets.md
Last active March 20, 2024 13:33
Overpass API query to retrieve all streets in a city

An area ID in Overpass is the OSM relation ID + 3600000000

This information is kind of buried in the Overpass API wiki page documenting the available filters: https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#By_area_.28area.29

The OSM relation ID can be seen in two places:

  • Visit https://www.openstreetmap.org and search for the city
  • Click on its entry and you will be taken to a https://www.openstreetmap.org/relation/SOME_NUMBER_HERE page
  • The relation ID is in the URL as "SOME_NUMBER_HERE" in the bullet point above
  • The relation ID will also be in parentheses next to the city name in the left column
@JamesChevalier
JamesChevalier / gist:7900a468a5038f7d0dc8
Created July 31, 2015 13:49
Key & Peele's East/West College Bowl Names
--- EAST ---
D'Marcus Williums
T.J. Juckson
T'varisuness King
Tyroil Smoochie-Wallace
D'Squarius Green, Jr.
Ibrahim Moizoos
Jackmerius Tacktheritrix
D'Isiah T. Billings-Clyde
@JamesChevalier
JamesChevalier / lambda_function.py
Last active November 28, 2022 12:58
How to run Newspaper in an Amazon Lambda function
from newspaper import Article
def lambda_handler(event, context):
url = event['url']
article = Article(url)
article.download()
article.parse()
return {
'content' : article.text
@JamesChevalier
JamesChevalier / routes.rb
Created February 3, 2013 19:23
This is an example routes file for a Rails app using Devise along with a custom Users Controller
Railsappname::Application.routes.draw do
root :to => "home#index"
devise_for :users, :skip => [:sessions, :registrations]
devise_scope :user do
# make some pretty URLs
get "login" => "devise/sessions#new", :as => :new_user_session
post 'login' => 'devise/sessions#create', :as => :user_session
delete "logout" => "devise/sessions#destroy", :as => :destroy_user_session
@JamesChevalier
JamesChevalier / osmosis.md
Last active January 20, 2022 07:56
I'm trying to figure out why osmosis won't run more than two threads

I've asked this at OpenStreetMap Help, but I'm posting it here as well for anyone without an OSM account.

The simplest version of the command I'm using is (pretty formatting for easier reading - it's usually one line):

osmosis --read-pbf-fast file="north-america-latest.osm.pbf" 
        --bounding-polygon file="holyoke_ma.poly" --write-xml file="holyoke_ma.osm"

I get more complex by adding --tee ## with ## being the number of files being read/written. So that's something like (pretty formatting for easier reading - it's usually one line):

osmosis --read-pbf-fast file="north-america-latest.osm.pbf" --tee 4

@JamesChevalier
JamesChevalier / howto.md
Last active September 14, 2021 01:39
How to recover from commits pushed to the wrong branch

The scenario here is that you've got a lot of commits on the master branch that should have been committed to a feature branch. You want to reset master back to the last commit, and you don't want to lose your work. The process below is fairly specific to SourceTree.

  1. Create a new branch named placeholder at the point that you want to restore to ... This will be deleted later, after everything is confirmed ok.
    • In SourceTree: right click the commit, choose Branch..., name it placeholder, and click Create Branch
    • Push this to origin
  2. Create a new branch at your latest commit ... This is the branch that will contain further work, so you should stick to your typical feature branch naming conventions.
    • In SourceTree: switch back to the branch for that latest commit and create a new branch from there
  • Push this to origin
@JamesChevalier
JamesChevalier / index.js
Created March 15, 2016 01:23
Get the bounding box of a GeoJSON object, regardless of how many polygons it contains. The core of this is from http://mikefowler.me/2014/06/10/drawing-geojson-in-a-canvas/
function getBoundingBox(data) {
var bounds = {}, coordinates, point, latitude, longitude;
// Loop through each "feature"
for (var i = 0; i < data.features.length; i++) {
coordinates = data.features[i].geometry.coordinates;
if(coordinates.length === 1){
// It's only a single Polygon
// For each individual coordinate in this feature's coordinates...
@JamesChevalier
JamesChevalier / NominatimOnEC2.md
Created September 21, 2016 02:43 — forked from econandrew/NominatimOnEC2.md
Instructions for installing an OpenStreetMap Nominatim geocoder instance on Amazon Linux / EC2 (Dec 2014)

Installing Nominatim on Amazon Linux / EC2

  1. Introduction

The official instructions for installing Nominatim are complete, but brief in places, and several steps must be changed in the Amazon Linux environment (which is roughly CentOS / Redhat). The steps below are rough record of what I did to get it working, but I didn't keep perfect track so you shouldn't rely on them as a shell script. Just follow each step, make sure it worked, and hopefully you'll need to adapt very little (version numbers, for one thing). (I also skip in and out of root, but you can be more careful if you like.)

  1. Setting up the EC2 instance

@JamesChevalier
JamesChevalier / AWSLambdaSimpleSMS.js
Created November 11, 2015 23:03 — forked from stevebowman/AWSLambdaSimpleSMS.js
AWS Lambda Function to send an SMS message via the Twilio API
console.log('Loading event');
// Twilio Credentials
var accountSid = '';
var authToken = '';
var fromNumber = '';
var https = require('https');
var queryString = require('querystring');