Skip to content

Instantly share code, notes, and snippets.

View jlei523's full-sized avatar

jlei523

  • San Francisco
View GitHub Profile
class CashAmount {
constructor(amount) {
this.money = amount;
}
convertToPennies(amount) {
let amountString = amount + '';
let first = amountString.split('.')[0] * 100;
class CashAmount {
constructor(amount) {
this.money = amount;
}
convertToPennies(amount) {
let amountString = amount + '';
let first = amountString.split('.')[0] * 100;
let cache = {};
class App extends React.Component {
static async getInitialProps({ req, query, asPath, pathname }) {
let data;
//if data is in cache then use the cache
if (cache[someID]) {
data = cache[someID]
} else {
class App extends React.Component {
static async getInitialProps({ req, query, asPath, pathname }) {
let baseUrl = req ? `${req.protocol}://${req.get("Host")}` : "";
let data = await fetch(baseUrl + 'relativeURL')
return {
data: data
@jlei523
jlei523 / data.csv
Last active February 22, 2019 17:04
id title content url
245 i love next.js because... /post/i-love-nextjs
@jlei523
jlei523 / url.js
Last active February 25, 2019 09:36
server.get('/post/:slug', async (req, res) => {
const actualPage = "/post";
//get the data using '/post/i-love-nextjs' as the id
let data = await fetchDataWithURL(req.params.slug)
const postContent = { data: data };
app.render(req, res, actualPage, postContent);
});
function createPageContext() {
return {
theme,
sheetsManager: new Map(),
sheetsRegistry: new SheetsRegistry(),
//add this to fix broken css in prod
generateClassName: createGenerateClassName({
productionPrefix: "prod"
select * from posts where url = '/post/i-love-nextjs'
server.get("/autocomplete/:searchString", async (req, res) => {
let cloudSearchEndpoint = 'your endpoint here'
let data = await axios.get(
` ${endpoint}/2013-01-01/search?q=~${
req.params.searchString
}&return=_all_fields%2C_score&highlight.label=%7B%22max_phrases%22%3A3%2C%22format%22%3A%22text%22%2C%22pre_tag%22%3A%22*%23*%22%2C%22post_tag%22%3A%22*%25*%22%7D&highlight.unitcode=%7B%22max_phrases%22%3A3%2C%22format%22%3A%22text%22%2C%22pre_tag%22%3A%22*%23*%22%2C%22post_tag%22%3A%22*%25*%22%7D&sort=_score+desc`
);
res.send(JSON.stringify(data));