Skip to content

Instantly share code, notes, and snippets.

View pfernandez's full-sized avatar

Paul Fernandez pfernandez

View GitHub Profile
@pfernandez
pfernandez / Simple WordPress Maintenance Mode
Last active August 29, 2015 14:08
Drop this snippet into the top of functions.php to get a simple maintenance mode without a separate plugin.
/**
* Show a special message to non-whitelisted users instead of the regular site.
* To activate maintenance mode, uncomment the add_action() line below.
*/
//add_action('wp_head', 'simple_maintenance_mode');
function simple_maintenance_mode() {
$user_name = wp_get_current_user()->user_login;
$ip = $_SERVER['REMOTE_ADDR'];
@pfernandez
pfernandez / hello-world.cljs
Last active December 11, 2015 17:38
Basic OM Next component in a Devcard
(ns cards.playground
(:require
[om.next :as om :refer-macros [defui]]
[om.dom :as dom]
[devcards.core :refer-macros [defcard]]
[devcards.util.edn-renderer :refer [html-edn]]))
(defui HelloWorld
Object
(render [this]
@pfernandez
pfernandez / query-read-mutate-example.cljs
Created December 11, 2015 17:36
Om Next Query, Read & Mutate in a Devcard
(ns cards.query-read-mutate-example
(:require
[om.next :as om :refer-macros [defui]]
[om.dom :as dom]
[devcards.core :refer-macros [defcard dom-node]]
[devcards.util.edn-renderer :refer [html-edn]]))
(def item-list-init-data
{:current-user {:email "bob.smith@gmail.com" :username "bobsmith"}
:items [{:id 0 :title "Foo"}
@pfernandez
pfernandez / backup-website.sh
Created May 26, 2019 03:27
Back up website files and database
#!/bin/bash
#
# Back up website files and database.
backupdir=~/backup
fileid=$(date +%F_%T)
filesource=/var/www/my-website
filetarget=$backupdir/my-website_$fileid.tar.gz
dbsource=my-database-name
dbtarget=$backupdir/my-website_$fileid.sql.tar.gz
@pfernandez
pfernandez / prefix-tables.sh
Created May 26, 2019 03:31
Replace table name prefixes in a mysqldump file
#!/bin/bash
#
# Replace table name prefixes in a mysqldump file. Test first!
dumpfile=~/my-database.sql
backup=$dumpfile.$(date +%F_%T).orig
oldprefix=
newprefix=staging_
@pfernandez
pfernandez / install-drupal.sh
Created May 26, 2019 03:33
Install (or reinstall) Drupal
#!/bin/bash
#
# Install (or reinstall) Drupal.
dir=/var/www/my-website/
files=sites/default/files/
default=sites/default/default.settings.php
settings=sites/default/settings.php
vendor=vendor/
@pfernandez
pfernandez / neovim-iterm2-semantic-history.md
Last active June 29, 2023 11:03
Command-click a file in iTerm2 to open it in an existing instance of Neovim
  1. Install neovim: brew install neovim
  2. Install neovim-remote: pip3 install neovim-remote
  3. In iTerm2, go to Preferences -> Profiles -> Advanced, select Semantic History -> Run coprocess, and paste this in:
n=/usr/local/bin/nvr; s="$n --serverlist | tail -n1"; c="$n --servername `$s` --remote-silent"; [ -z "\2" ] && $c \1 || $c +\2 \1

Then command-click a filepath (with optional line number) in iTerm to open the file. Neovim must already be open, and the most recently opened running instance will be used.

You can also achieve this with macvim, but only neovim works in the terminal.

@pfernandez
pfernandez / index.tsx
Created March 4, 2022 23:02
Store React component state and setters in a global object
if (APP.RUNTIME_ENVIRONMENT === RuntimeEnvironment.Development) {
// Create a global key-value store to keep references to all of our component
// state.
const store = {};
(window as any).REACT_STORE = store;
const rawUseState = React.useState;
// @ts-ignore ~ TODO: Type this correctly.
React.useState = (initialState: any) => {
// Wrap useState so that we can store its results before returning them.