Skip to content

Instantly share code, notes, and snippets.

View Zeitsperre's full-sized avatar
🗺️
Keeping on keepin' on.

Trevor James Smith Zeitsperre

🗺️
Keeping on keepin' on.
View GitHub Profile
@CristinaSolana
CristinaSolana / gist:1885435
Created February 22, 2012 14:56
Keeping a fork up to date

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@patmisch
patmisch / shape_importer.py
Created May 10, 2012 02:29
Shapefile Importer
#!/user/bin/python2.7
#script for importing US Census Tract File
#works specifically for subfolder 'shapefiles' with x number of subfolders for each state
#requires pyshp library http://code.google.com/p/pyshp/ and psycopg2 postgresql library
import psycopg2
import shapefile
import glob
@benbalter
benbalter / geojson-conversion.sh
Last active April 23, 2024 13:16
Bulk convert shapefiles to geojson using ogr2ogr
# Bulk convert shapefiles to geojson using ogr2ogr
# For more information, see http://ben.balter.com/2013/06/26/how-to-convert-shapefiles-to-geojson-for-use-on-github/
# Note: Assumes you're in a folder with one or more zip files containing shape files
# and Outputs as geojson with the crs:84 SRS (for use on GitHub or elsewhere)
#geojson conversion
function shp2geojson() {
ogr2ogr -f GeoJSON -t_srs crs:84 "$1.geojson" "$1.shp"
}
@jwass
jwass / convert.py
Created August 15, 2013 21:52
Simple Shapefile to GeoJSON converter. Using the shapefile from here: http://www.mass.gov/anf/research-and-tech/it-serv-and-support/application-serv/office-of-geographic-information-massgis/datalayers/senate2012.html it will result in an error "ValueError: Record's geometry type does not match collection schema's geometry type: 'Polygon' != 'Unk…
import fiona
import fiona.crs
def convert(f_in, f_out):
with fiona.open(f_in) as source:
with fiona.open(
f_out,
'w',
driver='GeoJSON',
crs = fiona.crs.from_epsg(4326),
@guziy
guziy / Converter.py
Last active June 30, 2022 04:59
A quick way to copy variables and metadata from one netcdf file to another using netcdf4-python
# -*- coding: utf-8 -*-
from netCDF4 import Dataset
#input file
dsin = Dataset("crop.nc")
#output file
dsout = Dataset("crop.nc3", "w", format="NETCDF3_CLASSIC")
#Copy dimensions
@bdjackson
bdjackson / SetMidpoint.py
Last active September 15, 2021 23:55
Setting the midpoint of a matplotlib colormap
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
class MidpointNormalize(mpl.colors.Normalize):
"""
class to help renormalize the color scale
"""
def __init__(self, vmin=None, vmax=None, midpoint=None, clip=False):
self.midpoint = midpoint
import asyncio
loop = asyncio.get_event_loop()
async def hello():
await asyncio.sleep(3)
print('Hello!')
if __name__ == '__main__':
loop.run_until_complete(hello())
@Hermanio
Hermanio / .thermal-daemon.sh
Last active July 6, 2021 03:24
Quick and dirty early throttling script using bash and intel p-state driver toggling. USE AT YOUR OWN RISK.
#!/bin/bash
targettemp=90
clockpct=70
while true
do
currenttemp=$(sensors -u | awk '/temp1_input/ {print $2; exit}' )
compare=$(echo $currenttemp'>'$targettemp | bc -l)
turbo=`cat /sys/devices/system/cpu/intel_pstate/no_turbo`
if [ "$turbo" -eq 0 ]
@dyerrington
dyerrington / auto_reload.py
Created December 6, 2017 04:19
This basic Python snippet is a basic pattern to automatically reload the contents of a file after it has changed. You can also adapt this example to extend the "watching" to include all files and directories within current context if you want to also trigger a reload on file modification / change.
import os, sys
from time import sleep
## We could update this to all files in all subdirectories
watching = [__file__]
watched_mtimes = [(f, os.path.getmtime(f)) for f in watching]
while True:
print("Idle...")
sleep(2) ## So not to kill our CPU cycles
@danwild
danwild / subset_examples.py
Last active September 8, 2020 12:56
Crop a NetCDF file by XY, Z, and Time with CDO + python bindings
# setup
from cdo import *
cdo = Cdo()
cdo.debug = True
in_file = '/path/to/in_file.nc'
out_file = '/path/to/out_file.nc'
date1 = '2018-03-01T00:00:00'
date2 = '2018-03-01T02:00:00'
# my target is in meters