Skip to content

Instantly share code, notes, and snippets.

@syshen
Last active October 19, 2015 05:48
Show Gist options
  • Save syshen/fb7383e965700214446a to your computer and use it in GitHub Desktop.
Save syshen/fb7383e965700214446a to your computer and use it in GitHub Desktop.
var http = require("http");
var urlParser = require('url');
var names = ["Jim Chang", "Max Liu", "Sara Ku", "Sophie", "Justin", "Brendon", "Jeniffer", "Cherry", "Alice", "John", "Bill", "James", "Steven", "Steve Chen", "Bill Gates", "Steve Jobs", "Mark"]
var currencies = ["HKD", "USD", "TWD", "PHP", "MYR", "RMB", "YEN"];
var notes = ["Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven't found it yet, keep looking. Don't settle. As with all matters of the heart, you'll know when you find it.",
"Your time is limited, so don't waste it living someone else's life. Don't be trapped by dogma - which is living with the results of other people's thinking. Don't let the noise of others' opinions drown out your own inner voice. And most important, have the courage to follow your heart and intuition.",
"Innovation distinguishes between a leader and a follower.",
"You can't connect the dots looking forward; you can only connect them looking backwards. So you have to trust that the dots will somehow connect in your future. You have to trust in something - your gut, destiny, life, karma, whatever. This approach has never let me down, and it has made all the difference in my life.",
"Be a yardstick of quality. Some people aren't used to an environment where excellence is expected.",
"No one wants to die. Even people who want to go to heaven don't want to die to get there. And yet death is the destination we all share. No one has ever escaped it. And that is as it should be, because Death is very likely the single best invention of Life. It is Life's change agent. It clears out the old to make way for the new.",
"My favorite things in life don't cost any money. It's really clear that the most precious resource we all have is time.",
"Stay hungry, stay foolish.",
"Technology is nothing. What's important is that you have a faith in people, that they're basically good and smart, and if you give them tools, they'll do wonderful things with them.",
"Sometimes life hits you in the head with a brick. Don't lose faith.",
"I believe life is an intelligent thing: that things aren't random.",
"If you haven't found it yet, keep looking. Don't settle. As with all matters of the heart, you'll know when you find it. And, like any great relationship, it just gets better and better as the years roll on.",
"I want to put a ding in the universe."];
function randomInt(num) {
return Math.floor(Math.random() * num);
}
function randomRecord() {
var name = names[randomInt(names.length)];
var date = new Date();
date.setHours(randomInt(24));
date.setMonth(randomInt(12));
date.setMinutes(randomInt(60));
date.setSeconds(randomInt(60));
var recipient = names[randomInt(names.length)];
var debit = randomInt(3000);
var amount = randomInt(50000);
return {
"created": date.toISOString(),
"source": {
"sender": name,
"note": notes[randomInt(notes.length)]
},
"destination": {
"recipient": recipient,
"amount": amount,
"currency": currencies[randomInt(currencies.length)]
},
}
}
module['exports'] = function echoHttp (hook) {
hook.res.writeHead(200, {"Content-Type": "application/javascript"});
var startIndex = 0;
if ("startIndex" in hook.params) {
startIndex = parseInt(hook.params["startIndex"]);
}
var num = 10;
if ("num" in hook.params) {
num = parseInt(hook.params["num"]);
}
var records = [];
for (var idx = 0; idx < num ; idx++) {
var record = randomRecord();
record["id"] = startIndex + idx;
records.push(record);
}
hook.res.write(JSON.stringify(records));
hook.res.end();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment