Skip to content

Instantly share code, notes, and snippets.

View magician11's full-sized avatar

A magician11

  • Golightly+
  • New Zealand
View GitHub Profile
@magician11
magician11 / fallback-image.html
Created September 1, 2015 10:05
How to set a fallback image for a slider
<section class="slider">
<img src="andrew-and-artist.jpg" onerror='this.src="./andrew-and-artist.jpg"' />
<nav class="slider-nav">
<ul>
<li class="arrow">
<a href="#"><i class="fa fa-long-arrow-left"></i></a>
</li>
<li class="arrow">
<a href="#"><i class="fa fa-long-arrow-right"></i></a>
</li>
@magician11
magician11 / processingBaptisteData.js
Last active November 2, 2015 12:13
Script to process all baptiste data
(function() {
"use strict";
var fs = require('fs');
var firebase = require("firebase");
var ref = new firebase("https://xyz.firebaseio.com/baptiste");
var request = require('request').defaults({ encoding: null });
// Grab all teacher data
var obj = JSON.parse(fs.readFileSync('teachers-part1.json', 'utf8'));
@magician11
magician11 / sort-by-custom-metafield.html
Last active October 8, 2023 15:07
How to sort a collection in Shopify based on a custom metafield.
<!--
This code displays the dropdown for the options to sort from.
Adapted from https://gist.github.com/carolineschnapp/11352987
It will be inserted on every collections page. Probably in a snippet called something like collection-sorting.liquid
-->
<div class="form-horizontal">
<label for="SortBy" class="uppercase">{{ 'collections.sorting.title' | t }}&nbsp;</label>
<select name="SortBy" id="SortBy">
@magician11
magician11 / billablehours.js
Last active March 16, 2016 11:17
Get all billable hours for a project from Freshbooks
let getBillableHours = function(projectId) {
function sumTimes(times) {
let billableHours = 0;
for(let time of times) {
billableHours += parseFloat(time.hours);
}
return billableHours;
@magician11
magician11 / encrypt-secret-key.js
Last active July 7, 2017 01:22
How to encrypt a secret key from tweetnacl using scrypt.
const scrypt = require('scrypt-async');
const nacl = require('tweetnacl');
nacl.util = require('tweetnacl-util');
// utility functions
// -----------------
function printStage(stage) {
console.log(stage);
console.log('-'.repeat(stage.length));
}
@magician11
magician11 / google-url-shortener.js
Last active September 18, 2023 14:39
How to use Request with the Google URL Shortener API.
const request = require('request');
const GOOGLE_API_KEY = 'your api key'; // from https://console.developers.google.com/apis/credentials
const urlToShorten = 'http://www.thelongurltoshorten.com';
const shortenerUrl = `https://www.googleapis.com/urlshortener/v1/url?key=${GOOGLE_API_KEY}`;
const options = {
uri: shortenerUrl,
json: {
longUrl: urlToShorten
@magician11
magician11 / .eslintrc.json
Created June 8, 2016 16:03
Andrew Golightly's personal eslint rules.
{
"extends": "airbnb",
"plugins": [
"react"
],
"rules": {
"max-len": [2, 122],
"comma-dangle": [0],
"react/jsx-closing-bracket-location": [1, "tag-aligned"]
},
@magician11
magician11 / shop-buttons.js
Created October 27, 2016 04:41
Lumenflex shop buttons in header
<script>
jQuery(document).ready(function () {
var urls = ["motor-lightrider", "bike-brightcycle", "industry-orbitsun", "sport-utility-brimbeam", "street-streetseen"];
var productAr = {
'motor': [
{'productName': "lightrider", "label": "BUY NOW"}
],
'bike': [
@magician11
magician11 / touch.html
Created October 31, 2016 10:24
Testing for touch screen devices
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Touchscreen Test</title>
<style>
body {
text-align: center;
}
@magician11
magician11 / sticky-dropdown.html
Created November 7, 2016 07:33
Creates a sticky dropdown for the Fusion Mega Menu for the Avada WordPress theme.
<script>
// makes the dropdown sticky on hover and removes it on scrolling
jQuery(document).ready(function () {
/*
On hovering over the products button, when the mouse is moved away,
then make the dropdown stick by resetting the attributes to do that
per Avada setup.
*/
jQuery('.shop-main-menu').hover(null, function() {