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 / write-to-firebase.js
Last active June 28, 2022 10:24
Writing data to Firebase from Node.js
const admin = require('firebase-admin');
admin.initializeApp({
credential: admin.credential.cert('./movies-387bf-firebase-adminsdk-4hoi8-c52699119b.json'),
databaseURL: 'https://movies-387bf.firebaseio.com',
});
// Get a database reference to our blog
const db = admin.database();
@magician11
magician11 / react-ga-no-routes.jsx
Last active April 11, 2020 22:02
How to setup the React Google Analytics Module (react-ga) for your react.js app (with no routes).
import ReactGA from 'react-ga'; // https://github.com/react-ga/react-ga
import { React, Component } from 'react';
class MyApp extends Component {
constructor() {
super();
this.state = {
someData: null,
};
@magician11
magician11 / listen-for-shopify-webhooks.js
Created November 21, 2016 08:06
How to listen to Shopify webhook event data with Node.js
/* eslint-disable no-console */
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
/*
Shopify issues a HTTP POST request.
- https://help.shopify.com/api/tutorials/webhooks#receive-webhook
@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() {
@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 / 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 / .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 / 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 / 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 / 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;