Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dylants
dylants / proton-mail.css
Last active April 28, 2022 20:39
Dark Theme for Proton Mail
/* ProtonMail */
/* CLASSIC THEME */
body { font-size: 14px }
body,
.pm_opensans {
font-family: 'Lucida Grande', Verdana, Arial, sans-serif
}
@dylants
dylants / app.js
Last active February 6, 2021 17:50
Passport security using local authentication (username/password)
require("express-namespace");
var express = require("express"),
fs = require("fs"),
cons = require("consolidate"),
app = express(),
passport = require("passport"),
mongoose = require("mongoose");
// 30 days for session cookie lifetime
var SESSION_COOKIE_LIFETIME = 1000 * 60 * 60 * 24 * 30;
@dylants
dylants / upload-data-controller.js
Created September 19, 2013 00:50
Upload CSV (Excel spreadsheet) data to a listening Node.js controller.
var request = require("request"),
csv = require("csv");
module.exports = function(app) {
// accepts the POST form submit of the CSV file
app.post("/upload/data", function(req, res) {
// the name under "files" must correspond to the name of the
// file input field in the submitted form (here: "csvdata")
csv().from.path(req.files.csvdata.path, {
delimiter: ",",
@dylants
dylants / myapp.conf
Last active October 8, 2018 16:29
upstart config file for running node.js on a linux machine. This uses nodemon to allow file changes when pulled from git. This also specifies the NODE_ENV environment variable as "production" which would trigger the app to production mode (as opposed to development). Remove the environment variable if development environment is desired.
#!upstart
description "nodemon server for myapp"
author "ubuntu"
start on startup
stop on shutdown
script
export HOME="/home/ubuntu/git/myapp"
@dylants
dylants / Gruntfile.js
Created March 26, 2014 21:50
Mocha and Jenkins integration for Titanium (Appcelerator). The titanium-tests.js contains the setup for Jenkins integration with ti-mocha (Mocha integrated into Titanium). The Gruntfile.js contains a way of monitoring for the done.testing file, which will kill the iOS simulator and allow the Jenkins build to complete.
/* global module:true */
module.exports = function(grunt) {
"use strict";
grunt.initConfig({
watch: {
files: "done.testing",
tasks: ["shell"],
options: {
event: ["added"]
@dylants
dylants / nock.js
Created October 10, 2017 23:42
Nock / mock API requests
// config/mock/nock.js
import nock from 'nock';
import config from '../../config';
// disable all connections so that we use only the mocks
nock.disableNetConnect();
nock(config.blah.api.rootUrl)
@dylants
dylants / mock-mongoose-model.js
Created March 13, 2015 22:09
When testing code which uses Mongoose models, you often run into problems when the schemas are not defined. This code provides an idea on how to mock these models (in a `beforeEach`) and clear them later (in an `afterEach`)
"use strict";
var mongoose = require("mongoose");
var mockMongooseModel = {};
module.exports = mockMongooseModel;
/**
* This function is useful for tests that require Mongoose models
* loaded prior to loading the test file. This should be called in
@dylants
dylants / child.reducer.js
Last active September 11, 2016 13:37
Dynamically add reducers or state to a Redux application, using parent/child reducers
const initialState = {
...
};
export default function childReducer(state = initialState, action) {
switch (action.type) {
// process the actions as you would normally in any reducer
case CHILD_REDUCER_ACTION:
return Object.assign({}, state, {
...
@dylants
dylants / nodejs
Created January 24, 2014 23:32
Nginx configuration file for sites-available to direct traffic based on subdomain to node servers, denying unknown subdomains
# The first node application
upstream app-one {
server 127.0.0.1:3000 max_fails=0;
}
# The second node application
upstream app-two {
server 127.0.0.1:3001 max_fails=0;
}
@dylants
dylants / app-state.js
Created January 7, 2014 21:57
JavaScript client side application state, using session storage.
/*global define:true, sessionStorage:true*/
define([
"underscore"
], function(_) {
"use-strict";
var appState, sessionStorageNamespace;
sessionStorageNamespace = "app.appState";