Skip to content

Instantly share code, notes, and snippets.

View delvalle's full-sized avatar

Pablo A. Del Valle H. delvalle

View GitHub Profile
@delvalle
delvalle / next.config.js
Last active September 17, 2020 05:10
Next.js Tips and Tricks, redirects
module.exports = {
async redirects() {
return [
{
source: '/about',
destination: '/',
permanent: true
}
]
}
@delvalle
delvalle / next.config.js
Last active September 17, 2020 05:10
Next.js Tips and Tricks, rewrites
module.exports = {
async rewrites() {
return [
{
source: '/backend/:path*',
destination: 'https://example.com/:path*',
}
]
}
}
@delvalle
delvalle / index.tsx
Last active September 16, 2020 22:15
Next.js Tips and Tricks, console log
import { GetStaticProps } from 'next';
type Props = {
data: string,
};
export const getStaticProps: GetStaticProps = async (context): Props => {
console.log('in getStaticProps...');
return {
@delvalle
delvalle / index.jsx
Created August 27, 2020 06:50
Redis/Next.js
import bluebird from 'bluebird';
import uuid from 'react-uuid';
import redis from 'redis';
const fetchData = async (url) => {
console.log('fetching...');
const query = await fetch(url);
return await query.json();
};
@delvalle
delvalle / index.jsx
Created August 27, 2020 06:25
Redis/Next.js
import bluebird from 'bluebird';
import uuid from 'react-uuid';
import redis from 'redis';
const fetchData = async (url) => {
console.log('fetching...');
const query = await fetch(url);
return await query.json();
};
@delvalle
delvalle / index.jsx
Last active August 27, 2020 02:59
Redis/Next.js
import uuid from 'react-uuid';
const fetchData = async (url) => {
const query = await fetch(url);
return await query.json();
};
export const getStaticProps = async () => {
const data = await fetchData('https://www.healthcare.gov/api/articles.json');
@delvalle
delvalle / mock_stub_4.py
Created August 11, 2020 05:36
Account Class
class Account():
__balance = 0
def __init__(self, initialBalance):
self.__balance = initialBalance
def get_balance(self):
return self.__balance
def update_balance(self, amount):
@delvalle
delvalle / mock_stub_3.py
Created August 11, 2020 05:22
Testing with a Mock
# more imports
from unittest.mock import MagicMock
# more tests
def test_withdraw_has_balance_mock(self):
# setup
withdrawalAmount = 75
self.account.update_balance = MagicMock()
@delvalle
delvalle / mock_stub_2.py
Last active August 11, 2020 05:19
Testing with a Stub
def test_withdraw_has_balance_stub(self):
# setup
withdrawalAmount = 40
def stub():
return 60
original_get_balance = self.account.get_balance
@delvalle
delvalle / mock_stub_1.py
Last active August 11, 2020 02:32
Tests for Account withdrawal
import unittest
from account import Account
class TestAccount(unittest.TestCase):
def setUp(self):
self.account = Account(100)
def test_withdraw_has_balance(self):