Skip to content

Instantly share code, notes, and snippets.

View davehax's full-sized avatar

Davehax davehax

View GitHub Profile
// JSON.stringify({ date: new Date() }) --> '{"date":"2019-06-20T12:29:43.288Z"}'
// JSON.parse('{"date":"2019-06-20T12:29:43.288Z"}') --> { date: "2019-06-20T12:29:43.288Z" }
// hmm..
// let's use the following function to revive our Date objects!
function jsonDateReviver(key, value) {
// plug this regex into regex101.com to understand how it works
// matches 2019-06-20T12:29:43.288Z (with milliseconds) and 2019-06-20T12:29:43Z (without milliseconds)
var dateFormat = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,}|)Z$/;
if (typeof value === "string" && dateFormat.test(value)) {
/**
* Minimal Pub/Sub class
*
* @class EventEngine
*/
class EventEngine {
/**
* Creates an instance of EventEngine.
* @memberof EventEngine
*/
// Modern method
// If you need to polyfill, see this MDN article https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from
var args = Array.from(arguments);
// Old school method
var args = [].slice.call(arguments);
// POST example
var post = $.ajax({
url: "/api/AttendancesAPI/AddOrEditMultiple",
type: "POST",
dataType: "json",
contentType: "application/json;charset=utf-8",
data: JSON.stringify({
eventId: 1,
userAttendanceProxies: [
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace EventMate.Models
{
/// <summary>
/// Proxy class that will be used facilitate populating or modifying multiple database rows
/// </summary>
// Other using statements...
using Newtonsoft.Json.Linq;
// POST: api/AttendancesAPI/AddOrEditMultiple
[HttpPost, Route("api/AttendancesAPI/AddOrEditMultiple")]
[ActionName("AddOrEditMultiple")]
public HttpResponseMessage AddOrEditMultiple([FromBody]JToken attendanceProxy)
{
// JToken as a parameter type allows us to accept JSON
// webpack.config.js example
var OfflinePlugin = require('offline-plugin');
module.exports = {
// ...
plugins: [
// ... other plugins
// it's always better if OfflinePlugin is the last plugin added
new OfflinePlugin({
ServiceWorker: {
// ES2015 require
require('offline-plugin/runtime').install();
// OR the new way which will require transpiling
import * as OfflinePluginRuntime from 'offline-plugin/runtime';
OfflinePluginRuntime.install();
// webpack.config.js example
var OfflinePlugin = require('offline-plugin');
module.exports = {
// ...
plugins: [
// ... other plugins
// it's always better if OfflinePlugin is the last plugin added
// ... code ...
app.use("/poketype/", express.static(path.join(__dirname, "../poketype/dist/")))
// ... code ...