This file contains hidden or 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/python3.6 | |
# Conversion of genetic algorithm from Will Larson's example in | |
# https://lethain.com/genetic-algorithms-cool-name-damn-simple/ to Python 3 | |
""" | |
# Example usage | |
target = 371 | |
p_count = 100 | |
i_length = 6 |
This file contains hidden or 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 bash | |
exec /Applications/Sublime\ Text.app/Contents/MacOS/Sublime\ Text "$@" |
This file contains hidden or 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
print('Output:') | |
for x in enumerate('hello world'): | |
print x | |
# Output: | |
# (0, 'h') | |
# (1, 'e') | |
# (2, 'l') | |
# (3, 'l') | |
# (4, 'o') |
This file contains hidden or 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
cat "${1}" | pbcopy |
This file contains hidden or 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
# Simple example of Python Fabric + Jinja deployment of a file using templating | |
from datetime import datetime | |
from fabric.tasks import execute | |
from fabric.contrib.files import upload_template | |
def create_setup_from_template(): | |
today = datetime.now() | |
today_string = today.strftime('%m%d%Y') |
This file contains hidden or 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 __future__ import print_function | |
import os | |
import time | |
import shutil | |
def get_path_and_mod_date(file_entry): | |
""" | |
Get the full path and the modification date of a file entry. | |
:param file_entry: The input file entry (could be a directory or file, | |
though this script only deals with directories). |
This file contains hidden or 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
convert big_image.png -crop 410x312+476+291 cropped_image.png |
This file contains hidden or 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 csv | |
import datetime | |
import dask.bag as db | |
b = db.read_text('*.csv', blocksize=10000000) # Read in a bunch of CSV files from the current directory. | |
records = b.str.strip().str.split(',') | |
header = records.compute()[0] # Get the first line from the records to retrieve the header. | |
combined_bag = db.from_sequence(records.compute(), npartitions=1) | |
# ^ Join the bag into one partition, so the CSV file is not separated. |
This file contains hidden or 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 os | |
import fnmatch | |
from PIL import Image | |
from PIL import ImageFont | |
from PIL import ImageDraw | |
dirs = filter(os.path.isdir, os.listdir(os.curdir)) | |
has_files = filter(lambda this_dir: os.listdir(this_dir), dirs) # Get all directories that actually contain files. | |
count_pngs = len(filter(lambda this_file: this_file.endswith('.png'), os.listdir(has_files[0]))) |
This file contains hidden or 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
// Adapted from https://muaz-khan.blogspot.com/2012/02/absolute-or-relative-url-issues-and.html | |
function qualifyURL(url) { | |
var a = document.createElement('a'); | |
a.href = url; // set string url | |
url = a.href; // get qualified/absolute url | |
a.href = null; // no server request | |
return url; | |
} |