Skip to content

Instantly share code, notes, and snippets.

Complex SQL queries using WITH

One of SQL's best features is the ability to use subqueries within a query, creating ad hoc tables that can be used to simplify queries that would otherwise melt your brain (or at least be difficult to read).

In this real-world example, we have a database of several thousand survey responses and want to be able to report on people's income. Normally we'd use SQL's COUNT and GROUP BY functions to report on totals, but the income field contains hundreds of distinct values - far too many to put into a chart.

Here's the query and the first few rows of the result:

SELECT Income, COUNT(Income) AS IncomeCount 
FROM surveydata 
@panicboy
panicboy / README.md
Created July 29, 2016 04:08 — forked from sgnl/README.md
React Kanban

React Kanban

A digital Kanban board made with React

kanban_guide_print_kpo_bleed_board2-1024x517

"The Kanban technique emerged in the late 1940s as Toyota’s reimagined approach to manufacturing and engineering. ... The system’s highly visual nature allowed teams to communicate more easily on what work needed to be done and when. It also standardized cues and refined processes, which helped to reduce waste and maximize value." - via LeanKit.com

Introduction

Build a Digital Kanban board using:

  • React for building the front-end User-Interface (UI)
@panicboy
panicboy / gist:bf8c1dd1cc7e6e4c7ab25bdd31e21f97
Created July 23, 2016 02:00
Introduction to Sequelize Migrations

What are Migrations

Just like how we use Git to version control source code, we use migrations to manage the state of our database schemas.

I'm not really sure what that means...

Imagine you're working on project with another developer, and you're both tasked with creating a specific part of an event planning application. Let's say you are in charge of creating the Users and your friend is going to create the Events.

Let's say you and your friend divided the work in a way so that neither of you will have to to use each other's code to finish your tasks. While you're working on your part of the application, you only really need to touch the Users table when you are working with the database.

Before you begin

Make sure that the project you are in is a node project (it has a package.json) and you have already installed and initialized sequelize (npm install --save sequelize, sequelize init). Also make sure that your config.json file has the correct credentials to connect to your database.

@panicboy
panicboy / README.md
Created July 15, 2016 01:33 — forked from sgnl/README.md
Articles, Products and Express - Oh my!

Articles, Products, and Express - Oh my!

Goal

Build a mock application which will have 2 resources: Products and Articles. Each resource will have an implementation of CRUD (create, read, update, delete). You should make use of Express' Router module to keep your code organized. Routes go in a directory called routes.

In addition, you will also have additional routes which will render HTML to the user. You will harness the power of Jade to build your templates and have them be dynamic. These templates should go in a directory called templates.

Each of your resources will have it's own module in charge of it's own data. This module should have helper methods for retreiving data. Keep these files in a directory named db.

note: we are not using a database, having a folder called db sort of sets up us for our next topic, databases.

@panicboy
panicboy / express-todo-api.md
Created July 13, 2016 06:57 — forked from sgnl/express-todo-api.md
Buzz Word Bingo API Exercise (no database edition)

Buzz Word Bingo

About the game

Before a meeting the players are asked to enter words with point values. A player can enter a total of 5 words at most. Once a meeting starts if a word that the player previously entered is heard during a meeting that player can mark that word and score the points increasing their score. Each time the player scores a new word the total increases by the point value.

Welcome to Team Buzz™

Our game has been getting a lot of traction and we need to rebuild the API server with NodeJS to handle all the connections, we need you to create the server using ExpressJS. Our CTO will provide you with the specs below.

@panicboy
panicboy / README.md
Created July 12, 2016 19:04 — forked from sgnl/README.md
Manual array iteration exercise feat. Module Pattern + Currying

Manual Array Iteration

Goal

A module which takes an array and returns a function which you can used to manually iterate through the array and return each value found until the end of the array's contents.

Example:

  // load module
  var iteratorModule = require('./iteratorModule.js');
@panicboy
panicboy / README.md
Created July 5, 2016 19:07 — forked from jaywon/README.md
Memoize Me

##Memoize Me We are going to be building an in-memory cache to improve performance and extend the getElementById() and querySelector() functions of the DOM. Querying the DOM for elements can be an inefficient operation and if we are finding elements in the DOM repeatedly we would like to improve performance but we also don't want to clutter our codebase with many variables to hold references to the various elements we will use and to keep things a bit more dynamic.

##Your Challenge Write a module that anyone can add to their project and call your module's functions instead of the native DOM functions.

  1. Use good naming conventions for the module as well as the methods you're exposing. This is subjective to you but put yourself in someone elses shoes of what would make sense to them.
  2. Use memoization to cache elements if they have not been retrieved before from the DOM and return the element just as the above functions would do normally by calling them directly.
  3. If the element has been
@panicboy
panicboy / serverCodes.md
Created July 1, 2016 22:19 — forked from sgnl/serverCodes.md
status codes

1xx: Information

Code Message Description
100 Continue The server has received the request headers, and the client should proceed to send the request body
101 Switching Protocols The requester has asked the server to switch protocols
103 Checkpoint Used in the resumable requests proposal to resume aborted PUT or POST requests

2xx: Successful

Code Message Description
@panicboy
panicboy / README.md
Created July 1, 2016 19:02 — forked from jaywon/README.md
Better Buttons

###The Ask Good morning team! We have been asked to implement a better button for our marketing landing pages in the hopes it leads to more conversions. We currently do one off landing pages for inbound marketing to lead customers to our main brand site. The CEO is demanding that we increase our number of conversions this year and we want something a little more enticing to get users to click.

###Your Challenge Please mock up a simple app with a nice big blue button that when a user hovers over the button grows by 5px in all directions and changes from the dark blue we have on the site to...idk something..."warmer". We also are not sure of the color or sizes we will end up deciding on so the implementation needs to be flexible. Please mock up a prototype for us so we can sell more widgets!!

Any other styling is ok too since you guys are the web masters so impress us.

Thaaaannnks :D

@panicboy
panicboy / sorting-algorithms.md
Created June 29, 2016 20:50 — forked from JoeKarlsson/sorting-algorithms.md
Five popular sorting algorithms implemented manually and visualized with DOM manipulation