Skip to content

Instantly share code, notes, and snippets.

@matthewbeta
matthewbeta / readme.md
Created Jun 2, 2021 — forked from davidohlin/readme.md
Homestead allow CORS (with Sprig for Craft CMS)
View readme.md

Working allow CORS Homestead (with Sprig for Craft CMS)

Place the following in the server block of your sites nginx config, ie /etc/nginx/sites-enabled/example.com

# Allow CORS
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With,hx-current-url,hx-request,hx-target,hx-t>
@matthewbeta
matthewbeta / gatsby-node.js
Created Jun 18, 2020
Rough Gatsby Plugin for downloading images from Craft CMS
View gatsby-node.js
const { createRemoteFileNode } = require(`gatsby-source-filesystem`);
const axios = require('axios');
require('console-success');
const ENTRY_API_URI = `${process.env.GATSBY_API_URL}/entries.json`;
const CATEGORY_API_URI = `${process.env.GATSBY_API_URL}/categories.json`;
exports.sourceNodes = async ({ actions, createNodeId, cache, store, createContentDigest }) => {
const { createNode, createNodeField } = actions;
@matthewbeta
matthewbeta / free-shipping-with-product.rb
Last active May 18, 2020
Shopify Script - Free Shipping with purchase of a specific product
View free-shipping-with-product.rb
# This is the product you need to buy to get free shipping
PRODUCT_ID = 000000000000
# This is the name of the shipping rate you want to discount (you can probably ad more options here and loop over them or soemthing
SHIPPING_NAME = "Standard Shipping"
# This is updated shipping name
UPDATED_SHIPPING_NAME = "FREE Standard Shipping"
# This is the message that will appear next to the doiscounted shipping rate option
MSG = "Buy X get Free Delivery offer"
is_in_cart = false
@matthewbeta
matthewbeta / gatsby-node.js
Created Nov 19, 2019
Paginated Blog in Gatsby
View gatsby-node.js
const createPaginatedPages = require('gatsby-paginate');
exports.createPages = ({ graphql, actions: { createPage } }) => {
return new Promise((resolve, reject) => {
graphql(`
{
blog: craft {
entriesConnection(section: [yoursectionhandle]) {
edges {
node {
@matthewbeta
matthewbeta / scrim-gradient.scss
Last active Jan 17, 2022
A simple little SCSS mixin for creating scrim gradients
View scrim-gradient.scss
/*
A simple little SCSS mixin for creating scrim gradients
Inspired by Andreas Larson - https://github.com/larsenwork
https://css-tricks.com/easing-linear-gradients/
*/
@mixin scrimGradient($startColor: $color-black, $direction: 'to bottom') {
$scrimCoordinates: (
@matthewbeta
matthewbeta / isnumber.js
Last active Feb 23, 2017
Test if its a number in JS
View isnumber.js
function isNumber(val) {
// only returns true if its a number
return Number(val) === val;
}
// OR
function isAlsoNumber(val) {
return typeof val === 'number' && !Number.isNaN(val)
}
View parsley.multipleof.js
<input type="text" data-parsley-multiple="3" data-parsley-error-message="Please try again" />
/*...*/
<script type="text/javascript">
window.ParsleyValidator
.addValidator('multipleof', function (value, requirement) {
return 0 === value % requirement;
}, 32)
.addMessage('en', 'multipleof', 'This value should be a multiple of %s');
</script>
View init.coffee
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@matthewbeta
matthewbeta / visuallyhidden.css
Last active Aug 29, 2015 — forked from sousk/gist:1280108
Hide Visually HTML5 BP style
View visuallyhidden.css
/* Hide only visually, but have it available for screenreaders: h5bp.com/v */
.visuallyhidden {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
@matthewbeta
matthewbeta / mediaquery.less
Created Apr 27, 2015
Mixin for media queries with .no-mq fallback (for <IE9)
View mediaquery.less
@sml-bp: 480px;
@med-bp: 720px;
@lrg-bp: 970px;
.phablet(@rules) {
@media screen and (min-width: @sml-bp) {
@rules();
}
};