This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// many ifs | |
function performActions(actionName: string) { | |
if (actionName === "save") { | |
// save... | |
} else if (actionName === "update") { | |
// update ... | |
} else if (actionName === "delete") { | |
// delete... | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NestFactory } from '@nestjs/core'; | |
import { AppModule } from './app.module'; | |
import * as os from 'os'; | |
const cluster = require('node:cluster'); | |
const numCPUs = os.cpus().length; | |
async function bootstrap() { | |
const app = await NestFactory.create(AppModule); | |
await app.listen(3000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
attachFile(event: any) { | |
const file: File = event.target.files?.[0]; | |
if (file && this.isValid(file)) { | |
this.errorMessage = ''; | |
const formData = new FormData(); | |
formData.append('file', file, file.name); | |
const uploadFileHeaders = new HttpHeaders({ | |
Accept: `application/json, text/plain, */*`, | |
}); | |
this.httpClient |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input #fileInput type="file" class="file-input" [accept]="acceptedFileExtensions" (change)="attachFile($event)" /> | |
<div class="row document-type"> | |
<div class="col-xs-12"> | |
<button class="fileButton" action="file" (click)="onSelectFile()" type="submit">Upload document</button> | |
allowed file types(JPG, PNG, GIF) | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function bootstrap() { | |
const app = await NestFactory.create(AppModule); | |
app.setGlobalPrefix('api'); | |
config.update({ | |
accessKeyId: '[your S3 Access key]', | |
secretAccessKey: '[your S3 secret]', | |
region: '[your S3 region]', | |
}); | |
await app.listen(3000); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable() | |
export class FileService { | |
async uploadPublicFile(dataBuffer: Buffer, filename: string) { | |
try { | |
const s3 = new S3(); | |
const uploadResult = await s3 | |
.upload({ | |
Bucket: 'file-uploads', | |
Body: dataBuffer, | |
Key: `${uuid()}-${filename}` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Post('upload') | |
@UseInterceptors(FileInterceptor('file')) | |
async uploadFile( | |
@UploadedFile() file: Express.Multer.File, | |
@Request() req, | |
): Promise<any> { | |
const result = await this.fileservice.uploadPublicFile( | |
file.buffer, | |
file.originalname, | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create a simulator | |
xcrun simctl create "my first simulator" "iPhone X" com.apple.CoreSimulator.SimRuntime.iOS-14–5 | |
# boot a simulator | |
xcrun simctl boot 64B94C27-A5BB-4B2A-8E6B-C48B1AFEF298 | |
# shutdown | |
xcrun simctl shutdown 64B94C27-A5BB-4B2A-8E6B-C48B1AFEF298 | |
# show content of a plist file | |
plutil -p "[HOME]/Library/Developer/CoreSimulator/Devices/[DEVICE_NAME]/data/Library/Preferences/.GlobalPreferences.plist" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Firstly, import MikroOrmModule in App.module | |
@Module({ | |
imports: [MikroOrmModule.forRoot(), CatsModule], | |
}) | |
// The Database configuration is store in mikro-orm.config.ts | |
const config: Options = { | |
entities: [Cat], | |
dbName: 'postgres', | |
type: 'postgresql', | |
port: 5432, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Firstly, we create a Sequelize instance with an options object | |
export const databaseProviders = [ | |
{ | |
provide: 'SEQUELIZE', | |
useFactory: async () => { | |
const sequelize = new Sequelize({ | |
dialect: 'postgres', | |
host: 'localhost', | |
port: 5432, | |
username: 'postgres', |
NewerOlder