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.

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"
}
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';
#!/bin/sh
set -eu
not_supported() {
echo "OS not supported: ${UNAME}"
echo "Please compile manually from https://github.com/dnote-io/cli"
exit 1
}
@sungwoncho
sungwoncho / calculate_remote_score.js
Last active July 22, 2017 08:57
RemoteBase - RemoteScore formula
/**
* Calculate RemoteScore in https://remotebase.io
*
* Currently all RemoteScores are computed in the browser using JavaScript.
* In the future, this logic might be brought to the server-side so that the public API can query it.
*
* Note: RemoteBase public API - https://remotebase.github.io/remotebase-api/
*/
const remoteScoreWeights = {
@sungwoncho
sungwoncho / capture_slides.js
Created July 22, 2017 11:34
A script to capture slides from reveal.js presentation
var webshot = require('webshot');
var maxSlideNumber = 17
var opt = { windowSize: { width: 1440
, height: 799 }};
webshot('https://sungwoncho.github.io/presentations/20170727-graphdb-node-stackoverflow.html#/', 'slide0.png', opt, function(err) {
if (err) {
console.log(err)