This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Tuple | |
import numpy as np | |
class MineSweeper(object): | |
def __init__(self, shape: Tuple, n_mines: int): | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* create some database and administrator account, for example. */ | |
create user dummy_admin; | |
alter user dummy_admin with password 'dummy_pass'; | |
create database "dummy_dbase" owner dummy_admin; | |
\c "dummy_dbase" | |
create extension if not exists postgis; | |
create extension if not exists fuzzystrmatch; | |
create extension if not exists postgis_tiger_geocoder; | |
create extension if not exists postgis_topology; | |
\c postgres |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from contextlib import contextmanager | |
@contextmanager | |
def manage_something(something): | |
""" this is the general structure of a contextmanager """ | |
try: | |
# prepare the something | |
yield something | |
except Exception as e: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from queue import Queue | |
import threading | |
import os | |
from datetime import datetime | |
import time | |
def updater(): | |
for i in range(10): | |
time.sleep(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
class AmbiguousArgs(BaseException): | |
pass | |
def remove_png_alpha(image_path, overwrite=False, color=(255, 255, 255), out_path=None): | |
""" | |
Removes the alpha layer form an input png (probably works with other filetypes as well) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ftplib | |
import os | |
import re | |
""" | |
MIT license: 2017 - Jwely | |
Example usage: | |
``` python | |
import ftplib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'Jwely' | |
class Butt(): | |
def __init__(self): | |
self.times_farted = 0 | |
def fart(self, times): | |
self.times_farted += times |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# super barebones list to csv | |
list = ["some", "kind", "of", "data"] | |
with open("myfile.csv", "w+") as f: | |
for item in list: | |
f.write(str(item) + "\n") | |
# same deal but with lists of lists | |
list_of_lists = [["bob", "20"], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# in the input expression | |
#from osgeo import gdal, gdalconst, gdalnumeric | |
import gdal | |
import gdalconst | |
import gdalnumeric | |
import numpy | |
import os | |
import math # imported so it is available to the users expression evaluation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'Jwely' | |
import numpy | |
# in order to handle Nodata values, we must use floats, not integer datatypes. | |
array = numpy.array([0, 5, 6, 3, 0, 11, 5, 2, 3, 6, 4, 1, 2, 5, 12], "float32") | |
# mask this array, where all "0" values are masked | |
# see also: https://docs.scipy.org/doc/numpy/reference/maskedarray.generic.html | |
masked_array = numpy.ma.masked_equal(array, 0) |
NewerOlder