Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Golightly magician11

View GitHub Profile
@magician11
magician11 / processingBaptisteData.js
Last active Nov 2, 2015
Script to process all baptiste data
View processingBaptisteData.js
(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 / billablehours.js
Last active Mar 16, 2016
Get all billable hours for a project from Freshbooks
View billablehours.js
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 Apr 10, 2015
A negabinary filter for AngularJS
View negabinary.js
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 Jun 8, 2016
Andrew Golightly's personal eslint rules.
View .eslintrc.json
{
"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 Oct 27, 2016
Lumenflex shop buttons in header
View shop-buttons.js
<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 Oct 31, 2016
Testing for touch screen devices
View touch.html
<!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 Dec 15, 2016
How to add https to your Node.js server
View secure-node-server.js
// 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 Mar 17, 2017
How to use variables in regular expressions in JavaScript.
View regex-with-variables.js
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 Jul 7, 2017
How to encrypt a secret key from tweetnacl using scrypt.
View encrypt-secret-key.js
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 Aug 2, 2017
How To Use jQuery To Post A CSV File To A Node.js Server
View front-end.js
// using jQuery
$("#2020data").submit(function(e) {
$.ajax({
url: "https://e0d92634.ngrok.io/test",
type: "POST",
data: new FormData(this),
processData: false,
contentType: false
});
You can’t perform that action at this time.