Skip to content

Instantly share code, notes, and snippets.

View jdrew1303's full-sized avatar
probably drinking coffee

James Drew jdrew1303

probably drinking coffee
View GitHub Profile
@jdrew1303
jdrew1303 / modules.js
Created August 15, 2018 22:52 — forked from branneman/1-globals.js
A history of different JavaScript module formats
/**
* Globals
*/
var Carrousel = function(elem) { this.init() };
Carrousel.prototype = { init: function() {} };
new Carrousel();
/**
* Namespacing
* - No globals (only the namespace variable itself is global)
@jdrew1303
jdrew1303 / fp-lenses.js
Created August 15, 2018 22:52 — forked from branneman/fp-lenses.js
JavaScript: Lenses (Functional Programming)
// FP Lenses
const lens = get => set => ({ get, set });
const view = lens => obj => lens.get(obj);
const set = lens => val => obj => lens.set(val)(obj);
const over = lens => fn => obj => set(lens)(fn(view(lens)(obj)))(obj);
const lensProp = key => lens(prop(key))(assoc(key));
@jdrew1303
jdrew1303 / primitive-reference-types-javascript.md
Created August 15, 2018 22:52 — forked from branneman/primitive-reference-types-javascript.md
Primitive Types & Reference Types in JavaScript

Primitive Types & Reference Types in JavaScript

An explanation of JavaScript's pass-by-value, which is unlike pass-by-reference from other languages.

Facts

  • JavaScript has 2 kinds of variable types: primitive and reference.
  • A fixed amount of memory is reserved after creation of every variable.
  • When a variable is copied, it's in-memory value is copied.
  • Passing a variable to a function via a call also creates a copy of that variable.

Primitive Types

@jdrew1303
jdrew1303 / vscode-settings.md
Created August 15, 2018 22:52 — forked from branneman/vscode-settings.md
Visual Studio Code: My setup

Visual Studio Code: My setup (macOS)

Global settings

git clone [email protected]:branneman/dotfiles.git ~/.dotfiles
ln -s ~/.dotfiles/vscode-settings.json "~/Library/Application Support/Code/User/settings.json"

Run from terminal

  • Open the Command Palette ( + + P)
@jdrew1303
jdrew1303 / better-nodejs-require-paths.md
Created August 15, 2018 22:50 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@jdrew1303
jdrew1303 / markdown.md
Created July 19, 2018 16:29 — forked from rikukissa/POST.md
Unit testing Angular.js app with node.js, mocha, angular-mocks and jsdom

Testing Angular.js app headlessly with node.js + mocha

Lean unit tests with minimal setup

Code examples

Keypoints

  • Fake DOM (Everything works without a real browser)
  • Uses ngMocks to inject and mock Angular.js dependencies
  • I'm assuming you are already using browserify (but everything works fine without it)
@jdrew1303
jdrew1303 / main.ts
Created July 19, 2018 16:23 — forked from jon-acker/main.ts
Run Angular 4 app in NodeJS using jsdom instead of a real DOM
import 'zone.js';
import 'reflect-metadata';
import * as path from 'path';
import * as fs from 'fs';
// import { XMLHttpRequest } from 'xmlhttprequest';
import { JSDOM } from 'jsdom';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { ResourceLoader } from '@angular/compiler';
import { AppModule } from './app/app.module';
@jdrew1303
jdrew1303 / Event-stream based GraphQL subscriptions.md
Created July 15, 2018 23:11 — forked from OlegIlyenko/Event-stream based GraphQL subscriptions.md
Event-stream based GraphQL subscriptions for real-time updates

In this gist I would like to describe an idea for GraphQL subscriptions. It was inspired by conversations about subscriptions in the GraphQL slack channel and different GH issues, like #89 and #411.

Conceptual Model

At the moment GraphQL allows 2 types of queries:

  • query
  • mutation

Reference implementation also adds the third type: subscription. It does not have any semantics yet, so here I would like to propose one possible semantics interpretation and the reasoning behind it.

@jdrew1303
jdrew1303 / AGB-001_Light_Mod.md
Created June 18, 2018 23:15 — forked from grantland/AGB-001_Light_Mod.md
AGB-001 Front/Backlight Mod Instructions

AGB-001 Front/Backlight Mod Instructions

AGB-001 Backlight Mod

Requirements

  • AGB-001
  • ASS101 screen
@jdrew1303
jdrew1303 / how-to-copy-aws-rds-to-local.md
Created May 29, 2018 00:28 — forked from syafiqfaiz/how-to-copy-aws-rds-to-local.md
How to copy production database on AWS RDS(postgresql) to local development database.
  1. Change your database RDS instance security group to allow your machine to access it.
    • Add your ip to the security group to acces the instance via Postgres.
  2. Make a copy of the database using pg_dump
    • $ pg_dump -h <public dns> -U <my username> -f <name of dump file .sql> <name of my database>
    • you will be asked for postgressql password.
    • a dump file(.sql) will be created
  3. Restore that dump file to your local database.
    • but you might need to drop the database and create it first
    • $ psql -U <postgresql username> -d <database name> -f <dump file that you want to restore>
  • the database is restored