Skip to content

Instantly share code, notes, and snippets.

Patrick Tran theptrk

Block or report user

Report or block theptrk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View binary-tree-depth-first-search.js
/**
* Depth first search and Breadth first search traverals in JavaScript
* This example uses a binary tree with left and right nodes
* by theptrk <github.com/theptrk>
*/
function Node(value, opts = {}) {
this.value = value
this.left = opts.left ? opts.left : null
this.right = opts.right ? opts.right : null
}
View tictactoe.py
import random
# The indices in state represent this tic tac toe board
#
# index 0 | index 1 | index 2
# ---------------------------
# index 3 | index 4 | index 5
# ---------------------------
# index 6 | index 7 | index 8
@theptrk
theptrk / sequelize-migration-addColumn.js
Created Apr 13, 2019
Run $ /node_modules/.bin/sequelize migration:generate --name 1m_user_to_dids
View sequelize-migration-addColumn.js
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.addColumn(
'Dids',
'UserId',
{
type: Sequelize.INTEGER,
references: {
View django-custom-user.md

Create a custom user model to use as the new default

Gotcha! Django comes with a default auth library that utilizes a default hidden User model. This default model cannot be easily migrated so DO NOT use this model. Even the Django docs recommend extending this into a custom user model.

Why would you want to extend the model? Imagine you later want to record a users birthdate, using the default model, there is no easy way to add this field to the model. By extending the mode you are future proofing your user model.

Gotcha! Extending the model won’t be enough. In creating your own User model, you must...

  • Step 1: Create new app with "manage.py startapp"
@theptrk
theptrk / sublime-text-vim-remap-jj.md
Last active Feb 24, 2019
Sublime Text vim (vintage) remap `jj` to exit
View sublime-text-vim-remap-jj.md
  • Go to Sublime Text -> Preferences -> Key Bindings and add this to your Default (OSX).sublime-keymap
[
    {
        "keys": ["j", "j"],
        "command": "_enter_normal_mode",
        "args": {
            "mode": "mode_insert"
        },
        "context": [{"key": "vi_insert_mode_aware"}]
@theptrk
theptrk / app.js
Last active Jan 22, 2019
local authentication
View app.js
app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));
app.use(session({ secret: "ilovetodidlist" }));
// authman init needs to be invoked AFTER app.use(session)
authman.init(app);
@theptrk
theptrk / readme.md
Last active Jan 21, 2019
Migrate a postgres database with sequelize.js
View readme.md

Migrate postgres database with sequelize.js

Part I: Set up postgres and sequelize

  • Start the postgresql server using brew and ensure relaunch on login more
$ brew services start postgresql
View save-file.js
const fs = require('fs')
const path = require('path')
const saveToFile = (entry) => {
const target = path.join(__dirname, 'did.txt')
console.log(chalk.green(`... saving to did.txt`))
if (fs.existsSync(target)) {
View index.js
const chalk = require('chalk')
const inquirer = require('inquirer')
const promptSignup = () => {
const questions = [
{
message: 'Whats hannenin\'??',
name: 'action',
type: 'list',
choices: ['did', 'task']
You can’t perform that action at this time.