Skip to content

Instantly share code, notes, and snippets.

@cleverinx
cleverinx / file_content_replace.py
Created December 11, 2018 07:10
Multiple find and replace operations in a file at once using Python.
import re
import csv
import fileinput
replacements = {'find this' : 'replace this',
'find this too' : 'replace with this',
'find this as well' : 'also replaced',
}
lines = []
with open('input_file.csv') as infile:
@cleverinx
cleverinx / one-time-download.php
Created December 11, 2018 07:03
Simple PHP script to allow downloading a file only once, after which it is deleted or renamed.
<?php
if ($_POST["submit"]) {
$file_name = '/srv/users/path/to/filename.zip';
// make sure it's a file
if (is_file($file_name)) {
@cleverinx
cleverinx / custom_walker.php
Created May 8, 2016 04:15
Custom Wordpress Sub-Menu Walker
class custom_sub_walker extends Walker_Nav_Menu {
public function start_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat( "\t", $depth );
$output .= "\n$indent<ul role=\"menu\" class=\" dropdown-menu\">\n";
}
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
@cleverinx
cleverinx / A Roots Sage Theme and Dev Setup.md
Created February 4, 2016 23:39 — forked from jasperf/A Roots Sage Theme and Dev Setup.md
Setting up Roots 8.0 (Sage) on a a Mac with Local Yosemite OSX Server and AMP. This includes setting up the server part of things #roots #wordpress #osx