Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am waggertron on github.
  • I am weylinw (https://keybase.io/weylinw) on keybase.
  • I have a public key ASDPXFNOs1yerc_f7f3ckXN2u8JNjWFhJ0r9qOA2tER8bwo

To claim this, I am signing this object:

@waggertron
waggertron / 0_README.md
Created February 2, 2019 02:02 — forked from scryptonite/0_README.md
Dumps all Sequelize models to JSON to help with creating the first migration script.
  1. Modify & run dump-sequelize-schema.js.
    • It currently uses a few lodash methods, so be sure to temporarily install them—or if you feel up to it you can rewrite the script so they're not needed.
    • npm i lodash.sortby lodash.pick lodash.omit lodash.mapvalues
  2. Inspect sequelize-schema.json and make sure it appears represent all of your tables, attributes, indexes, constraints, references, etc...
  3. When you are satisfied, copy and rename sequelize-schema.json file into a migration-extras/ directory that is next to your migrations/. Name it initial-sequelize-schema.json.
    • migration-extras/
      • -> initial-sequelize-schema.json
    • migrations/
      • (this folder should probably be empty)
  4. Run sequelize migration:create and then copy the contents of 2018XXXXXXXXXX-initial-migration.js into the newly generated migration script. No additional modifications are required if y
@waggertron
waggertron / sequelieze-field-encrypt.js
Created December 19, 2018 20:32 — forked from ajmas/sequelieze-field-encrypt.js
Code to encrypt a Sequelize fields
// Code to encrypt data in sequelize fields
// We are using ascii85 as a way save on storage. Also, note that
// the space delimiter we are using is a bit of an abuse since in
// normal cases ascii85 will skip over it, but since we are using
// after encoding and before encoding, it shouldn't be an issue.
//
// Fields are broken down to facilitate unit testing.
//
// based on code here: http://vancelucas.com/blog/stronger-encryption-and-decryption-in-node-js/
@waggertron
waggertron / gist:0956fd107a4683fc381e0e603785387d
Created December 18, 2018 00:00 — forked from pranildasika/gist:2964211
Virtual fields using getter and setter methods in sequelize
var Sequelize = require('sequelize')
var sequelize = new Sequelize('sequelize_test', 'root')
//Note that the model definition does not have "fullName"
var User = sequelize.define('User', {
email: Sequelize.STRING,
firstName: Sequelize.STRING,
lastName: Sequelize.STRING,
},
{
@waggertron
waggertron / nodegit-private-clone-test.js
Created December 10, 2018 21:42 — forked from mojavelinux/nodegit-private-clone-test.js
Clone a private repository using nodegit
const git = require('nodegit')
const fs = require('fs-extra')
const { URL } = require('url')
const REPO_URL = 'git@github.com:org/path.git'
const CLONE_DIR = '/tmp/private-repo-clone-test'
;(async () => {
await fs.emptyDir(CLONE_DIR)
let authAttempted = false
await git.Clone.clone(REPO_URL, CLONE_DIR, {
// https://www.reddit.com/r/dailyprogrammer/comments/98ufvz/20180820_challenge_366_easy_word_funnel_1/
const fs = require('fs');
const { promisify } = require('util');
const readFilePromise = promisify(fs.readFile);
const makeWordSet = async file => new Set((await promisify(fs.readFile)(file, 'utf8')).split('\n'));
function funnel(word1, word2) {
@waggertron
waggertron / main.c
Created October 1, 2018 22:53
build pyramid one loop construction
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char * char_repeat( int n, char c ) {
char * dest = malloc(n+2);
memset(dest, c, n);
dest[n] = '\n';
dest[n + 1] = '\0';
return dest;
@waggertron
waggertron / main.c
Created October 1, 2018 21:54
two loop solution
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char * char_repeat( int n, char c ) {
char * dest = malloc(n+1);
memset(dest, c, n);
dest[n] = '\0';
return dest;
}
@waggertron
waggertron / pub-sub.js
Created February 15, 2017 04:48 — forked from reu/pub-sub.js
node.js redis pub-sub example
var redis = require("redis")
, subscriber = redis.createClient()
, publisher = redis.createClient();
subscriber.on("message", function(channel, message) {
console.log("Message '" + message + "' on channel '" + channel + "' arrived!")
});
subscriber.subscribe("test");
@waggertron
waggertron / after_res_hooks.js
Created December 10, 2016 22:21 — forked from pasupulaphani/after_res_hooks.js
Mongoose connection best practices
var db = mongoose.connect('mongodb://localhost:27017/DB');
// In middleware
app.use(function (req, res, next) {
// action after response
var afterResponse = function() {
logger.info({req: req}, "End request");
// any other clean ups