Skip to content

Instantly share code, notes, and snippets.

View jonathanfann's full-sized avatar

Jonathan Fann jonathanfann

View GitHub Profile
@jonathanfann
jonathanfann / .zshrc
Last active April 29, 2024 13:22
Get current ticket from branch name and return with commit message in ZSH
function doCommit() {
local branch=$(git symbolic-ref HEAD 2> /dev/null | awk 'BEGIN{FS="/"} {print $NF}')
local ticket=""
if [[ $branch != "" ]];
then
local parts=(${(@s[-])branch})
local part1=$parts[1]
local part2=$parts[2]
ticket="$part1-$part2"
fi
@jonathanfann
jonathanfann / console.js
Created February 14, 2018 20:44
Make any website say it's garbage and apologize to you.
var dang = new SpeechSynthesisUtterance(window.location.hostname + ' is garbage and we truly apologize.'); dang.lang = 'en-US'; window.speechSynthesis.speak(dang);
@jonathanfann
jonathanfann / pdf-embed-shortcode.php
Last active February 1, 2018 15:58
PDF Embed Shortcode (For Wordpress); just include this in your functions.php file
<?php // TODO: put this in your functions.php file and use on a page like [pdf]/path-to-your/file.pdf[/pdf] ?>
<?php
function pdf_embed_shortcode($attrs, $content) {
$pdfPath = $content;
if ( wp_is_mobile() ) {
$htmlStuff =
'<div style="text-align:center;"><p id="mobilefallback">This browser does not support native PDF embeds or you are on a mobile device. Please <a href="' . $pdfPath . '" target="_blank">download</a> the PDF instead.</p>
<p class="pdfDownload"><a class="btn btn-primary btn-md" href="' . $pdfPath . '" target="_blank">Download</a></p></div>';
@jonathanfann
jonathanfann / functions.php
Created January 16, 2018 16:53
How to cache-bust css file changes on wordpress (only if file is updated)
$maincssupdate = filemtime($path . 'wp-content/themes/your_theme/static/gen/main.css');
wp_enqueue_style( 'your_theme_custom', get_template_directory_uri() . '/static/gen/main.css', array(), $maincssupdate, 'all');
@jonathanfann
jonathanfann / custom-taxonomy-custom-post-type-sortable.php
Created April 10, 2017 17:48
Custom Taxonomy added to custom post type (add to functions.php)
<?php
/*
add this to your functions.php
replace 'mytax' with your custom taxonomy
replace 'mypost' with your custom post type
*/
/* 1. add mytax to mypost */
function set_custom_columns($columns) {
$columns['mytax'] = __( 'My Tax Name', 'your_text_domain' );
@jonathanfann
jonathanfann / big_overlay.css
Created March 22, 2017 14:46
test to make sure your css works by adding an overlay over your whole site
body:after {
position:fixed;
top:0;
bottom:0;
right:0;
left:0;
padding-top:20%;
text-align:center;
background:rgba(0,0,0,0.8);
content: 'it worked!';
@jonathanfann
jonathanfann / diff-header-per-custom-post-type.php
Created February 15, 2017 23:05
Include Different Header For Each Custom Post Type
<?php
$post_type = get_post_type( get_the_ID() );
get_template_part( 'headers/' . $post_type, 'header' );
?>
<!--
if your custom post type label is named 'support' for example
this will include the contents of 'yourtheme/headers/support-header.php'
Note: Fails silently so if file doesn't exist, nothing will be included.
-->
@jonathanfann
jonathanfann / gist_wordpress_shortcode.php
Last active October 21, 2016 14:03
Wordpress Gist Shortcode
// Add Shortcode to your functions.php
function gist_shortcode( $atts ) {
// Attributes
$atts = shortcode_atts(
array(
'name' => 'jonathanfann',
'slug' => 'ae707752f2f2c3f93e739838f8dce5c0',
),
[fields.body]
label = Body
type = markdown
{% for k,v in bag('career.quotes').iteritems() %}
<div id="{{ k }}">
<div class="quote">
<h3>"{{ v.quote }}"</h3>
<p><em>{{ v.name }}, {{ v.title }}</em></p>
</div>
</div>
{% endfor %}