Skip to content

Instantly share code, notes, and snippets.

@pnettto
pnettto / functions.php
Created July 29, 2020 14:32
Surface Guntenberg Block in WP Rest API
<?php
// Surface all Gutenberg blocks in the WordPress REST API
function add_blocks_to_rest_api() {
$post_types = get_post_types_by_support([ 'editor' ]);
foreach ($post_types as $post_type) {
register_rest_field($post_type, 'blocks', [
'get_callback' => function (array $post) {
return parse_blocks($post['content']['raw']);
"""
This script takes a csv file exported from Google Spreadsheets
after getting answers from a Google Form, and displays the results
neatly in an Markdpown file. It also aggregates the results by one
column (in my case the question "Group name"), which you need to
specify in the group_column variable.
The answers.csv file (from Google Spreasheets) needs to be in the
same directory as this python script on run time.
"""
"""
Creates a CSV file to import passwords into BitWarden from an array
Usage:
- Download this file to a folder in your computer
- Change the file as you wish to add more account entries
- "cd" into the chosen download directory with the Terminal
- Run "python3 generate_bitwarden_import_file.py"
- A file called "generated_passwords.csv" will be created in the same directory
"""
This script generates a sidebar structure for Docsify (https://docsify.js.org/)
projects. It's intended as a way to make the sidebar a little more
straight-forward but the result will probably need some re-arranging.
Usage:
- Download this file to your project's directory
- "cd" into that directory
- Run "python3 generate_sidebar.py"
@pnettto
pnettto / png_to_jpg.py
Created May 22, 2017 21:14
Transform all png images in a directory to jpg
# Transform png image to jpg
imgs = []
path = "/path/containing/png/files"
valid_images = [".png"]
for f in os.listdir(path):
ext = os.path.splitext(f)[1]
if ext.lower() not in valid_images:
continue
imgs.append({
'name': f,
@pnettto
pnettto / download_images_from_csv.py
Created May 22, 2017 21:12
Download images from csv
# Download images from csv
with open('file.csv', 'rb') as myFile:
reader = csv.reader(myFile, delimiter=',')
for row in reader:
if row[5] != 'Images':
command = 'wget ' + row[5].split('?')[0]
subprocess.Popen(command.split(), stdout=subprocess.PIPE)