Skip to content

Instantly share code, notes, and snippets.

View ruthtillman's full-sized avatar

Ruth ruthtillman

View GitHub Profile
@ruthtillman
ruthtillman / slug.php
Created July 17, 2014 19:09
Wordpress: globally-isolating a page's slug.
function get_the_slug( $id=null ){
if( empty($id) ):
global $post;
if( empty($post) )
return ''; // No global $post var available.
$id = $post->ID;
endif;
$slug = basename( get_permalink($id) );
return $slug;
@ruthtillman
ruthtillman / 2.sh
Last active August 29, 2015 14:06
Updating my _ebooks tweets including an old tweets.zip export. On Windows but w/Git Bash
#as a note, I took out the first two lines of tweets.model after creating it from tweets.csv. This seems to allow the files to merge ok.
cd C:/Users/RKT/Dropbox/bots
cp ruthbrarian.json C:/ruthbrar_ebooks/corpus
cd C:/ruthbrar_ebooks
ebooks consume corpus/ruthbrarian.json
@ruthtillman
ruthtillman / 1.sh
Last active August 29, 2015 14:06
Pulling my _ebooks account update on Linux and transferring to Windows via Dropbox.
#!/bin/bash
#because Ruby isn't automatically running on this one
source ~/.rvm/scripts/rvm
cd /home/rkt/ruthbrar_ebooks
ebooks archive ruthbrarian corpus/ruthbrarian.json
cp corpus/ruthbrarian.json /home/rkt/Dropbox/bots
@ruthtillman
ruthtillman / DPLA-search.php
Created June 4, 2015 12:58
DPLA API search
<?php
/*
YES) allow the user to enter her own query terms into a form
YES) only connect to the API when a user has entered a query into the form
YES) validate and encode the user's input to prevent cross-site scripting and other errors
YES) check that the HTTP request to the API did not result in an error
YES) display an error message if no results are returned from the API
YES) use at least one of your own functions in your PHP script
@ruthtillman
ruthtillman / regex-replace-unclosed-xml
Last active May 17, 2021 21:07
Regex to find/replace improperly-closed tags
# Regex to find/replace improperly-closed tags
For situations with `<dc:title>Title<dc:title>` errors, etc. Syntax works with Sublime Text 2 directory-wide search. Example uses DC. NOTE: This search relies on line-breaks separating the tags you're looking at. Otherwise it can catch the second start tag, because "." includes everything except new lines.
## For Prefixed Tags
Find: <dc:(.+)>(.+)<dc:(.+)>
Replace With: <dc:\1>\2<\/dc:\3>
## For Non-Prefixed Tags
<xsl:choose>
<xsl:when test="self::dc:date and text()[matches(.,'^\d{4}\-\d{2}-\d{2}')]">
<xsl:text>^^xsd:date</xsl:text>
</xsl:when>
<xsl:when test="self::dc:date and text()[matches(.,'^\d{4}\-\d{2}')]">
<xsl:text>^^xsd:gYearMonth</xsl:text>
</xsl:when>
<xsl:when test="self::dc:date and text()[matches(.,'^\d{4}')]">
<xsl:text>^^xsd:gYear</xsl:text>
</xsl:when>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="text" indent="no" media-type="string"/>
<xsl:strip-space elements="*"/>
find C:/Path/To/Folders -type f -name "*.pdf" -exec cp {} C:/Path/To/New/Folder \;
import glob
import os
"""
Loops through all the .xml files in the directory where the script is located and removes the designated string: REMOVETHIS in each filename.
If you want to replace, add your new text as the second argument in replace().
"""
def do_rename_files():

Add new column, based on this column and extract RDF URI

cell.recon.match.id

Merging several columns

(copied from Recipes) You'd need to use the 'cells' variable:

cells["col1"].value + cells["col2"].value