Skip to content

Instantly share code, notes, and snippets.

View jserrao's full-sized avatar
🦍
Swinging from the trees

John Serrao jserrao

🦍
Swinging from the trees
View GitHub Profile
@jserrao
jserrao / vertical_centering.scss
Created January 11, 2016 14:39
Vertical centering that works IE10+
/* Mixin */
@mixin vertical-align($position: relative) {
position: $position;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
.element p {
@jserrao
jserrao / slug.php
Created January 15, 2016 21:14
WordPress - Get Slug
// Something important to remember about WordPress is that it's functions act differently depending on your template
// This might be the single most annoying thing about WP
// You can get information out of WP but it's very situational
// 1- get the slug is with get_queried_object (on a page)
$slug = get_queried_object()->post_name;
// 2- Checkout the permalink, another way to do this (on a page)
$slug = basename(get_permalink());
@jserrao
jserrao / list-creator.php
Created March 15, 2016 17:19
Create four equally sized unordered lists <ul> with indeterminate amount of list items <li>
<?php
/* This is trickier than it sounds
* You have to think about getting the number of list items and then dynamically generating the lists
* In HTML, you have to know when to close the lists too but there aren't finite objects in this model
* The following example is using WordPress but you could do this on any PHP app
*/
// 1- Setup WP_query variable to get all location posts
// posts_per_page=-1 shows all locations
// orderby=title, orders locations alphabetically by title
@jserrao
jserrao / _bootstrap-grid-supersmall-extension.scss
Created June 6, 2016 19:38
Bootstrap grid extension adds 5th breakpoint for super small devices (iPhone SE)
// Extending bootstrap grid concept for an extra smaller breakpoint via mixin
// Set small breakpoints (default xs is 480px)
$screen-xxs-min: 380px;
$screen-xs-min: 480px;
// Generate the super columns (xxs extension)
@mixin make-xxs-column($columns, $gutter: $grid-gutter-width) {
position: relative;
float: left;
@jserrao
jserrao / text-stroke.css
Created July 27, 2016 15:40
CSS Text Stroke with Text Shadow
/* Adding text stroke using text-shadow, which most browsers actually know */
h1 {
color: white;
text-shadow:
-1px -1px 0 #000,
1px -1px 0 #000,
-1px 1px 0 #000,
1px 1px 0 #000;
}
@jserrao
jserrao / regex.js
Created September 7, 2016 14:18
Basic regex for HTML
// All regex start and with forward slashes
/(conditions-here)/
// Put g character at end of regex to get recursion
/(conditions-here)/g
// Matches all opening HTML tags
/(<\w+\b>)/g
// Matches all <a href="anything">
@jserrao
jserrao / pseudo-reader.js
Created February 24, 2017 04:55
Read a pseudo class in JS
// How to read a pseudo class in JS
window.getComputedStyle(
document.querySelector('.element'), ':before'
);
@jserrao
jserrao / gist:2fe9b3770786b9774b537b8b475f53ee
Last active November 7, 2017 16:42
Verifying my Blockstack ID is secured with the address 19Qdh8zaHkHj6QxQdgf7eRnRjhhZkzaSBs https://explorer.blockstack.org/address/19Qdh8zaHkHj6QxQdgf7eRnRjhhZkzaSBs
Verifying my Blockstack ID is secured with the address 19Qdh8zaHkHj6QxQdgf7eRnRjhhZkzaSBs https://explorer.blockstack.org/address/19Qdh8zaHkHj6QxQdgf7eRnRjhhZkzaSBs
@jserrao
jserrao / wp-menu-switch.js
Created April 18, 2018 15:05
A JS <a> and <li> switcher for WordPress menus
/* MAIN MENU ITEM SWITCH
*
* Description:
* For whatever reason, it's near impossible to get the WP markup in the menu to switch around
* So we're begrudgingly doing it in JS
* This is accomplished by using a regex that breaks the capture after each list item end tag
*
* Usage:
* Really simple - just pass in the class / ID for the sidebar menu container
* This function is not really reusable due to the regex but encapsulation is a good idea in a big JS file
@jserrao
jserrao / gatsby-node.js
Last active November 25, 2018 03:17
gatsby-node.js with DOM Parsing
// Give Node access to path
const path = require('path')
const fs = require('fs')
// Setup parser for taking apart the HTML Description hack stuff from Shopify
const DomParser = require('dom-parser')
const shopifyDescParser = new DomParser()
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions