Skip to content

Instantly share code, notes, and snippets.

View ramcandrews's full-sized avatar
🏠
Working from home

Ryan McAndrews ramcandrews

🏠
Working from home
View GitHub Profile
@johnwbryant
johnwbryant / extract_aus.sh
Last active September 17, 2024 01:18
Extract Australia data in a usable format from Microsoft road detections data
#!/bin/bash
# see https://github.com/microsoft/RoadDetections
# 1) get the data
wget https://usaminedroads.blob.core.windows.net/road-detections/Oceania-Full.zip
# 2) extract the records for Australia, second column of tsv only
zgrep AUS Oceania-Full.zip | cut -f2 > AUS.geojson
# 3) convert to GPKG, works better in QGIS
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
## Importing Necessary Modules
import requests # to get image from the web
import shutil # to save it locally
## Set up the image URL and filename
image_url = "https://cdn.pixabay.com/photo/2020/02/06/09/39/summer-4823612_960_720.jpg"
filename = image_url.split("/")[-1]
# Open the url image, set stream to True, this will return the stream content.
r = requests.get(image_url, stream = True)
@zacjszewczyk
zacjszewczyk / webS
Created October 4, 2019 23:15
A syllable dictionary I built with Python. See https://zacs.site/blog/building-a-syllable-dictionary-with-python.html for the full writeup.
This file has been truncated, but you can view the full file.
# A syllable dictionary I built with Python. See https://zacs.site/blog/building-a-syllable-dictionary-with-python.html for the full writeup.
#
# This work is licensed under a Creative Commons Attribution 4.0 International License
# See https://zacs.site/disclaimers.html for more information.
# © 2012-2019 Zachary Szewczyk.
a,1
a,1
aa,1
aal,-1
@andrewjong
andrewjong / pytorch_image_folder_with_file_paths.py
Last active October 31, 2024 11:13
PyTorch Image File Paths With Dataset Dataloader
import torch
from torchvision import datasets
class ImageFolderWithPaths(datasets.ImageFolder):
"""Custom dataset that includes image file paths. Extends
torchvision.datasets.ImageFolder
"""
# override the __getitem__ method. this is the method that dataloader calls
def __getitem__(self, index):
@webbower
webbower / shuffle-durstenfeld.js
Created December 2, 2017 22:02
Durstenfeld shuffle
// http://en.wikipedia.org/wiki/Fisher-Yates_shuffle#The_modern_algorithm
// https://stackoverflow.com/a/12646864/2684520
// Pre-ES6
/**
* Randomize array element order in-place.
* Using Durstenfeld shuffle algorithm.
*/
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
@kmjjacobs
kmjjacobs / gru_tensorflow.py
Last active August 14, 2022 17:10
GRU (Gated Recurrent Unit) implementation in TensorFlow and used in a simple Machine Learning task. The corresponding tutorial is found on Data Blogger: https://www.data-blogger.com/2017/08/27/gru-implementation-tensorflow/.
#%% (0) Important libraries
import tensorflow as tf
import numpy as np
from numpy import random
import matplotlib.pyplot as plt
from IPython import display
% matplotlib inline
#%% (1) Dataset creation.
@ericls
ericls / async-await-fetch-map.js
Created July 19, 2017 04:03
async/await with fetch and map
// Use hacker news API as example
async function getData() {
const ids = await (await fetch('https://hacker-news.firebaseio.com/v0/topstories.json')).json()
const data = Promise.all(
ids.map(async (i) => await (await fetch(`https://hacker-news.firebaseio.com/v0/item/${i}.json?print=pretty`)).json())
)
return data
}
getData()
@webbower
webbower / generate-text-image.js
Last active October 2, 2021 06:30
Generate an image from text using the Canvas API
function generateImageFromText(text, width, height) {
// TODO Add auto-wrapping logic when text is too wide
// TODO Add tiered text scaling (if height > 200: font-size = 36; else if height > 100: font-size = 18; etc)
const canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext('2d');
const fontSize = Math.min(height, 36);
ctx.fillStyle = '#212121';
@yrevar
yrevar / imagenet1000_clsidx_to_labels.txt
Last active November 8, 2024 06:50
text: imagenet 1000 class idx to human readable labels (Fox, E., & Guestrin, C. (n.d.). Coursera Machine Learning Specialization.)
{0: 'tench, Tinca tinca',
1: 'goldfish, Carassius auratus',
2: 'great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias',
3: 'tiger shark, Galeocerdo cuvieri',
4: 'hammerhead, hammerhead shark',
5: 'electric ray, crampfish, numbfish, torpedo',
6: 'stingray',
7: 'cock',
8: 'hen',
9: 'ostrich, Struthio camelus',