Skip to content

Instantly share code, notes, and snippets.

View mulhoon's full-sized avatar
💻
building withcabin.com

Nic Mulvaney mulhoon

💻
building withcabin.com
View GitHub Profile
@mulhoon
mulhoon / complete.post.js
Last active September 27, 2023 17:40
Streaming OpenAI GPT Completions in to Nuxt 3
// server/complete.post.js
import { Configuration, OpenAIApi } from 'openai-edge'
import { OpenAIStream } from 'ai'
import type { H3Event } from 'h3'
const { OPENAI_API_KEY } = useRuntimeConfig()
let openai
@mulhoon
mulhoon / index.js
Last active July 12, 2023 13:24
Calendars
const fs = require('fs')
const readline = require('readline')
const { google } = require('googleapis')
const client_secret = require('./client_secret.json')
// If modifying these scopes, delete token.json.
const SCOPES = ['https://www.googleapis.com/auth/calendar.readonly']
// The file token.json stores the user's access and refresh tokens, and is
// created automatically when the authorization flow completes for the first
// time.
@mulhoon
mulhoon / Highcharts Cheat Sheet
Last active March 22, 2023 18:43
Highcharts Cheat Sheet
$('#container').highcharts({
chart: {
alignTicks: true, // When using multiple axis, the ticks of two or more opposite axes will automatically be aligned by adding ticks to the axis or axes with the least ticks.
animation: true, // Set the overall animation for all chart updating. Animation can be disabled throughout the chart by setting it to false here.
backgroundColor: '#FFF', // The background color or gradient for the outer chart area.
borderColor: '#4572A7', // The color of the outer chart border.
borderRadius: 5, // The corner radius of the outer chart border. In export, the radius defaults to 0. Defaults to 5.
borderWidth: 0, // The pixel width of the outer chart border.
className: null, // A CSS class name to apply to the charts container div, allowing unique CSS styling for each chart.
defaultSeriesType: 'line', // Alias of type.
@mulhoon
mulhoon / s3proxy.js
Last active March 20, 2023 22:42
Serve S3 files through express proxy
// Example of using express to proxy files from s3.
// Works with streaming media like mp4
const AWS = require('aws-sdk')
const mime = require('mime-types')
const express = require('express')
AWS.config.update({
secretAccessKey: '...',
accessKeyId: '...',
@mulhoon
mulhoon / last-modified-demo-server.js
Last active December 28, 2022 12:23
Counting unique visitors and bounces without cookies.
const express = require('express')
const app = express()
app.get('/ping', (req, res) => {
const now = Date.now(),
day = 8.64e7
// calculate midnight today and tomorrow
const midnight = Math.floor(now / day) * day
const midnightDate = new Date(midnight)
@mulhoon
mulhoon / onesignal-node.js
Last active November 9, 2021 07:28
Send a push notification in node with OneSignal
var request = require('request');
var sendMessage = function(device, message){
var restKey = '****';
var appID = '****';
request(
{
method:'POST',
uri:'https://onesignal.com/api/v1/notifications',
headers: {
@mulhoon
mulhoon / global-component-loader.js
Created July 23, 2019 14:47
Global component loading in Vue
import Vue from 'vue'
const components = require.context('@/components', true, /[A-Z]\w+\.(vue)$/)
let keys = components.keys()
keys.forEach(fileName => {
const componentConfig = components(fileName)
const componentName = fileName
.split('/')
.pop()
.split('.')[0]
@mulhoon
mulhoon / templateEngine.php
Last active February 18, 2018 22:18
Simple PHP Template engine
<?php
/*
Original by Rasmus Larsson
http://www.rasmuslarsson.se/2013/05/a-template-engine-in-php/
*/
class Template
{
protected $template;
@mulhoon
mulhoon / PUSH_Notifications.md
Created November 14, 2016 16:29
How to add push notification to a Cordova project - the easy and reliable way.

Push Notifications for cordova.

Use One Signal to add push notifications. There's no need to do anything on the Apple Member Center.

Set up One Signal

  1. Use this to download a .p12 file
  2. Add a new app using the same .p12 for developer and production
  3. Note your App ID and REST API Key from App Settings > Keys & IDs

In your app

@mulhoon
mulhoon / $.js
Last active August 15, 2016 16:35
jQuery selection in One Line
$ = function(s){return s.charAt(0)==='#' ? document.getElementById(s.slice(1)) : document.querySelectorAll(s);};