Skip to content

Instantly share code, notes, and snippets.

@cferdinandi
cferdinandi / terminal-cheat-sheet.txt
Last active April 24, 2024 17:51
Terminal Cheat Sheet
# Terminal Cheat Sheet
pwd # print working directory
ls # list files in directory
cd # change directory
~ # home directory
.. # up one directory
- # previous working directory
help # get help
-h # get help
@cferdinandi
cferdinandi / pandoc-cheatsheet.md
Last active April 23, 2024 17:49
CLI cheats for creating a markdown ebook with Pandoc.

epub

pandoc assets/metadata.yml chapters/*.md -o book.epub -S

pdf

Using WKHTMLtoPDF (no page numbers)

<?php
//
// Utility Methods
// I usually keep this in a separate file for reuse across APIs
//
/**
* Get the API method
@cferdinandi
cferdinandi / print-to-pdf.html
Last active March 18, 2024 23:53
A boilerplate for building a print-to-PDF HTML page that you can dynamically generate with JS (could also be server-rendered if you prefer).
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Print to PDF</title>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<style type="text/css">

Ceasefire Script: Palestine

Want to call your US Senators and Represenatives and urge them to do more to stop the genocide in Palestine?

Here's a script you can you use.

  1. Look up your congress members here: https://www.congress.gov/members/find-your-member
  2. Call them on the numbers listed, and read the script below.

Script

@cferdinandi
cferdinandi / stop-video.js
Last active February 15, 2024 17:03
A simple method to stop YouTube, Vimeo, and HTML5 videos from playing.
/**
* Stop an iframe or HTML5 <video> from playing
* @param {Element} element The element that contains the video
*/
var stopVideo = function ( element ) {
var iframe = element.querySelector( 'iframe');
var video = element.querySelector( 'video' );
if ( iframe ) {
var iframeSrc = iframe.src;
iframe.src = iframeSrc;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Code Sandbox</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
@cferdinandi
cferdinandi / has-characters.php
Last active January 7, 2024 11:58
Test strings for letters, numbers, and special characters. Returns true if they exist, false if they don't. Forked from http://stackoverflow.com/a/9588010/1293256
<?php
// Does string contain letters?
function _s_has_letters( $string ) {
return preg_match( '/[a-zA-Z]/', $string );
}
// Does string contain numbers?
function _s_has_numbers( $string ) {
return preg_match( '/\d/', $string );
@cferdinandi
cferdinandi / umd-script-boilerplate.js
Last active December 10, 2023 10:23
A simple boilerplate for UMD JS modules.
(function (root, factory) {
if ( typeof define === 'function' && define.amd ) {
define([], factory(root));
} else if ( typeof exports === 'object' ) {
module.exports = factory(root);
} else {
root.myPlugin = factory(root);
}
})(typeof global !== "undefined" ? global : this.window || this.global, function (root) {
@cferdinandi
cferdinandi / myplugin-media.js
Last active December 6, 2023 14:23
Adding a Media Uploader to a custom metabox
/**
* Load media uploader on pages with our custom metabox
*/
jQuery(document).ready(function($){
'use strict';
// Instantiates the variable that holds the media library frame.
var metaImageFrame;