Skip to content

Instantly share code, notes, and snippets.

View greglinch's full-sized avatar

Greg Linch greglinch

View GitHub Profile
@greglinch
greglinch / file-generator.py
Last active June 16, 2021 22:05
Python script to batch generate files based on a variable. Save this file in a new directory and make the desired modifications. Open terminal and cd into that directory. Type $ python ./file-generator.py to execute the script.
values = ['comma','separated', 'list', 'of','values', 'each', 'surrounded', 'by', 'quotes']
# for each item in the list of items
for value in values:
# construct the filename; prefix or suffix optional
filename = 'prefix-' + value + '.jpt'
# open the file to be written
fo = open(filename, 'w')
@greglinch
greglinch / the_slug.php
Created December 5, 2012 04:28
create the_slug() function for WordPress
function the_slug($echo=true){
$slug = basename(get_permalink());
do_action('before_slug', $slug);
$slug = apply_filters('slug_filter', $slug);
if( $echo ) echo $slug;
do_action('after_slug', $slug);
return $slug;
}
// credit: http://www.tcbarrett.com/2011/09/wordpress-the_slug-get-post-slug-function/
@greglinch
greglinch / udacity-cs101-unit-1-final-quiz.py
Created March 1, 2012 03:20
Example of how to extract a link in Python using only the find() function
page ='<div id="top_bin"><div id="top_content" class="width960"><div class="udacity float-left"><a href="http://www.xkcd.com">'
start_link = page.find('<a href=')
start_quote = page.find('"', start_link)
end_quote = page.find('"', start_quote+1)
url = page[start_quote+1:end_quote]
@greglinch
greglinch / arduino_input_incrementer
Created June 4, 2011 20:51
To measure the output of my desk pedals at work using an Arduino
// ARDUINO INPUT INCREMNENTER
// To measure the output of my desk pedals at work
// Adapted from Example 03A from "Getting Started with Ardunio" by Massimo Banzi
// Greg Linch
// http://www.greglinch.com
#define BUTTON 7 // input pin where the push button is connected; this will soon be replaced with alternative method to measure output of pedals
int val = 0; // store the state of the input pint