Skip to content

Instantly share code, notes, and snippets.

View tsh-code's full-sized avatar

TSH code sharing tsh-code

View GitHub Profile
function add(a, b) {
return a + b;
}
let number = add(2, 2);
function tokenExpired(token, currentDate) {
return token.expirationDate < currentDate;
}
test('tokenExpired', () => {
const token = { token: '123-abc-123', expirationDate: new Date('2018-01-01T12:00:00.000Z') };
const timeBeforeTokenExpiration = new Date('2018-01-01T11:59:00.000Z');
const timeAfterTokenExpiration = new Date('2018-01-01T12:01:00.000Z');
expect(tokenExpired(token, timeBeforeTokenExpiration)).toBe(false);
expect(tokenExpired(token, timeAfterTokenExpiration)).toBe(true);
});
router.post('/:id/title-image', (req, res, next) => {
lwip.open(req.file.buffer, 'jpg', (err, image) => {
if (err) { next(err); return; }
let ratio = (image.width() > 960 ? (960 / image.width()) : 1);
image.scale(ratio, (err, image) => {
if (err) { next(err); return; }
image.crop(image.width(), Math.min((image.width() / 2), image.height()), (err, image) => {
if (err) { next(err); return; }
image.toBuffer('jpg', { quality: 80 }, (err, buffer) => {
<div *ngFor="let hero of heroes">{{hero.name}}</div>
<input #heroInput> {{heroInput.value}}
const add = (a, b) => a + b;
const sum = array => array.reduce(add, 0);
const EmployeesTable = ({ employees }) => (
<table>
<tr><th>Name</th><th>Position</th></tr>
{employees.map(
({ name, position }) => <tr><td>{name}</td><td>{position}</td></tr>
)}
</table>
);
<Surface width={surfaceWidth} height={surfaceHeight} left={0} top={0}>
<Image style={imageStyle} src='...' />
<Text style={textStyle}>
Here is some text below an image.
</Text>
</Surface>
{
optimization: {
splitChunks: {
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
}
}
import * as React from 'react';
import { createRoute } from 'router-8000';
import { LandingViewContainer } from 'views/landing/container';
function getRouteComponent(): JSX.Element {
return <LandingViewContainer />;
}
createRoute('/', getRouteComponent);