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 / 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 / negabinary.js
Created April 10, 2015 03:16
A negabinary filter for AngularJS
var negabinaryApp = angular.module('negabinaryApp', []);
negabinaryApp.filter('negabinary', function() {
return function (decimal) {
if (isNaN(decimal)) return "not a number";
var negabinary = [];
var base = -2;
@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 / secure-node-server.js
Last active December 15, 2016 04:46
How to add https to your Node.js server
// libraries
const express = require('express');
const https = require('https');
const fs = require('fs');
const cors = require('cors'); // Cross-Origin Resource Sharing
// setup express
const app = express();
app.use(cors());
@magician11
magician11 / regex-with-variables.js
Created March 17, 2017 10:31
How to use variables in regular expressions in JavaScript.
function getURL(startMatch, endMatch, str) {
var regex = new RegExp(startMatch + ': (.+), ' + endMatch);
var contents = str.split(regex)[1];
return contents ? contents : 'none found';
}
var str = 'website: http://www.google.com, soundcloud: http://www.soundcloud.com, facebook: http://www.facebook.com, stage: the main one';
console.log('Website URL:', getURL('website', 'soundcloud', str));
@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 / front-end.js
Last active August 2, 2017 21:36
How To Use jQuery To Post A CSV File To A Node.js Server
// using jQuery
$("#2020data").submit(function(e) {
$.ajax({
url: "https://e0d92634.ngrok.io/test",
type: "POST",
data: new FormData(this),
processData: false,
contentType: false
});
@magician11
magician11 / google-oauth.js
Last active November 12, 2017 13:29
How to get a new Google access token from a refresh token on Node.js
const axios = require('axios');
const querystring = require('querystring');
const keys = require('../config/keys');
const getAccessToken = async refreshToken => {
try {
const accessTokenObj = await axios.post(
'https://www.googleapis.com/oauth2/v4/token',
querystring.stringify({
refresh_token: refreshToken,