Skip to content

Instantly share code, notes, and snippets.

View ChristianRich's full-sized avatar

Christian Rich ChristianRich

View GitHub Profile
@ChristianRich
ChristianRich / hasDataAttrib.js
Last active May 10, 2016 00:16
jQuery plugin determining if an element contains named data-attributes and that their values are non empty
$.fn.extend({
/**
* jQuery plugin determining if an element contains named data-attributes and that their values are non empty
* Usage:
*
* <button id="myButton" data-country="australia" data-city="sydney" data-some-empty-value="">
*
* $('#myButton').hasDataAttrib('country') // true
* $('#myButton').hasDataAttrib('data-country') // true
@ChristianRich
ChristianRich / exec.js
Created December 6, 2016 04:34
Makes it possible to run shell commands from a Node script. Tested on Mac and Windows. Inspired by https://gist.github.com/goatslacker/1050077
#!/usr/bin/env node
const exec = require('child_process').exec
, Promise = require('promise');
/**
* @param {Array} array of shell commands
*/
module.exports = function(array){
FROM nginx
# File Author / Maintainer
MAINTAINER Christian Rich
# Copy custom configuration file from the current directory
COPY nginx.conf /etc/nginx/nginx.conf
@ChristianRich
ChristianRich / csv2sqlite3.js
Last active April 26, 2017 07:15
Reads CSV files and saves them as Sqlite3 tables to a on-disc database
import parse from 'csv-parse';
import fs from 'fs';
import sqlite3 from 'sqlite3';
import async from 'async';
import csvHeaders from 'csv-headers';
import path from 'path';
let count = 0;
/**
@ChristianRich
ChristianRich / regex-yyyy-mm-dd.js
Created July 5, 2017 07:30 — forked from m-coding/regex-yyyy-mm-dd.js
javascript regex to match date pattern YYYY-MM-DD
// allows YYYY/M/D and periods instead of slashes
// http://stackoverflow.com/questions/24989065/trying-to-validate-yyyy-mm-dd
/^\d{4}[\/.]\d{1,2}[\/.]\d{1,2}$/
// YYYY-MM-DD and YYYY-M-D
// http://stackoverflow.com/questions/6177975/how-to-validate-date-with-format-mm-dd-yyyy-in-javascript
/^\d{4}\-\d{1,2}\-\d{1,2}$/
// YYYY-MM-DD
// https://gist.github.com/arth2o/8471150
@ChristianRich
ChristianRich / index.js
Last active July 18, 2017 05:04
Intercept all HTTPx traffic for logging and debugging purposes. This snippet should be a part of your server startup script.
import * as httpInterceptor from 'global-request-logger';
const debug = require('debug')('my:app');
if(process.env.DEBUG){
httpInterceptor.initialize();
httpInterceptor.on('success', (req, res) => {
const protocol = (req.port === 443 ? 'https://' : 'http://');
@ChristianRich
ChristianRich / createTable.sh
Last active August 30, 2018 05:58
Query DynamoDB for items within a given date time range using a global secondary index and a range key
#!/bin/bash
# You may want to remove the `--endpoint-url http://localhost:8000` line for actual AWS deployment
aws dynamodb create-table \
--endpoint-url http://localhost:8000 \
--table-name exampleTableName \
--attribute-definitions \
AttributeName=id,AttributeType=S \
AttributeName=status,AttributeType=S \
AttributeName=createdDateTime,AttributeType=S \
--key-schema \
@ChristianRich
ChristianRich / error-code.test.js
Last active September 7, 2018 04:24
Chai as promised - assess type Error and status code
import { describe, it } from 'mocha';
import chai, { expect } from 'chai';
import chaiAsPromised from 'chai-as-promised';
chai.use(chaiAsPromised);
describe('Example', () => {
it('should return 404', () =>
expect(foo()).to.eventually.be.rejected
.and.be.an.instanceOf(Error)
@ChristianRich
ChristianRich / gist:6cfa2fdc6daaa921073c450be02e6925
Created October 3, 2018 04:30
Node.js output complex object to console without stringifying
import util from 'util';
console.log(util.inspect(myObject, false, null, true /* enable colors */))
@ChristianRich
ChristianRich / create-table.sh
Last active December 20, 2018 22:50
AWS create DynamoDB tables on localhost
cd ~/dynamodb_local_latest
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb
aws dynamodb create-table \
--endpoint-url http://localhost:8000 \
--table-name pricing-api-tst-menu-dyn \
--attribute-definitions \
AttributeName=id,AttributeType=S \
AttributeName=storeId,AttributeType=S \
--key-schema \