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 / animation.js
Last active August 29, 2015 14:02
Timeline a VelocityJS animation
// requires underscore or lodash + velocity + jquery
var animation = {
play:function(sequence, complete){
_.each(sequence, function(o){
var el = $(o.el);
el.attr('style','');
_.each(o.timeline, function(a, i){
el.velocity(a, {delay:a.delay, complete:a.end ? complete : null});
});
@mulhoon
mulhoon / validate.js
Last active August 29, 2015 14:05
Validate email address
var validateEmail = function(email) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
};
@mulhoon
mulhoon / App.push.js
Created February 11, 2016 15:31
JS for One Signal
App.push = (function(){
var id = '[---App ID---]';
var notificationOpenedCallback = function(jsonData) {
console.log('didReceiveRemoteNotificationCallBack: ' + JSON.stringify(jsonData));
};
var init = function(customid, callback){
id = customid ? customid : id;
@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);};
@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 / 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 / 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 / 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 / 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 / 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: '...',