Skip to content

Instantly share code, notes, and snippets.

@sungwoncho
sungwoncho / README.md
Last active January 5, 2016 10:49
Coddee test example

Coddee test example

An example code from coddee. These are a set of tests written using mocha and chai.

In webhook_method_tests.js, I am testing that the method saves a MongoDB document into a collection.

In webhook_tests.js, I am testing that this method is called when a webhook comes in from GitHub.

I wrote two different tests because the middleware that detects the GitHub webhook is an event emitter, and I don't have much control over how long it takes to actually save a document to a collection.

// Given path and value, get an object
// e.g. getObj('a.b.c', 1)
// { a: { b: { c: 1 } } }
function getObj(path, val) {
const keys = path.split('.');
if (keys.length === 1) {
const current = keys[0];
return {
[current]: val
import React from 'react';
import { connect } from 'react-redux';
/**
* A higher order function that returns a function whose argument is the component
* to be wrapped.
*
* usage example:
* const EnsureLoggedIn = AuthWrapper();
* <EnsureLoggedIn(Profile) />
{
"_id",
"name"
}
@sungwoncho
sungwoncho / cleanup_example.sh
Last active November 11, 2022 21:50
Clean up previous build after a webpack build. Used in production at https://remotebase.io
# Store the filenames of previous build
PREVIOUS_BUILD=(./static/dist/*)
# ...
# build using webpack
# ...
# after the build
regex="([a-zA-Z_0-9]+)-([0-9a-z]+)\.(.*)"
export function sendJobAlertEmail() {
console.log('CRON: sending alert email');
function handleJobs(jobs, user, notifiableJobs, done) {
each(jobs, (job, n) => {
Notification.count({ jobId: job._id, userId: user._id }, (err, count) => {
if (count > 0) {
console.log('notificaiton already sent');
return n();
}
login(req, res) {
const { username, shaHash } = req.body;
res.setHeader('Content-Type', 'application/json');
User.findOne({ username, verified: true }, (err, user) => {
if (!user) {
console.log('No user with that username found or not verified');
res.status(500);
res.end();
return;
#!/bin/bash
# Store the filenames of previous build
PREVIOUS_BUILD=(./static/dist/*)
function fetch {
echo "###### Fetching..."
git pull origin prod
git checkout prod
}
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, browserHistory } from 'react-router';
import { Provider } from 'react-redux';
import ReactGA from 'react-ga';
import getRoutes from './routes';
import ApiClient from './libs/api_client';
import configureStore from './configureStore';
import { ReduxAsyncConnect } from 'redux-connect';
@sungwoncho
sungwoncho / aws_lightsail_bootstrap.sh
Last active August 5, 2017 04:42
Bootstrap a fresh Ubuntu 16 instance
#!/bin/bash
# bootstrap a fresh instance running Ubuntu 16.04
sudo apt-get update
sudo apt-get install -y zsh
sudo apt-get install -y nginx
sudo apt-get install -y tmux
sudo apt-get install -y postgresql postgresql-contrib
# nginx stuff