Skip to content

Instantly share code, notes, and snippets.

// many ifs
function performActions(actionName: string) {
if (actionName === "save") {
// save...
} else if (actionName === "update") {
// update ...
} else if (actionName === "delete") {
// delete...
}
}
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);
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
<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>
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);
}
@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}`
@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,
);
# 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"
// 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,
//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',